Redis is not just as simple as a Key-Value storage engine, but rather a structured data engine would be more accurate. It supports 5 different data structures that we are going to explore in this post. We will also discover some commonly used commands used in Redis for each data types.

Data structures used in Redis

Structure type What it contains Structure read/write ability
STRING Strings, integers, or floating-point values Operate on the whole string, parts, increment/ decrement the integers and floats
LIST Linked list of strings Push or pop items from both ends, trim based on offsets, read individual or multiple items, find or remove items by value
SET Unordered collection of unique strings Add, fetch, or remove individual items, check membership, intersect, union, difference, fetch random items
HASH Unordered hash table of keys to values Add, fetch, or remove individual items, fetch the whole hash
ZSET (sorted set) Ordered mapping of string members to floating-point scores, ordered by score Add, fetch, or remove individual values, fetch items based on score ranges or member value

1. STRING

Out of the five data structures, STRING is the most basic and simple data type. STRINGs in Redis are similar to strings that we see in other languages or other key-value stores. It can contain any kind of data. You have a key pointing to a value, where both key and value are text or binary strings.

  • GET: Fetches the data stored at the given key
  • SET: Sets the value stored at the given key
  • DEL: Deletes the value stored at the given key

2. LIST

LIST lets you store an ordered sequence of strings.

Commands to use with LIST:

  • LPUSH: Push items to the front.
  • RPUSH: Push items to the back.
  • LPOP: Pop items from the front.
  • RPOP: Pop items from the back.
  • LINDEX: Fetch an item at a given position.
  • LRANGE: Fetch a range of items.

3. HASH

HASH allows you to store a mapping of keys to values. It’s like a collection of keys and corresponding values.

Commands to use with HASH:

  • HSET: Stores the value at the key in the hash
  • HGET: Fetches the value at the given hash key
  • HGETALL: Fetches the entire hash
  • HDEL: Removes a key from the hash, if it exists

4. SET

SET is similar to List, but it keeps all strings unique and unordered.

Commands to use with SET:

  • SADD: Add items by value 
  • SREM: Remove items by value
  • SMEMBERS: Returns the entire set of items
  • SISMEMBER: Checks if an item is in the set

5. ZSET

ZSET is somewhat similar to HASH which holds a type of key and value. The keys (members) are unique, and the values (scores) are floating-point numbers.

Commands to use with ZSET:

  • ZADD: Add new member and score
  • ZRANGE: Fetch all members and scores in sorted order
  • ZRANGEBYSCORE: Fetch members and scores based on a range of scores
  • ZREM: Remove member and score from ZSET.

Looking for a good GUI tool to work with Redis database? Try TablePlus.

TablePlus is a modern, native client with intuitive GUI tools to create, access, query & edit multiple databases: MySQL, PostgreSQL, SQLite, Microsoft SQL Server, Amazon Redshift, MariaDB, CockroachDB, Vertica, Cassandra, Oracle, and Redis.

It’s free anyway.

Download TablePlus for Mac.

Not on Mac? Download TablePlus for Windows.

On Linux? Download TablePlus for Linux

Need a quick edit on the go? Download TablePlus for iOS.

TablePlus for Redis