---
title: "Deep Dive into Redis Data Types"
description: "Deep Dive into Redis Data Types"
canonical_url: "https://www.bigbinary.com/blog/redis-data-types-deep-dive"
markdown_url: "https://www.bigbinary.com/blog/redis-data-types-deep-dive.md"
---

# Deep Dive into Redis Data Types

Deep Dive into Redis Data Types

- Author: Sreeram Venkitesh
- Published: November 14, 2023
- Categories: Misc

Last week, while migrating [NeetoGit's](https://www.neeto.com/neetogit)
production deployment to [NeetoDeploy](https://www.neeto.com/neetodeploy), we
faced a challenge. The Redis 7 add-on only had a TLS URL in Heroku. We were not
able to get the dump in a straightforward manner using redis-cli, since we
didn't have access to the certificates for making a TLS connection. We were able
to connect to the add-on, so we decided to write a script to manually copy all
the keys and values over to the Redis add-on in NeetoDeploy.

While writing the program, we realized that we'd need a switch-case that checked
what data type each key was. We had to search for the get and set methods for
each data type manually while writing the program. Late,r we used the redis-rb
gem and was able to get the dump with `OpenSSL::SSL::VERIFY_NONE`, but we had
still faced the issue of having to look up what the command was for different
data types like zset and hash.

I thought this could be a good opportunity to write a blog post summarizing all
the data types and the commands associated with them. The Redis documentation
has a page about the different data types, but all the commands are not
available at a single place.

## Redis key-value database

When we say that Redis is a key-value database, there is more to it than what
meets the eye. Redis keys can store values of several different data types.
Redis has a set of commands for each of these different data types to do
operations with them. In this post, we’ll go over the different data types, what
they are and how we can work with them.

### What are the different data types?

Redis has more than a couple of data types, which can be used to store different
data based on your needs. These include the following:

- `String` - The basic data type we are all familiar with.
- `List` - An array of strings.
- `Hash` - A collection of key-value pairs, similar to a Ruby `Hash`.
- `Set` - A collection of unique strings.
- `Sorted Set` - A collection of unique strings maintaining by each string’s
  score.
- `HyperLogLog` - Probabilistic estimates of cardinality of large sets.
- `Stream` - An append only log.
- `Geospatial Index` - Data structure for storing geographic coordinates.

### Checking data type of your keys

You can use the `TYPE` command to check what data type your key is. Once you
know what type your key is, you can use the commands associated with your key's
data type to interact with it.

```
127.0.0.1:6379> TYPE schedule
zset
```

### Cheatsheet for Redis commands based on data type

Each Redis data type has its own set of commands for doing operations with the
key and its value. Here's a quick overview of the basic data types you would
encounter and some of the basic commands to set, retrieve and delete data from
them.

![A list of Redis commands for doing operations with each data type.](https://www.bigbinary.com/blog/images/images_used_in_blog/2023/redis-data-types-deep-dive/redis-commands-based-on-data-types.png)

Read more about the different data types in Redis and all the different commands
that are available in their
[official documentation](https://redis.io/docs/data-types/).

## Links

- [Human page](https://www.bigbinary.com/blog/redis-data-types-deep-dive)
