Data Modeling with Redis - Data Types Visualization

This post is a short introduction to data structures available in Redis. Nothing new, right? Right. However, the chosen approach here is to visualize the most common Redis data structures with ASCII side by side with a simple redis-cli command.

Overview

Besides a sample create command the following section deliberately provides the ASCII visualizations only and no further information. This can be found all over the web. Some good sources as well as the plain text ASCII are listed at the end.

Redis Data Types

The following data type visualizations always picture how to store three values and the corresponding amount of keys to a Redis database instance. And ... indicates that there could follow more keys or values.

Redis Strings (Key Value)

RRedis Data Type Visualization: Strings (KeyValue)
MSET key1 value key2 value key3 value

Redis Lists

Redis Data Type Visualization: Lists
LPUSH key value value value or RPUSH key value value value

Redis Hashes

Redis Data Type Visualization: Hashes
HMSET key field1 value field2 value field3 value

Redis Sets

Redis Data Type Visualization: Sets
SADD key uniqueMember1 uniqueMember2 uniqueMember3

Redis Sorted Sets

Redis Data Type Visualization: Sorted Sets
ZADD key score uniqueMember1 score uniqueMember2 score uniqueMember3

Redis Geopositions

Same as Sorted Set: Score is calculated from latitude and longitude (Geohash).
GEOADD key long lat uniqueMember1 long lat uniqueMember2 long lat uniqueMember3

Redis Bitmaps

Redis Data Type Visualization: Bitmaps
SETBIT key 0 0 or SETBIT key 0 1

Redis HyperLogLogs

Redis Data Type Visualization: HyperLogLogs
PFADD uniqueMember1 uniqueMember2 uniqueMember3

Further Information

Redis Docs & Command Reference:
https://redis.io/topics/data-types-intro
https://redis.io/commands/

DZone Refaced for Redis (with simple yet comprehensive examples):
https://dzone.com/refcardz/getting-started-with-redis

Online Tool for ASCII:
http://asciiflow.com

Plain Text ASCII Data Types Visualizations

Redis Strings (Key Value):

+---------------+
|               |
| +---+ +-----+ |
| |key| |value| |
| +---+ +-----+ |
|               |
| +---+ +-----+ |
| |key| |value| |
| +---+ +-----+ |
|               |
| +---+ +-----+ |
| |key| |value| |
| +---+ +-----+ |
|               |
| +---+   +---+ |
| |...|   |...| |
| +---+   +---+ |
|               |
+---------------+


Redis Lists:

+-------------------------------------+
|                                     |
| +---+ +-----+ +-----+ +-----+ +---+ |
| |key| |value| |value| |value| |...| |
| +---+ +-----+ +-----+ +-----+ +---+ |
|                                     |
+-------------------------------------+


Redis Hashes:

+-----------------------+
|                       |
| +---+                 |
| |key|                 |
| +---+                 |
|                       |
|       +-----+ +-----+ |
|       |field| |value| |
|       +-----+ +-----+ |
|                       |
|       +-----+ +-----+ |
|       |field| |value| |
|       +-----+ +-----+ |
|                       |
|       +-----+ +-----+ |
|       |field| |value| |
|       +-----+ +-----+ |
|                       |
|       +---+     +---+ |
|       |...|     |...| |
|       +---+     +---+ |
|                       |
+-----------------------+

Redis Sets:

+-------------------------------------------------------------+
|                                                             |
| +---+ +-------------+ +-------------+ +-------------+ +---+ |
| |key| |uniqueMember1| |uniqueMember2| |uniqueMember3| |...| |
| +---+ +-------------+ +-------------+ +-------------+ +---+ |
|                                                             |
+-------------------------------------------------------------+

Redis Sorted Sets:

+-------------------------------+
|                               |
| +---+                         |
| |key|                         |
| +---+                         |
|                               |
|       +-----+ +-------------+ |
|       |score| |uniqueMember1| |
|       +-----+ +-------------+ |
|                               |
|       +-----+ +-------------+ |
|       |score| |uniqueMember2| |
|       +-----+ +-------------+ |
|                               |
|       +-----+ +-------------+ |
|       |score| |uniqueMember3| |
|       +-----+ +-------------+ |
|                               |
|       +---+             +---+ |
|       |...|             |...| |
|       +---+             +---+ |
+-------------------------------+

Redis Geopositions:
Same as Sorted Set: Score is calculated from latitude and longitude (Geohash).


Redis Bitmaps:

+----------------+
|                |
| +---+ +------+ |
| |key| |0|1...| |
| +---+ +------+ |
|                |
+----------------+


Redis HyperLogLogs:

+-------------------------------------------------------+
|                                                       |
| +---+ +---------------------------------------------+ |
| |key| |uniqueMember1 uniqueMember2 uniqueMember3 ...| |
| +---+ +---------------------------------------------+ |
|                                                       |
+-------------------------------------------------------+