Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Redis series-3, Redis data type

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)06/01 Report--

Redis supports five data types, which are described below:

Strings-string

The string of Redis is a sequence of bytes. Strings are binary safe in Redis, which means they have a known length and are not determined by any special character termination, so they can store anything up to 512 megabytes in length.

Example redis 127.0.0.1 OKredis 6379 > SET name "yiibai" OKredis 127.0.0.1 yiibai > GET name "yiibai"

In the above example, using the Redis commands set and get,Redis, the key whose name is yiibai is stored in the string value of Redis.

Note: string values can store a maximum length of 512 megabytes.

Hashes-hash value

A collection of hash key value pairs for Redis. The hash values of Redis are mappings between string fields and string values, so they are used to represent objects

Example redis 127.0.0.1 HGETALL user:11 > HGETALL user:11) "username" 2) "yiibai" 3) "password" 4) "yiibai" 5) "points" 6) "200"

The hash data type in the above example is used to store the user's object that contains the user's basic information.

Here HMSET,HEXTALL is the key for the Redis command user:1.

Each hash can store up to 232-1 field-value pairs (more than 4 billion).

Lists-list

The list of Redis is a simple list of strings that sorts the insertion order. You can add elements to the head or tail of the Redis list.

Example: redis 127.0.0.1 1redis 6379 > lpush tutoriallist redis (integer) 1redis 127.0.0.1 1redis 6379 > lpush tutoriallist mongodb (integer) 2redis 127.0.0.1 1redis 6379 > lpush tutoriallist rabitmq (integer) 3redis 127.0.1 lrange tutoriallist 0101) "rabitmq" 2) "mongodb" 3) "redis"

The maximum length of the list is 232-1 elements (4294967295, with more than 4 billion elements in each list).

Sets-set

The Redis collection is an unordered collection of strings. In Redis, you can add, delete, and test whether files exist in O (1) time complexity members.

Example redis 127.0.0.1 1redis 6379 > sadd tutoriallist mongodb (integer) 1redis 127.0.0.1 1redis 6379 > sadd tutoriallist rabitmq (integer) 1redis 127.0.1 1redis 6379 > sadd tutoriallist rabitmq (integer) 0redis 127.0.0.1 1redis 6379 > smembers tutoriallist1) "rabitmq" 2) "mongodb" 3) "redis"

Note: in the above example, the rabitmq setting property is added twice, but only once because of uniqueness.

The maximum number of sets in the members is 4294967295 (with more than 4 billion members).

Ordered set

The ordered collection of Redis is similar to the Redis collection, with non-repeating strings. The difference is that each member of an ordered set is associated with a score, which is used to take ordered set commands, from the lowest to the highest score. Although the members are unique, the scores may be repeated.

Example redis 127.0.0.1 1redis 6379 > zadd tutoriallist 0redis (integer) 1redis 127.0.0.1 integer 6379 > zadd tutoriallist 0 mongodb (integer) 1redis 127.0.0.1 1redis 127.0.0.1 integer > zadd tutoriallist 0 rabitmq (integer) 0redis 127.0.0.1) ZRANGEBYSCORE tutoriallist 0 10001) "redis" 2) "mongodb" 3) "rabitmq"

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Database

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report