Reputation: 87
I know that REDIS cache is an example of in-memory cache. But it (REDIS) can also acts as distributed cache.
My question is where exactly is cached data stored in in-memory cache. Is the cache deployed directly on the application server? If yes, then how does REDIS being an in-memory cache acts as distributed?
Upvotes: 1
Views: 1157
Reputation: 24110
The basic Redis server is a single server that runs on one machine and stores data in-memory. Any number of clients (applications) can connect to it and get or update values. The application and Redis can be on the same machine, but are often on different ones (e.g. multiple machines talking to the same Redis server).
There are several ways it can become distributed. You is replication: each Redis server has a copy of the same data. This setup is described here: https://redis.io/topics/replication
More interesting distributed operation involves multiple Redis servers each maintaining a different subset of the data. This requires coordination. This setup is called a Redis Cluster, described here: https://redis.io/topics/cluster-spec. At the most basic level, when a client wants to read or set a key, it first hashes it to get a slot number. Each server is responsible for a subset of slots. The client either maintains state to know which server is responsible for which slot or asks some server, which will tell it. Then it just uses the regular Redis commands to communicate with this server about this key.
Beyond this, there is complexity because it's possible for the set of servers to change, due to failures or to allow growing the cluster.
Upvotes: 3