One Redis Server for a Rails Application?

I have a rails application on my server that should use Redis as a caching mechanism.

Should I run one instance of Redis for each of my applications or support Redis support?

I am worried that if I delete one value in one application, the value with the same key will be deleted for all my applications.

I do NOT , for example, I want this to happen.

Attachment 1
Rails.cache.write("key", "value")

Appendix 2
Rails.cache.read("key") => "value"

Appendix 3
Rails.cache.delete("key")

Attachment 1
Rails.cache.read("key") => nil

+4
source share
3 answers

The solution was to use redis-store with a namespace parameter.

Here is my config/production.rb file.

 # App 1 config.cache_store = :redis_store, {path: "/tmp/redis.sock", db:1, namespace: "app1"} # App 2 config.cache_store = :redis_store, {path: "/tmp/redis.sock", db:2, namespace: "app2"} 
+2
source

I suggest starting a server for each application. Each additional instance of Redis uses only 1 megabyte of memory when it is empty, so the overhead is small and it is normal to run dozens of servers in one instance. Also an unoccupied Redis server will use minimal memory.

Thus, basically, by running several servers, you do not waste resources, but instead get speed, because you will use all your processors or processor cores, given that Redis is single-threaded.

+5
source

A common method for this is one of two things:

  • The prefix of your keys with some type identifier, for example app1:key , app2:key .
  • Use separate databases for each using SELECT . By default, connections start with DB 0. If you do SELECT 1 for app1, SELECT 2 for app2, etc., you are guaranteed that no other application will compress this data.
+2
source

All Articles