Distributed caching using Redis

Red Redis iconAnd so, 2 weeks after I’m about to complete my first project on my own. I’m working on a distributed cache module for Nginx that stores cached content in Redis. Redis is a superfast persistent key-value storage that is easy to integrate and easy to work with.

The choice fell on Redis because my customer has continuous experience with Redis, so the solution is going to integrate with his infrastructure in a plug and play manner. Redis has a simple and open protocol that makes programming for it more robust which is a good contribution to the reliability of entire system.

Redis implements auto-expiration feature by means of which a cache entry expires automatically once certain time interval has elapsed, so there is no need to implement extra flushing procedures to keep your cache clean.

The module that implements the caching is quite trivial to configure:

    redis redis_server {
        server localhost:6379;
    }
    server {
        listen       8080 backlog=4096;
        server_name  www.example.com;
        location / {
            proxy_pass ;
            rediscache_pass redis_server "$scheme$proxy_host$request_uri";
            rediscache_fetch $uri;
        }
    }

In this way it can speed up an existing system with little effort while enabling more consistent caching across multiple frontends. As you can see, it also supports distinct description of Redis servers or groups of servers. This stimulates you to avoid ambiguity while referencing servers from specific locations. The module maintains a pool of persistent connections to each server defined and recycles them once they they are idling. This helps you to squeeze the most performance out of your Redis server.

The testing phase is still ahead, but by now it’s visible that a little effort on HTTP caching logic will make the module work transparently with respect to any service it is put upon, reducing the need to patch border cases.

The combination of above-mentioned features makes this module a very elegant solution for distributed caching.

 

This entry was posted in Uncategorized. Bookmark the permalink.

Comments are closed.