jazzband / django-redis

Full featured redis cache backend for Django.
Other
2.89k stars 429 forks source link

[Solved] "django.core.cache.cache" not matches with "redis_cache.get_redis_connection('default')" #93

Closed ukjin1192 closed 10 years ago

ukjin1192 commented 10 years ago

First of all, thank you for offering awesome plug-in. I have one question. Please refer following materials.

[ Pre-Condition ] OS : Ubuntu 12.04.5 LTS (GNU/Linux 3.2.0-34-generic-pae i686) django==1.5.4 redis==2.2.12 django-redis==3.7.1

[ django-settings ] 1

[ django pyshell (./manage.py shell) ] 2

[ django admin (django-redisboard) ] 3

[ Problem ]

from django.core.cache import cache cache.set("aaa", 100) => make cache at "DB:1"

from redis_cache import get_redis_connection con = get_redis_connection("default") con => Redis<ConnectionPool<Connection>> con.set("bbb", 100) => expected to make cache at "DB:1", but it is not

niwinz commented 10 years ago

Hi!

I have tested the proposed problem, but everything seems works correctly:

>>> cache.set("aaa", "aaa", None)
True
>>> from redis_cache import get_redis_connection
>>> get_redis_connection("default")
Redis<ConnectionPool<Connection<host=127.0.0.1,port=6379,db=1>>>
>>> get_redis_connection("default").get("aaa")     # expected: because cache prefixes all keys
>>> get_redis_connection("default").get(":1:aaa")  # expected: retrieve key with prefix.
b'\x80\x04\x95\x07\x00\x00\x00\x00\x00\x00\x00\x8c\x03aaa\x94.'
>>> get_redis_connection("default").set(":1:bbb", "1", None)
True
>>> cache.get("bbb")
1

It is possible that I do not understand your question, sorry! Can you explain me more that is the problem?

ukjin1192 commented 10 years ago

Problem solved !

I thought that there is an API which can handle the cache's location as following.

get_redis_connection("default").selectDB("1").set("aaa", "1", None)

But I realized it can be solved more easily by your answer.

get_redis_connection("default").set(":1:aaa", "1", None)

Thanks! Have a good day :)