Redis - SPLessons
SPLessons 5 Steps, 3 Clicks
5 Steps - 3 Clicks

Redis Data Types

Redis Data Types

shape Description

If the client comes from a relational database background,the user probably find Redis to be very different from any database. Even if the client uses some NoSQL databases like Ravendb or Mongodb and probably still finds Redis to be quite unique and it is critical to understand what exactly how this Redis operations are performed and properly set the expectation moving forward. Redis is an open source database. Redis is bit different than jut a dictionary or a map,because even through it uses keys and values, the values are actually structured data types.

Data types in Redis

shape Description

They are 5 different datatypes in Redis server, such as:

Strings

shape Description

Redis string is a sequence of bytes. Strings in Redis are binary safe, meaning they have a known length not determined by any special terminating characters, so you can store anything up to 512 megabytes in one string.

shape Examples

The below example describes the string data type. [sql] redis 127.0.0.1:6379> SET name "SPLessons" OK redis 127.0.0.1:6379> GET name "SPLessons"[/sql]

Hashes

shape Description

A Redis hash is a gathering of key esteem sets. Redis Hashes are maps between string fields and string values, so they are utilized for representing the objects.

shape Examples

The below example describes the hashes data type.[sql] redis 127.0.0.1:6379> HMSET user:1 username splessons password splessons points 200 OK redis 127.0.0.1:6379> HGETALL user:1 1) "username" 2) "SPLessons" 3) "password" 4) "SPLessons" 5) "points" 6) "200" [/sql]

Lists

shape Description

Redis Lists are just arrangements of strings, sorted by inclusion arrange. You can add components to a Redis List on the head or on the tail.

shape Examples

The below example describes the list data type.[sql] redis 127.0.0.1:6379> lpush splessons redis (integer) 1 redis 127.0.0.1:6379> lpush splessons mongodb (integer) 2 redis 127.0.0.1:6379> lpush splessons rabitmq (integer) 3 redis 127.0.0.1:6379> lrange splessons 0 10 1) "rabitmq" 2) "mongodb" 3) "redis"[/sql]

Sets

shape Description

Redis Sets are an unordered collection of Strings. In redis you can add, remove, and test for existence of members in O(1) time complexity.

shape Examples

The below example describes the sets data type. [sql] redis 127.0.0.1:6379> sadd tutoriallist redis (integer) 1 redis 127.0.0.1:6379> sadd splessons mongodb (integer) 1 redis 127.0.0.1:6379> sadd splessons rabitmq (integer) 1 redis 127.0.0.1:6379> sadd splessons rabitmq (integer) 0 redis 127.0.0.1:6379> smembers splessons 1) "rabitmq" 2) "mongodb" 3) "redis" [/sql]

Sorted sets

shape Description

Redis Sorted Sets are, similarly to Redis Sets, non repeating collections of Strings. The difference is that every member of a Sorted Set is associated with score, that is used in order to take the sorted set ordered, from the smallest to the greatest score. While members are unique, scores may be repeated.

shape Examples

The below example describes the stored sets data type.[sql] redis 127.0.0.1:6379> zadd tutoriallist 0 redis (integer) 1 redis 127.0.0.1:6379> zadd splessons 0 mongodb (integer) 1 redis 127.0.0.1:6379> zadd splessons 0 rabitmq (integer) 1 redis 127.0.0.1:6379> zadd splessons 0 rabitmq (integer) 0 redis 127.0.0.1:6379> ZRANGEBYSCORE splessons 0 1000 1) "redis" 2) "mongodb" 3) "rabitmq"[/sql]

Summary

shape Key Points

  • Data types - Describes different types in Redis server data type.