Redis: New Persistent Key-Value Store

Most recently, I’m working on Redis which is a key-value datastore with interesting characteristics. It’s ultra fast and has built in atomic operations to handle concurrent usage. Although everything lives in-memory, Redis syncs with hard disk time to time to serve as permanent storage. Most impressively, downloading Redis and making a working build doesn’t take more than a few minutes.

Redis explains itself as a non-volatile memcached with various in-built data structures. Instead of only key and string value pairs, you can have lists and sets as values. There are atomic pop/push operations to work on these structures and increment/decrement functionality to work on numeric values.

Several client libraries are available including Perl, Python, Erlang, C++, Ruby, Scala and PHP. To write a more meaningful post, I’d like to add lines from a simple Python script.

import redis

storage = redis.Redis()
storage.keys("a*")  # returns keys starting with a

storage.get("key1") # returns the value of "key1"
storage.set("key1", "hello world") # setting the value of "key1"
storage.delete("key1") # deletes the pair with key1.

# working on lists
storage.push('key2', 'This is the first value', tail=True)
storage.push('key2', 'This is the second value', tail=True)
print storage.pop('key2')

Most of these methods are ported to client libraries and are available in downloadable Redis archive.

Although Redis can not be distributed, it’s easy to set up a slave node to replicate the master. Since it syncs with hard-disk in certain intervals, there might be data-loss in possible system crashes. So, setting up a slave may decrease the risks. It’s also advised to use Redis on a central server and manage sharding in the application level.

2 thoughts on “Redis: New Persistent Key-Value Store

  1. redis is not exactly a key-value storage system like memcached. in redis, the values can be sets or lists, and you can make set or list operations on values, where in memcached value’s are just binary objects. redis is written in c++, and fast. also I have been following the project for couple of months, and the developers have released many different versions, so we can say the project is going well. For more complicated data models however, mongoDB, or neo4j (for storing graph data) is more suited.

  2. It does seem that everybody is into this kind of stuff lately. Don’t really understand it though, but thanks for trying to explain it. Appreciate you shedding light into this matter. Keep it up

Leave a comment