Cache values not appearing in Redis

时间:2015-12-10 01:31:15

标签: django caching redis django-redis

I've got Redis set up as my cache in django, with the following setting:

CACHES = {
    'default': {
        'BACKEND': 'redis_cache.RedisCache',
        'LOCATION': 'localhost:6379',
        'OPTIONS': {
            'PICKLE_VERSION': 1,
        },
    },
}

And I'm experimenting with it (new to Redis, want to understand it better). So, I go into my Django shell, and I do:

from django.core.cache import cache
cache.set('asdf', 2)
cache.get('asdf')  # Returns 2

And then I go into redis-cli, where I expect to see the value, but none of these show any values:

KEYS *
GET *
GET 'asdf'

What's up with that?

1 个答案:

答案 0 :(得分:1)

默认情况下,Redis有16个数据库。正如@Bernhard在评论中所说,你可以看到每个人有多少把钥匙:

    public JsonResult IsUserExists(string Chemical)
    {
        return Json(!db.NPG_Chemical.Any(x => x.Chemical == Chemical), JsonRequestBehavior.AllowGet);
    }

    public JsonResult IsNIOSHExists(string Measurement_Method)
    {
        System.Diagnostics.Debug.WriteLine("value:",Measurement_Method);
        return Json(db.NPG_NIOSH_Method.Any(x => x.Measurement_Number == Measurement_Method), JsonRequestBehavior.AllowGet);
    }

在我的案例中返回了:

INFO KEYSPACE

您可以# Keyspace db0:keys=1,expires=0,avg_ttl=0 db1:keys=2,expires=2,avg_ttl=504748260 要检查的数据库:

SELECT

在这一点上,当然,我可以看到我期望的钥匙:

SELECT 1
相关问题