Redis High Speed Storage Or Cache System
NoSQL databases are the hype, with MongoBD and CouchDB on the forefront, while Memcache has found a place in many high load web applications during the past few years. Each of these applications has their own, very specific characteristic. MongoDB finds its usage where single key-value pairs are not sufficient, but adds a slight overhead and complexity with its hash table like multi field storage architecture. CouchDB is an ideal candidate where single key-value pair storage engine is sufficient.
And there is Redis, the new kid on the block. Redis is a high speed storage or cache system, much like Memcache on steroids. Redis writes data into memory, which makes it really fast. And in contrast to Memcache, it writes data periodically to disk depending on the amount of data that has changed. A Redis cache implementation is been said to be able to handle in excess of 10’000 reads/writes per second!
In contrast to Memcache, Redis has its own client language. The basic “set” and “get” are pretty much standard, but we can increment values, set lists and sets and easily handle key replacements and checks for existing values.
As of this writing, version 2 is in Release Candidate 4. For production environments, you’re highly encouraged to use the stable version 1.2.6. To install Redis, download the desired version, untar and switch to the Redis directory. There is no configure script, we just call make, then copy “redis_server” and “redis-cli” to your desired location (eg. /usr/local/bin) and copy redis.conf to /etc/. Let’s start it up! Although I downloaded version 2 RC 4, the server shows version 1.3.17:
redis-server  11 Aug 10:42:33 * Server started, Redis version 1.3.17  11 Aug 10:42:33 * The server is now ready to accept connections on port 6379  11 Aug 10:42:33 - 0 clients connected (0 slaves), 1074272 bytes in use  11 Aug 10:42:33 * Server started, Redis version 1.3.17  11 Aug 10:42:33 * The server is now ready to accept connections on port 6379  11 Aug 10:42:33 - 0 clients connected (0 slaves), 1074272 bytes in use
We can now use Telnet to connect on port 6379 or use the Command Line Interface that comes with Redis (redis-cli) and issue some commands:
redis> get firstName (nil) redis> set firstName Peter OK redis> get firstName "Peter" redis> setnx firstName Peters (integer) 0 redis> get firstName "Peter" redis> setnx firstNames Peters (integer) 1 redis> get firstNames "Peters" redis>
Complete command reference can be found here and it’s highly encouraged that you play around with them and get familiar with the CLI commands. It is really amazing what Redis provides in terms of powerful memory storage solution coupled with such an easy setup and usage. One thing is for sure, we’re hooked.