Skip to content

Redis: In-Memory Data Store easily explained!

  • Data

Redis is a key-value-based NoSQL database that stores data in memory, i.e. in RAM. This data store is one of the most frequently used key-value databases today and is used for caching, for example. The abbreviation stands for Remote Dictionary Server.

What are NoSQL Databases?

NoSQL (“Not Only SQL”) describes databases that, unlike SQL, are non-relational, i.e. cannot be organized in tables, among other things. These approaches can also be distributed across different computer systems and are therefore highly scalable. NoSQL solutions are very suitable for many Big Data applications.

The databases are characterized by two criteria in particular, which are very broad. Firstly, data is not stored in tables and secondly, the query language is not SQL, which is also made clear by the name Not Only SQL.

Redis belongs to the so-called key-value stores, which are a category within NoSQL databases. They are a very simple data structure in which each record is stored as a value with a unique key. Using this key, the information can be retrieved specifically.

Das Bild zeigt die vier Kategorien von NoSQL Datenbanken, also Document Stores, Key-Value Stores, Wide Column Stores und Graphdatenbanken.
NoSQL Database Categories | Source: Author

How does Redis work?

Redis was developed to have a reliable data store that can store and also output information in a short time. The special feature of this database is the combination of the already mentioned key-value store and the in-memory storage.

An in-memory database stores data on the computer’s random access memory (RAM) instead of writing it to a hard disk, such as an HDD or SSD. This speeds up the process of writing and reading many times over, but comes at the expense of data security and cost. RAM is usually more expensive than comparable hard disk storage and is completely erased when the machine shuts down or the system crashes.

Each entry in this memory is assigned a unique key that can be used to access the data record. Since the working memory of computers is usually a limited resource, it must be used carefully. This also includes the use of special data structures that consume as little memory as possible.

In most cases, strings are used and stored as data structures. In addition, there are other data types that Redis can process (cf. IONOS (2020)):

  • Strings: Strings with a maximum memory size of 512 MB.
  • Hashes: Mapping between a hash representation and an associated string.
  • Lists: A collection of strings that are stored in a list.
  • Bitmaps: Compact representation for boolean values.
  • Streams: A type of log file developed specifically for Redis.

What is in-memory storage?

In-memory storage is a type of data storage where the data is stored in the main memory of a computer rather than on a hard disk or another permanent storage device. This means that data can be accessed and processed much faster than with traditional storage methods, as the data does not need to be read from the hard drive before it can be used. In-memory storage is often used for applications that require extremely fast access to data, such as high-traffic web applications or real-time analytics systems. Redis is an example of a database with in-memory storage.

When data is stored in memory, there is also the risk of losing the information in the event of a system crash, since memory is not a persistent storage medium. Therefore, Redis has two options for the long-term persistence of data:

RDB persistence (Redis DataBase) takes a snapshot of the data in memory and saves it to disk at specified intervals. The snapshot can be configured to be automatic, manual, or both. RDB is a good option when using Redis as a cache, as it allows for quick recovery of data in the event of a crash.

Append Only File (AOF) persistence logs all writes to a log file. This log file can then be used to recover the data if Redis shuts down unexpectedly. Because AOF logs every write, it can be slower and consume more storage than RDB persistence, but it is a better option when using Redis as the primary data store.

Redis also offers a hybrid mode that uses both RDB and AOF persistence for increased data security.

What data types are supported?

Redis supports five main data types:

  • Strings: Strings are used to store a single binary data blob, up to a maximum size of 512 MB. They can be used to store text, integers, or binary data.
  • Lists: Lists are used to store an ordered collection of strings. They can be used to implement a queue, stack, or any other data structure that requires ordered access.
  • Sets: Sets are used to store an unordered collection of unique strings. They can be used to implement a tag system, store relationships between entities, or implement a set-based data structure.
  • Hashes: Hashes are used to store a collection of key-value pairs. They can be used to store objects or to implement a simple database.
  • Sorted Sets: Sorted sets are used to store a collection of unique strings sorted by a score. They can be used to implement a leaderboard to store data that needs to be sorted or to implement a data structure based on sorted sets.

For which Applications is Redis used?

Although the use cases of Redis are very limited, they are hard to displace in this area due to their advantageous properties. As mentioned earlier, Redis is primarily used for caching, such as on Twitter. Caching is generally understood to mean saving intermediate states so that future queries can run faster. In the case of Twitter, for example, this could mean that profile pictures or tweets that have already been loaded are kept in the cache so that they are available more quickly when they are queried again.

These functionalities are especially advantageous in chats or messaging services, as the new messages can be sent to the user almost in real-time.

What are the Advantages of Redis?

NoSQL databases have several advantages over traditional, relational databases. These include better performance with large data volumes and distribution across multiple systems. Redis can also score with the following advantages:

  • Fast accessibility through in-memory memory
  • Support for most common programming languages
  • With the help of various tools, Redis offers a high level of user-friendliness
  • Data can also be distributed across multiple clusters and held in memory on other computers
  • Open-source

What are the Disadvantages of using Redis?

As with most databases, the use of Redis has some disadvantages that must be weighed before implementing it. Besides the risk of data loss in the event of a system crash, the following points also play a role:

  • Main memory is an expensive hardware component
  • Data can only be accessed via keys
  • More complex data sets can only be mapped with difficulty

This is what you should take with you

  • Redis is an open-source memory for data structures in memory that can be used as a database, cache, and message broker.
  • Its ability to store and access data in memory makes it much faster than traditional disk-based databases.
  • Redis supports a wide range of data structures, including strings, hashes, sets, and lists, making it versatile.
  • Persistence is achieved through various mechanisms such as RDB and AOF, allowing data to be recovered after a system failure.
  • Redis is used by various applications and companies such as Twitter, GitHub, and Craigslist due to its high performance, scalability, and ease of use.
  • Support for multiple programming languages and flexible data structures make Redis a popular choice for developers.
  • With the continuous development of new features and improvements, Redis is likely to remain a relevant and useful tool for managing and storing data in modern applications.
Kreisdiagramm / Pie Chart

What is a Pie Chart?

Visualize data proportions with pie charts: an intuitive and effective way to understand relative distribution.

Fuzzy Logik / Fuzzy Logic

What is Fuzzy Logic?

Discover the power of fuzzy logic solving complex problems in engineering and AI. Learn how it works and its advantages and disadvantages.

Swagger UI

What is Swagger UI?

Unlock the power of API documentation with Swagger UI. Learn how to customize and optimize your documentation for enhanced user experience.

Cosine Similarity / Kosinus Ähnlichkeit

What is the Cosine Similarity?

Unlock the potential of cosine similarity in Machine Learning. Explore efficient similarity measurement techniques and Enhance your knowledge.

Apache Flink

What is Apache Flink?

Unlock the power of Apache Flink: Dive into real-time stream processing and big data analytics with this comprehensive guide. Discover more!

Stream Processing

What is Stream Processing?

Introduction to Stream Processing, its applications, and differences to batch processing.

Das Logo zeigt einen weißen Hintergrund den Namen "Data Basecamp" mit blauer Schrift. Im rechten unteren Eck wird eine Bergsilhouette in Blau gezeigt.

Don't miss new articles!

We do not send spam! Read everything in our Privacy Policy.

Cookie Consent with Real Cookie Banner