简体   繁体   English

使用redis-rails,如何删除除会话缓存以外的所有内容?

[英]with redis-rails, how to delete all but sessions cache?

Rails 5.1 app, redis-rails gem 5.0.2 Rails 5.1应用程式,redis-rails gem 5.0.2

Gemfile 的Gemfile

gem "rails", "~> 5.1"
gem "redis-rails"

in production.rb 在production.rb中

config.cache_store = :redis_store, ENV.fetch("REDISCLOUD_URL")

in session_store.rb 在session_store.rb中

Rails.application.config.session_store :redis_store, servers: [ENV.fetch("REDISCLOUD_URL")]

I would like to be able to clear cache time to time and I can run 我希望能够不时清除缓存并可以运行

Rails.cache.clear

for that. 为了那个原因。 However, it clears everything and I don't want to remove sessions. 但是,它清除了所有内容,并且我不想删除会话。

I tried namespaces but can't find much of documentation anywhere ( https://github.com/redis-store/redis-rails ) 我尝试了名称空间,但在任何地方都找不到太多文档( https://github.com/redis-store/redis-rails

What commands, configs, approach I can take to solve this? 我可以采取哪些命令,配置和方法来解决此问题? Thank you. 谢谢。

Maybe you can get all cache keys 也许您可以获得所有缓存键

Rails.cache.instance_variable_get(:@data).keys

and use it in combination with delete_entry excluding the session keys. 并将其与不包含会话密钥的delete_entry结合使用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM