What is Redis and what are its key features
Redis is a key-value data store. This means it can be accessed by multiple processes, and that when you need to retrieve an item, you do so by its unique key. It was originally created as a generic cache in 2007, but has since evolved into a general-purpose data structure server which also happens to be open source. Unlike the SQL database which has many different types of data (i.e. tables with various columns), and where the size of each column is hardcoded, Redis uses a memory structure to store data. The data structure is stored in hierarchical fashion (similar to nature itself, with the mother of all structures at the root level, and then levels that branch out into their own sub-trees). This results in a “bounded space” or memory allocation capability which is extremely useful for managing big data.
Figure 1. The Redis data structure (source: http://redis.io/topics/data-structure)
It is open source, and is available under permissive BSD style license that permits it to be freely used, modified and redistributed as long as proper credit is given. One of the distinct advantages of Redis is that it has a very high performance, which makes it possible for even big data (Million of items or more) to be kept in memory with very little data on disk. It is also very easy to scale.
Redis has a wide range of uses. It is suitable for caching, key-value pairs, distributed key-value store (also known as a “cache server”), and many other scenarios. Redis is one of the most popular data structures to use in web applications, as it helps maximize its ability to handle high traffic load.
Figure 2. Comparison between Redis and Memcached (source:http://redis.io/topics/comparison)
Redis was built on an advanced memory management system with advanced data structures that are suitable even for the most demanding requirements and the release of Redis 2.8 in May 2013 has seen other similar data structures like ‘Bloom filter’ and ‘Bitmap indexes’, added to it.
How to install and configure Redis
To get Redis up and running, you need to download it, and configure the system. There are two ways of doing this: 1. Install from source/tarball using Redis-server, or 2. Build from source using gcc and makefile using Redis. See the respective links in [and] below, or information on each by looking at [and] below.
## Subscribing to redis-dev mailing list:
redis-dev at lists.sourceforge.net (archives) – for bug reports, feature requests and general discussion about Redis and related projects. For discussions about Redis 2.2, please use redis-2245 (old redis-dev archives).
## Subscribing to redis-(at)lists.sourceforge.net mailing list:
redis-at at lists.sourceforge.net (archives) – for bug reports, feature requests and general discussion about Redis and related projects, only available to Redis users. No support is given here as we do not provide any support of the software by this group of developers. For discussions about Redis 2.2, please use redis-2245 (old redis-at archives).
## Subscribing to redis-devel mailing list:
How to use Redis for caching, session storage, and more
Caching is one of the most common ways to use Redis. When you build and run a web application, it needs to connect to other servers, clients or databases. These connections can take a long time, and without caching you would need to wait up to a few seconds for each request. In this case, using Redis as a cache is ideal. In addition to this, Redis can also be used to improve the performance of certain types of applications. For example, some games need to communicate with other players over the internet. By storing the data in Redis, you can use it as a fast shared memory store between clients and servers. Redis even has client libraries for various languages so that we can connect to it from our application without re-implementing the whole system from scratch.
Today, most of the articles about Redis focus on its use for caching, storing session data and data structures. I will try to make the content richer by discussing the other uses of Redis that it can serve us.
As mentioned previously, Redis can be used as a cache. It is usually used as a layer in between a client and a backend server to get rid of unnecessary requests. You can store data in Redis in several different ways. One way is to store data in the keyspace (this method is more involved and beautifully described by Christian Heilmann). As a cache, the data can only be accessed within the timeframe you set for it.
I will just describe some of these very common ways of using Redis as a cache:
Redis as a memcached replacement for caching session information.
Redis as the cache for your mobile application.
Tips for optimizing your Redis deployments
Since Redis is a key value store, it’s easy to get the value that you want. However, since everything is stored in memory, the more data you store, the slower it becomes. To combat this there are two key steps: 1. Shrink your dataset: Only keep what we need for the current session of use 2. Reduce your dataset: compress or trim the data that is stored within Redis. This article will give you a few tips and tricks on how to accomplish these two key steps.
1. Shrink your Redis dataset
Alternatives to Redis
There are multiple alternatives to Redis. The most popular ones are: MySQL, MongoDB, Memcached, and Riak. Each of these has their own strengths and weaknesses and determine the right fit for a given application.
Redis is a semi open-source, in-memory key-value store. It stores keys as strings and values as arbitrary objects. The items (keys and values) are stored inside a single memory space, hence stored completely making the operations highly efficient. Redis allows storing of small objects (strings, hashes) lazily (without initializing them until requested) so that the memory usage is very low and only for the insertion of new data. The data is available instantly after being requested, thereby increasing the responsiveness of applications. Rediss is highly concurrent – multiple keys and values can be stored in the same memory space, thereby allowing for high concurrency. Redis has a very low latency due to its blazing fast commands and the ability to store key-value pairs in variuos ways (baked into the language). The lack of additional data structures keeps Redis lightweight, allowing it to be more efficient. Finally, Redis provides a rich set of commands (over 100) that allow developers to perform operations such as lists, sets, sorted sets, pub/sub and transactions. These commands reduce the latency of applications by allowing them to be simple and lightweight.