In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-01 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly introduces the data types supported by Redis. It is very detailed and has a certain reference value. Friends who are interested must read it!
Redis supports five data types: string (string), hash (hash), list (list), set (collection) and zset (sorted set: ordered collection).
Brief introduction:
1 、 string:
String is the most basic type of redis, which you can understand as exactly the same type as Memcached, with a key corresponding to a value.
The string type is binary safe. It means that the string of redis can contain any data. Such as jpg images or serialized objects.
The string type is the most basic data type of Redis, and the value of the string type can store 512MB at most.
Example:
Redis 127.0.0.1 OKredis 6379 > SET name "runoob" OKredis 127.0.0.1 runoob > GET name "runoob"
2 、 hash
Redis hash is a collection of key-value pairs (key= > value).
Redis hash is a mapping table for field and value of type string, and hash is particularly suitable for storing objects.
Example:
Redis 127.0.0.1 HMSET myhash field1 HMSET myhash field1 "Hello" field2 "World"OK" redis 127.0.0.1 HMSET myhash field1 6379 > HGET myhash field1 "Hello" redis 127.0.1 > HGET myhash field2 "World"
3 、 list
The Redis list is a simple list of strings sorted in the order in which they are inserted. You can add an element to the head (left) or tail (right) of the list.
Example:
Redis 127.0.0.1 > DEL runoobredis 127.0.0.1 > lpush runoobredis (integer) 1redis 127.0.0.1 > lpush runoob mongodb (integer) 2redis 127.0.0.1 > lpush runoob rabitmq (integer) 3redis 127.0.0.1 > lrange runoob 0101) "rabitmq" 2) "mongodb" 3) "redis" redis 127.0.1 >
Lists can store up to 232-1 elements (4294967295, each list can store more than 4 billion).
4. Set (collection)
The Set of Redis is an unordered collection of type string.
The collection is implemented through a hash table, so the complexity of adding, deleting, and finding is all O (1).
Sadd command
Add a string element to the set collection corresponding to key and successfully return 1. If the element has already returned 0 in the collection, an error will be returned if the set corresponding to key does not exist.
Sadd key member
Example:
Redis 127.0.0.1 sadd runoobredis (integer) 1redis 127.0.0.1 > sadd runoob mongodb (integer) 1redis 127.0.0.1 > sadd runoob rabitmq (integer) 1redis 127.0.0.1 > sadd runoob rabitmq (integer) 0redis 127.0.0.1 > smembers runoob1) "redis" 2) "rabitmq" 3) "mongodb"
5. Zset (sorted set: ordered set)
Redis zset, like set, is a collection of elements of type string, and duplicate members are not allowed.
The difference is that each element is associated with a score of type double. Redis sorts the members of the collection from small to large by scores.
The members of the zset are unique, but the score can be repeated.
Zadd command
Add an element to the collection, and update the corresponding score if the element exists in the collection
Example:
Redis 127.0.0.1 > DEL runoobredis 127.0.0.1 > zadd runoob 0redis (integer) 1redis 127.0.0.1 > zadd runoob 0 mongodb (integer) 1redis 127.0.0.1 > zadd runoob 0 rabitmq (integer) 1redis 127.0.0.1 integer > zadd runoob 0 rabitmq (integer) 0redis 127.0.1 > ZRANGEBYSCORE runoob 0 10001) "mongodb" 2) "rabitmq" 3) what are the data types supported by Redis? Thank you for reading! Hope to share the content to help you, more related knowledge, welcome to follow the industry information channel!
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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.