Rails Redis setting maxmemory and maxmemory-policy

2019-07-19 11:20发布

I'm trying to set maxmemory and maxmemory-policy in my cache_store configuration of my Rails app.

I did the following in my production.rb file:

  redis_url = "redis://localhost:6379/0"
  config.cache_store = :redis_store, redis_url, { :expires_in => 4.weeks ,
                                                  :namespace => 'rails-cache',
                                                  :maxmemory => '25gb',
                                                  'maxmemory-policy' => 'volatile-ttl'}

But the maxmemory doesn't seam to be working. When I do Rails.cache.methods I don't get any methods about memory or max.

I dont' see any examples on the web for Rails, the closest thing was handling redis maxmemory situations with rails when using rails caching but it doesn't give any examples.

I also cloned and grepped for maxmemory in the the redis-rb gem (https://github.com/redis/redis-rb), but nothing comes up. So it seem like it has not been implemented.

2条回答
Juvenile、少年°
2楼-- · 2019-07-19 11:49

I believe you'd have to set it in redis.conf (or your AWS configuraton) http://redis.io/topics/lru-cache

查看更多
三岁会撩人
3楼-- · 2019-07-19 12:02

If you set the cache store to use redis-rb, and it hasn't implemented maxmemory, I don't see why it'd work.

In particular, it seems like you configure redis's maxmemory in the redis server's config, so I don't think you can do it through a connecting client (ie. redis-rb).

查看更多
登录 后发表回答