Redis – the blazing fast datastore

In the sea of NoSQL databases Redis stands out thanks to its speed and features, it can work as a cache or as a persistent database. Redis stores data in key-value pairs completely in-memory, so if your data doesn’t fit in RAM then this might not be for you.

redis

In contrast to memcache, Redis offers access to a few data-structures (strings, list, hashes, sets, and sorted sets) which makes it a lot more powerful than a “dumb cache”. Getting started is very easy because it’s available in most Linux repos.

Installing and using redis

Here is how you would install it in a Ubuntu machine:

After installing it you can run the client redis-cli and it will drop you into a prompt similar to the mysql one. Only that you will be typing Redis commands instead of SQL, we are going to start with some basics. For a full list of commands click here.

That’s how easy it is to work with simple keys, if you want to see all the keys in the database you can issue the command “keys *”. Note that this command isn’t super fast if you have lots of keys so you don’t want to use it often.

If for example you wanted to store user data you could use the Hash structure and namespaces, this how you could do it:

If you prefer a more visual way of working there are web interfaces available, the main ones being phpRedisAdmin and PHPRedMin.

Well, that was a small taste of Redis! To learn more make sure to check out the documentation.

Leave a Reply