In recent years, we’ve seen an explosion of different database technologies and experimental database designs that have been developed to better cope with the scale and responsiveness demands of the modern Internet. Each of the new NoSQL options have different strengths and weaknesses because each was designed to fulfill a particular requirement or mitigate a perceived weakness in the traditional relational database model.
Today we’re going have a look at Redis. Redis is an open source, advanced, key-value store that has a few features that can make it very useful for solving some common problems that developers deploying large-scale high-use web sites and online applications encounter.
What Is Redis
Redis has three main peculiarities that set it apart from much of its competition:
Redis holds its database entirely in memory, using the disk only for persistence.
Redis has a relatively rich set of data types when compared to many key-value data stores.
Redis can replicate data to any number of slaves.
The first of these, Redis’ nature as an in-memory data store, has obvious advantages and obvious disadvantages. Redis is extremely fast, all operations take place in memory in contrast to other databases that have to hit the disk for reads and writes. Redis outperforms those relational databases by an order of magnitude when it comes to speed, all else being equal. On the other hand, that also means that the size of the Redis datastore is limited to the size of the available memory. Redis has been compared to Memcached, but because of its occasional snapshotting of the datastore to disk, it has persistence.
Many key-value data stores have a limited set of datatypes, but Redis is comparatively rich, allowing for lists and sets of strings to be stored, as well as sorted sets and hashes. It’s been pointed out that this makes Redis’ datatypes more comparable to the data types of the high level languages that are commonly used in web development, which makes mapping the concepts employed in development more intuitive than with relational databases, although that largely depends on the preferences of the particular developer.
When Would You Use Redis
It might be worth starting off with a discussion of occasions where Redis isn’t appropriate. Firstly, because Redis is an in-memory data store, it is best suited to relatively small data sets. If you want to store huge datasets then the balance between speed and cost will probably end up favoring cost. On the other hand, for many uses, the amount of RAM available is entirely sufficient.
Redis is most often used as a very fast cache for use cases where responsiveness is crucial. For example, suppose you are running an eCommerce website where latency is very harmful to conversions. Using Redis to cache product listings could significantly speed up access times when compared to holding the data in a MySQL database.
If you’ve used Redis, feel free to share your experiences with us in the comments.