redis data type _ dynamic node Java college collation
- 2020-06-01 11:16:16
Redis supports five data types, which are described as follows:
Strings - string
The string for Redis is a sequence of bytes. Strings in Redis are base 2 safe, which means they have a known length and are not terminated by any special characters, so they can store anything up to 512 megabytes in length.
redis 127.0.0.1:6379> SET name "yiibai" OK redis 127.0.0.1:6379> GET name "yiibai"
The above example USES the Redis commands set and get, and Redis's name is yiibai's key stored in Redis's string value.
Note: string values can store up to 512 megabytes in length.
Hashes - hash
A collection of hash key-value pairs for Redis. The hash value of Redis is a mapping between string fields and string values, so they are used to represent objects
redis 127.0.0.1:6379> HMSET user:1 username yiibai password yiibai points 200 OK redis 127.0.0.1:6379> HGETALL user:1 1) "username" 2) "yiibai" 3) "password" 4) "yiibai" 5) "points" 6) "200"
The hash data type in the example above 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 (over 41 billion).
Lists list -
Redis's list is a simple list of strings, sorted in insertion order. You can add elements to the head or tail of the Redis list.
redis 127.0.0.1:6379> lpush tutoriallist redis (integer) 1 redis 127.0.0.1:6379> lpush tutoriallist mongodb (integer) 2 redis 127.0.0.1:6379> lpush tutoriallist rabitmq (integer) 3 redis 127.0.0.1:6379> lrange tutoriallist 0 10 1) "rabitmq" 2) "mongodb" 3) "redis"
The maximum length of the list is 232-1 elements (4294967295, each with more than 41 billion elements).
Sets collection -
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 member.
redis 127.0.0.1:6379> sadd tutoriallist redis (integer) 1 redis 127.0.0.1:6379> sadd tutoriallist mongodb (integer) 1 redis 127.0.0.1:6379> sadd tutoriallist rabitmq (integer) 1 redis 127.0.0.1:6379> sadd tutoriallist rabitmq (integer) 0 redis 127.0.0.1:6379> smembers tutoriallist 1) "rabitmq" 2) "mongodb" 3) "redis"
Note: in the above example, rabitmq sets the property to be added twice, but only once because of the singibility.
The maximum number of sets among members is 232-1 (4294967295, with more than 41 billion members).
The collection ordering of Redis is similar to the collection of Redis, which does not repeat the string. The difference is that each member of an ordered set is associated with a score used to take the ordered set command, from the smallest to the largest score concerned. Although all members are unique, the score may be repeated.
redis 127.0.0.1:6379> zadd tutoriallist 0 redis (integer) 1 redis 127.0.0.1:6379> zadd tutoriallist 0 mongodb (integer) 1 redis 127.0.0.1:6379> zadd tutoriallist 0 rabitmq (integer) 1 redis 127.0.0.1:6379> zadd tutoriallist 0 rabitmq (integer) 0 redis 127.0.0.1:6379> ZRANGEBYSCORE tutoriallist 0 1000 1) "redis" 2) "mongodb" 3) "rabitmq"