如何测试我的Redis缓存是否正常工作? [英] How can I test if my redis cache is working?

查看:620
本文介绍了如何测试我的Redis缓存是否正常工作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经安装了django-redis-cache和redis-py。我关注了Django的缓存文档。据我所知,下面的设置是我所需要的。但是我怎么知道它是否正常工作?

I've installed django-redis-cache and redis-py. I've followed the caching docs for Django. As far as I know, the settings below are all that I need. But how do I tell if it's working properly??

    CACHES = {
        'default': {
            'BACKEND': 'redis_cache.RedisCache',
            'LOCATION': '<host>:<port>',
            'OPTIONS': {
                'DB': mydb,
                'PASSWORD': 'mydbspasswd',
                'PARSER_CLASS': 'redis.connection.HiredisParser'
            },
        },
    }

...

    MIDDLEWARE_CLASSES = (
        'django.middleware.cache.UpdateCacheMiddleware',
         ...[the rest of my middleware]...
        'django.middleware.cache.FetchFromCacheMiddleware',
    )

    CACHE_MIDDLEWARE_ALIAS = 'default'
    CACHE_MIDDLEWARE_SECONDS = (60 * 60)
    CACHE_MIDDLEWARE_KEY_PREFIX = ''


推荐答案

Didnt可以与Django一起使用,但是我的默认签入方法g,如果某个组件在开发过程中实际上写入了Redis:

Didnt work with Django yet, but my default approach for checking if some component actually writes to redis during development:

首先,我清空存储在redis中的所有键,以删除旧的缓存条目(在生产环境中请勿这样做)从redis删除所有数据):

First, I flush all keys stored in redis in order to remove old cache entries (never do this in production as this removes all data from redis):

> redis-cli FLUSHALL

然后在应用程序中激活缓存,并查看redis的作用:

Then activate caching in my application, and see what redis does:

> redis-cli MONITOR

您应该进入一个交互式会话,在此您可以看到发送到redis的每个命令。

You should enter a interactive session where you see every command sent to redis.

重新加载页面,在终端上,您应该会看到一些SET *操作来存储缓存数据。

Reload your page and on your terminal you should see some SET* operations storing the cache data.

重新加载并如果您的缓存有效,您应该会看到一些GET *操作正在检索缓存的数据。

Reload again and if your cache works, you should see some GET* operations retrieving the cached data.

注意:使用此方法,您可以检查缓存是否真正被使用。您看不到的是缓存是否有助于加快应用程序速度。为此,您必须按照注释中的建议进行性能测试。

Note: with this method you can check if your cache is actually used. What you cant see is if your cache helps speeding up your application. For that you have to do performance tests as suggested in the comments.

这篇关于如何测试我的Redis缓存是否正常工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆