Got it

HCIA-Big Data | Redis Features and Data Types

Latest reply: Jun 1, 2022 07:03:29 346 10 3 0 0

Hello, everyone!

In this post, I want to discuss Redis features and data types with you.

Introduction to Redis Features

Multiple databases

  • Each database is named in ascending order starting from 0 and cannot be customized.

  • By default, Redis supports 16 databases. Users can change the default number by modifying the database's parameter.

  • By default, Redis uses database 0.

  • SELECT number: Switches to the desired database by selecting a number.

  • The multiple databases are not completely isolated from each other. For example, the flushall command takes effect on all databases.

  • flushall: Clears data in all databases of a Redis instance.

  • flushdb: Clears data in the current database.

Redis Data Types

The Redis in-memory database can store mappings between keys and five data types: strings, hashes, lists, sets, and sorted sets. The following table compares the five data types, stored values, and semantics provided by Redis. 


Values Stored in the Structure

Read and Write Capabilities of the Structure


The value can be a character string, integer, or floating-point number.

Performs operations on the entire character string or a part of the character string, as well as increment or decrement operations on integers and floating-point numbers. 


The unordered hash list containing key-value pairs

Adds, obtains, and removes a single key-value pair; obtains all key-value pairs.


Adds, obtains, and removes a single key-value pair; obtains all key-value pairs.

Pushes or pops elements from two ends of the linked list and trims a linked list according to offsets. Reads one or more elements, and searches for or removes elements according to values.


The unordered collection contains character strings. Each character string 

contained in the unordered collection is unique and different from the others.

Adds, obtains, and removes a single element; checks whether an element exists in the collection; calculates the intersection sets, union sets, and difference sets; randomly obtains elements from a collection.

sorted sets

Sequential mapping between string members and floating point scores. The sequence of elements depends on the 


Adds, obtains, or deletes a single element; obtains elements based on the score range or members.

1. Redis Data Type - String

The string type is the most basic data type in Redis. It can store content in any form, including binary data and even an image (binary content). The maximum capacity for storing a string value is 1 GB.


  • set/get(setnx)

  • mset/mget

  • incr/decr/incrby/decrby/incrbyfloat

  • append

  • strlen

2. Redis Data Type - Hash

A hash value stores the mapping between fields and field values. The fields and field values must be strings. A hash key can store a maximum of fields.

Hash is suitable for storing objects.

Redis can add or delete fields for any key without affecting other keys.


hexists (Check whether the attribute in the key exists.)
hincrby (The hash type does not have the hincr command.)
hlen (Obtain the number of fields contained in a key.)

3. Redis Data Type - List

List is an ordered string list. The list is implemented using a bidirectional link (linked list). List can also be used as a queue.

A key of the list type can contain a maximum of elements.


llen/lrange (-1 indicates the location of the last element.)
lrem (lrem key count value) count has the following three situations:
count > 0: searches from the table header to the table tail and removes the elements whose values are equal to value. The number of elements is count.
count < 0: searches from the table tail to the table header and removes the elements whose values are equal to value. The 
number of elements is the absolute value of count.
count = 0: removes all elements whose values are equal to value from the table.
lindex: queries the data of a specified corner mark.
lset: changes the value of a specified corner mark.
ltrim: truncates and retains the specified data.
linsert: inserts elements before and after a specified element.
rpoplpush: transfers an element from one list to another.

4. Redis Data Type - Set

The elements in a set are not duplicate and are unordered. A key of the set type can store a maximum of elements.


sdiff (difference set)/sinter (intersection set)/sunion (union set);
scard (Obtains the set length.)/spop (Randomly takes an element out of the set and deletes it.);
srandmember key [count]:
If count is a positive number and less than the set cardinality, the command returns an array 
containing count different elements.
If count is greater than or equal to the set cardinality, the entire set is returned.
If count is a negative number, the command returns an array. The elements in the a ray may 
appear multiple times, and the length of the array is the absolute value of count.

5. Redis Data Type - Sorted Set

Each element in the set is associated with a score based on the set type. In this way, N elements with the highest scores can be easily obtained.


zrangebyscore (A closed interval is used by default. Users can use "(" to adopt an 
open interval.)
zincrby/zcard/zcount (Obtains the number of elements in a specified score range. A 
closed interval is used by default. Users can use "(" to adopt an open interval.)
zrem/zremrangebyrank/zremrangebyscore (A closed interval is used by default. 
Users can use "(" to adopt an open interval.)
Extension: +inf (positive infinity) -inf (negative infinity)

That's all, thanks!

The post is synchronized to: HCIA-Big Data

  • x
  • convention:

Moderator Author Created May 26, 2022 07:59:59

Redis keys are binary safe, which means that any binary sequence, from a string like "foo" to the content of a JPEG file, can be used as a key. The empty string can also be used as a key.
View more
  • x
  • convention:

Moderator Author Created May 26, 2022 08:03:51

Redis is more than just a key-value store; it's a data structures server that can handle a wide range of values. This means that, unlike typical key-value stores, where string keys are associated with string values, Redis allows for more complicated data structures to be stored in the value.
View more
  • x
  • convention:

olive.zhao Created May 27, 2022 08:58:44 (0) (0)
Thanks for your sharing!  
Created May 26, 2022 10:12:18

View more
  • x
  • convention:

Created May 26, 2022 10:12:26

HCIA-Big Data | Redis Features and Data Types-4959515-1
View more
  • x
  • convention:

olive.zhao Created May 27, 2022 08:58:51 (0) (0)
Created May 31, 2022 15:23:19

Thanks for sharing
View more
  • x
  • convention:

olive.zhao Created Jun 1, 2022 00:51:43 (0) (0)
Created Jun 1, 2022 07:03:29

Thank you for giving this useful information.
View more
  • x
  • convention:

olive.zhao Created Jun 6, 2022 08:24:55 (0) (0)


You need to log in to comment to the post Login | Register

Notice: To protect the legitimate rights and interests of you, the community, and third parties, do not release content that may bring legal risks to all parties, including but are not limited to the following:
  • Politically sensitive content
  • Content concerning pornography, gambling, and drug abuse
  • Content that may disclose or infringe upon others ' commercial secrets, intellectual properties, including trade marks, copyrights, and patents, and personal privacy
Do not share your account and password with others. All operations performed using your account will be regarded as your own actions and all consequences arising therefrom will be borne by you. For details, see " User Agreement."

My Followers

Login and enjoy all the member benefits


Are you sure to block this user?
Users on your blacklist cannot comment on your post,cannot mention you, cannot send you private messages.
Please bind your phone number to obtain invitation bonus.
Information Protection Guide
Thanks for using Huawei Enterprise Support Community! We will help you learn how we collect, use, store and share your personal information and the rights you have in accordance with Privacy Policy and User Agreement.