Questions tagged [django-redis]

105 questions
1
vote
0 answers

Why does accessing Django cache during unit tests (manage.py test) produces datetime.datetime objects instead of expected values?

I have a Django app, and I'm trying to create unit tests for functions/methods that work with the cache. My tests are run using python manage.py test using the same Docker container that I use for running the app locally. The functions/methods I'm…
sunw
  • 535
  • 5
  • 29
1
vote
1 answer

Django and redis adding :1 to keys

I'm using django-redis to store some data on my website, and I have a problem where Redis is adding :1 at the beginning so my key looks like this: :1:my_key I'm not sure why is it doing this, I've read the documentation on django-redis and I…
1
vote
1 answer

How to write python unittest cases to mock redis connection (redis.StrictRedis) in Django

How can I mock the following function for connecting to Redis? import redis class RedisCache: redis_instance = None @classmethod def set_connect(cls): redis_instance = redis.StrictRedis(host='0.0.0.0', port=6379,…
1
vote
2 answers

Caching serializer responses in Django Rest Framework

I am using serializer to get the related data for a particular resource like this: SessionSerializer.py def to_representation(self, instance): response = super().to_representation(instance) response["user"] = UserSerializer(instance.user).data …
1
vote
0 answers

New records not coming in the list call of Django DRF API using Redis cache

I have a Django REST API, and I am using Redis as the caching backend. Code @method_decorator(cache_page(60*60)) def dispatch(self, *args, **kwargs): return super().dispatch(*args, **kwargs) It caches the data on a get call, but when I…
Niyojan
  • 544
  • 1
  • 6
  • 23
1
vote
1 answer

How to check if redis connection is available when server starts running in django rest framework and return the error response if not connected

I'm doing multiple API calls but in each API call I'm checking if redis connection is available. showing only one of the API calls below. def check_redis_conn(): redis_exists = RedisCache.is_redis_available() if redis_exists is True: …
1
vote
1 answer

Django CACHEOPS different timeout for different querysets

I'm using Django CACHEOPS. cacheops' README In settings.py how can I config different timeouts for different querysets? (cache the get queryset for 10 seconds and cache queryset fetches for 60 seconds) Something like this: (This obviously has…
1
vote
1 answer

Is there a way to set an expiration time for a Django cache lock?

I have a Django 3.1.3 server that uses Redis for its cache via django-redis 4.12.1. I know that cache locks can generally be set via the following: with cache.lock('my_cache_lock_key'): # Execute some logic here, such as: …
sunw
  • 535
  • 5
  • 29
1
vote
0 answers

why is django app creating huge keys in redis

I am running django app (wagtail) in kubernetes cluster along with redis. These two pieces are connected by django-redis. This is how my backend configuration look { "BACKEND":"django_redis.cache.RedisCache", …
Ojas Kale
  • 2,067
  • 2
  • 24
  • 39
1
vote
1 answer

[Django rest_framework]Problems in using redis as Django DRF cache

I'm trying to open the redis cache for the rest framework. My configuration seems to be correct. When I run, it reports an error. As shown below: Watching for file changes with StatReloader Performing system checks... Exception in thread…
1
vote
1 answer

Is it a good idea to use cache and how to use it for 4000-10000 data rows in Django for a single page?

Django 2.2 I need to fetch 4000-10000 data rows from a particular datatable (let's call this commonsites) amongst others to display a webpage. I can narrow down to just 3 fields of these 4000-10000 rows (id, name, business_id) My traffic is low. But…
Kim Stacks
  • 10,202
  • 35
  • 151
  • 282
1
vote
2 answers

One to One vs field in same models django

I have created two templates I have the extended template De user (AbsctractUser) and the template (Score) with the field total_score. From what I could understand about the django cache with redis is that as long as the line is not modified, redis…
Pascal de Sélys
  • 127
  • 1
  • 10
1
vote
2 answers

Django caching with Redis

I have implemented django caching using redis following this blog: https://realpython.com/caching-in-django-with-redis/ So I followed this, installed the package, Added in CACHES = { "default": { "BACKEND": "redis_cache.RedisCache", …
Harshit verma
  • 506
  • 3
  • 25
1
vote
3 answers

installed django-redis in python virtualenv, redis-cli command not found

I just install django-redit using pip in my python virtualenv,but when I enter command redis-cli, it shows me redis-cli command not found. I'm pretty much sure redis-cli has been installed sucessfully. need your help thx in advance
Chase.yang
  • 13
  • 5
1
vote
2 answers

Django redis for notifications

I have build a REST API with Django REST framework. In the app there is a need for facebook-type notifications ( new friend request, new message etc. ). Currently I'm handling this using long-polling: front client sends GET request my REST view…