How can I test if my redis cache is working?

前端 未结 3 599
时光取名叫无心
时光取名叫无心 2021-02-02 14:54

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

相关标签:
3条回答
  • 2021-02-02 15:10

    You could install the django-debug-toolbar and see if the number of queries decreases when you enable caching. Though I don't think this is the best solution to the posed question, I still think you want to do this, as you can easily pinpoint costly queries using this setup, and then add the appropriate caching to them.

    0 讨论(0)
  • 2021-02-02 15:12

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

    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
    

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

    > redis-cli MONITOR
    

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

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

    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.

    0 讨论(0)
  • 2021-02-02 15:28

    Usage of Redis has been focused on lowering the overall query load to the database.

    This system likes to work independetly without any coflict ;)

    I suggest don't worry about its operation and don't change its configs if you can see its activities at:

    > redis-cli MONITOR
    

    And there is some elements about your code.

    0 讨论(0)
提交回复
热议问题