Navicat Blog

Redis Data Types Jun 26, 2023 by Robert Gravelle

One of the key features that sets Redis apart from other key-value stores is its support of numerous data types, which include strings, lists, sets, sorted sets, and hashes. This makes it easier for developers to solve problems because they tend to know which data type to use for a given task. This blog will outline the six data types supported by Redis.

Strings

Redis stores strings as a sequence of bytes. Strings in Redis are binary safe, meaning they have a fixed length rather than have it determined by one or more special terminating characters. As such, you can store anything up to 512 megabytes in one string.

In Navicat for Redis, we can create a new key/value pair via Edit -> Add Key from the main menu. That will add a new empty row in the Data View and open the Editor:

creating_a_string (102K)

We can use the Editor to set the:

  • Key Name
  • Key Type
  • Value
  • TTL (Time To Live)

Clicking the Apply button populates the new row with the contents of the Editor form. It also shows the size of the value:

new_string (34K)

Hashes

In Redis, a hash is a collection of key value pairs. As such, they are a good choice for representing objects and to store groupings of counters, among other things. Every hash can store up to 2^32 - 1 field-value pairs (that's more than 4 billion!).

For hash values, the Navicat Editor employs a table with Field and Value columns:

hash (78K)

Lists

Redis Lists are simply lists of strings, sorted by the same order in which they were added. You can add elements to a Redis List on the head or on the tail. The max length of a list is 2^32 - 1, or 4294967295, elements (that's more than 4 billion of elements per list!).

In the Navicat Editor, list values are represented as an Element. Clicking on the ellipsis [...] button on the right of the Element opens a special Editor where you can enter the complete list:

list_editor (72K)

Sets

Redis Sets are an unordered collection of strings. A Set is similar to a list, except that Set doesn't allow duplicates and doesn't preserve insertion order.

Sets can be sorted as well. In a Sorted Set, every member is associated with a score, that is used in order to take the sorted set ordered, from the smallest to the greatest score. While members remain unique, the scores may be repeated.

Navicat handles Sets much in the same way as Lists. Here's an example:

set_editor (76K)

Sorted Sets are listed as "zset" in the Key Type drop-down:

zset_editor (23K)

Streams

The Redis stream data type was introduced in Redis 5.0. Streams model a log data structure but also implement several operations to overcome some of the limits of a typical append-only log.

Yes, Navicat for Redis supports the Stream data type!

stream_editor (24K)

Final Thoughts on Redis Data Types

This blog outlined the six data types supported by Redis, including the new Stream type.

Interested in giving Navicat for Redis a try. Download it here. The trial version is fully functional for 14 days.

Navicat Blogs
Feed Entries
Blog Archives
Share