A key-value store and more
The 2.0.0 release of Redis is out and offers a super-fast key value store that stores data in-memory. It offers a persistent data store along with support for sets, string values and hashes. Performance wise it is extremely fast and offers replication without too much fuss. As a developer it is a joy to use. On OSX you can install it using homebrew:
1
| |
and then start the server with
1
| |
Now you can connect to it with a client and start adding and retrieving data with a client
1
| |
Basics
Here’s a basic example of setting and getting a value
1 2 3 4 | |
Once you have a value you can get information from Redis as to its type:
1 2 | |
And whether a key exists
1 2 | |
I’ll cover more of the excellent features in subsequent posts.
Using Ruby and Redis
Redis has wrappers for most lanugages including Ruby, Python and PHP. For Ruby you can install the wrapper with
1
| |
You can then use it in scripts with
1 2 3 4 5 | |
Great for caches and counters
Redis is great for things like counters. Say for example you want to track the number of times a page has been viewed. This is simple with Redis:
1 2 3 4 | |
For non-persistent data like caching it is a really good solution too. You can even use it as the cache in Rack applications.