Re­la­tion­al databases are used in most IT projects. Re­gard­less of whether they are used for web design or software de­vel­op­ment, table-based databases tend to deliver solid, stable results in most sit­u­a­tions. But are they always the perfect choice? In recent years, an in­creas­ing number of new database types have come onto the market, each with their own unique ad­van­tages. NoSQL databases are highly rec­om­mend­ed for certain projects. Redis supplies such a database. How does the data storage work and what are the ad­van­tages of Redis?

An ex­pla­na­tion of Redis databases

The name Redis stands for Remote Dic­tio­nary Server. This type of server is designed for high-speed data storage. As a database man­age­ment system (DBMS), Redis offers both an in-memory database and a key-value store.

  • In-memory database: In these databases, the DBMS stores all data directly in the memory. This results in very fast access times, even for large amounts of un­struc­tured data.
  • Key-value store: Key-value databases are also im­pres­sive with their high per­for­mance and easy scal­a­bil­i­ty due to their simple structure. A key is created for each entry which can then be used to retrieve the in­for­ma­tion.

So, all the data in a Redis server is not stored on the hard drive but in the memory instead. As a result, Redis is both a cache and a memory: it makes no dif­fer­ence for Redis whether the in­for­ma­tion is stored per­ma­nent­ly in the database or only for a short time.

Every entry in the database is assigned a key. Using these keys, data can be easily retrieved. Entries are not linked to one another and thus do not need to be requested across multiple tables. The in­for­ma­tion is directly available.

Storing data in the memory also means that there is a risk of losing all the data if the server crashes. To safeguard against this even­tu­al­i­ty, Redis can either copy all the data regularly to a backup hard drive or save all the commands needed for re­con­struc­tion in a log file.

Strings are the common data structure for Redis (i.e. simple character strings). Even keys (part of the key-value store) are strings. However, this system can also handle other data struc­tures:

  • Strings: a string of char­ac­ters with a maximum size of 512 MB
  • Hashes: an entry with multiple fields
  • Lists: a col­lec­tion of strings sorted based on the order they were entered
  • Sets: an unsorted col­lec­tion of strings
  • Sorted sets: a user-sorted col­lec­tion of strings
  • Bitmaps: a col­lec­tion of bit-level op­er­a­tions
  • Hy­per­LogLogs: an es­ti­ma­tion based on unique values
  • Streams: a list of strings or key-value pairs

Since Redis is open source, many de­vel­op­ers are working on ex­ten­sions for this DBMS. These modules add more func­tion­al­i­ty to the otherwise very simple database and adapt the software for specific ap­pli­ca­tions.

Fact

Redis is open source and can be used by anyone free of charge. Redis’s main sponsor is Redis Labs. This company offers paid cloud versions of the software.

Which ap­pli­ca­tions is Redis best suited for?

The standard ap­pli­ca­tion for Redis is a cache. For example, Twitter uses the database for this purpose. The timeline in this messaging service is im­ple­ment­ed using a Redis cache. Basically, the timeline consists of a list which can be quickly retrieved and in­cre­men­tal­ly extended thanks to Redis.

Redis is also used for other purposes. For example, Redis databases are perfect for messaging services and chat rooms due to their high access speeds. New entries can be displayed in real time. Even lists which must be quickly modified are im­ple­ment­ed using Redis.

Tip

Have you been convinced by Redis, and do you wish to use this database for your project? You can learn more about how to get started in our simple Redis tutorial.

The ad­van­tages and dis­ad­van­tages of Redis

Redis is always a good choice if you need simple data to be available quickly. Due to the fact that it makes standard data backups, the read speed is increased: data can be retrieved from different instances. Scaling also works well when using Redis, both hor­i­zon­tal­ly and ver­ti­cal­ly. If the Redis server’s memory is in­suf­fi­cient, the software has built-in virtual memory man­age­ment. This stores data on the hard drive. Redis itself is written in C, but there are clients for almost every pro­gram­ming language.

However, if you are working with complex data which requires equally extensive query options, Redis is not the right choice. Generally, data in a key-value store can only be accessed via its keys. In addition, Redis (like other in-memory databases) requires an extremely large amount of memory which can be expensive. You should also expect to provide more memory than the data actually uses.

Summary

Whenever data has to be written and retrieved quickly, Redis offers a good al­ter­na­tive to tra­di­tion­al re­la­tion­al databases. However, if you do not require speed and are looking for a database for more complex tasks, you should stick to the tra­di­tion­al solution.

Go to Main Menu