What Data Structure Is Used in Redis?


Larry Thompson

Redis is an open-source in-memory data structure store that is widely used for its high performance and versatility. It supports a variety of data structures, each designed to cater to different use cases. In this article, we will explore the various data structures available in Redis and understand when and how to use them.


Strings are the most basic data type in Redis. They can contain any type of data, such as text, integers, or even serialized objects. Redis provides a wide range of commands to manipulate strings, including getting, setting, and modifying their values.


Lists in Redis are ordered collections of strings. They allow for fast insertion and retrieval at both ends (head and tail) of the list. Lists are ideal for implementing queues or stacks where the order of elements matters.

To interact with lists in Redis, there are commands like LPUSH (push elements to the head), RPUSH (push elements to the tail), LPOP (pop an element from the head), RPOP (pop an element from the tail), and many more.


Sets are unordered collections of unique strings. Unlike lists, sets do not preserve the order of elements but ensure that each element is unique within the set.

Redis provides an extensive set of commands to manipulate sets such as SADD (add elements to a set), SREM (remove elements from a set), SISMEMBER (check if an element is present in a set), and more.


Hashes store field-value pairs where both fields and values are strings. They provide efficient access to individual fields and are suitable for representing objects or dictionaries.

Redis offers commands like HSET (set the value of a field in a hash), HGET (get the value of a field in a hash), HDEL (delete one or more fields from a hash), among others, to work with hashes.

Sorted Sets

Sorted Sets combine the features of sets and lists. They store a collection of unique elements, each associated with a score. The score is used to order the elements in ascending or descending order based on their numerical value.

Redis allows you to perform operations like ZADD (add an element with its score to a sorted set), ZRANGE (retrieve elements within a specific range by their scores), ZREM (remove one or more elements from a sorted set) and more on sorted sets.

In conclusion,

Redis provides various data structures that cater to different use cases and allow for efficient manipulation of data. By choosing the appropriate data structure based on your requirements, you can leverage Redis’s performance benefits and enhance your application’s functionality.

  • Strings: Basic data type for storing any type of data.
  • Lists: Ordered collections ideal for implementing queues or stacks.
  • Sets: Unordered collections of unique strings.
  • Hashes: Store field-value pairs, suitable for representing objects or dictionaries.
  • Sorted Sets: Combine set and list features, ordered by an associated score.

With this knowledge of Redis data structures, you can harness the power of Redis to optimize your application’s performance and data storage.

Discord Server - Web Server - Private Server - DNS Server - Object-Oriented Programming - Scripting - Data Types - Data Structures

Privacy Policy