0

django-redis source: https://github.com/jazzband/django-redis/tree/master/django_redis

my problem is I can not find method to get number of keys in Redis database, it call dbsize. Methods that available such as set, get, add, delete, delete_pattern, delete_many, clear, get_many, set_many, incr, decr, has_keys, keys, iter_keys, ttl, pttl, persist, expire, expire_at, pexpire, pexpire_at, lock, close, touch.

How can I used dbsize method of redis command in django-redis library?

environment:
django version : 3.2.10
django-redis: 5.2.0

1 Answers1

0

I found the solution of the question

from django_redis import get_redis_connection
REDIS = get_redis_connection("default") # default is alias of redis
REDIS.dbsize() # get number of keys in the currently-selected database

this solution can use native redis command but cannot use method of django-redis plugin
WARNING: Not all pluggable clients support this feature.