Data types and setting methods of redis
1. Five data types supported by redis: string (string), Hash (hash), list (list), set (collection), and zset (ordered collection)
2. String is the most basic type of redis. A key can support storing 512MB at most.
Set name "lanyulei"
Del name
/ / set a key to be name, and the corresponding value to be a string of Lan Yulei
Get name
/ / result set is "lanyulei"
3. Redis hash is a mapping table of field and value of string type, and hash is especially suitable for storing objects.
Hmset user username lanyulei sex man age 25
/ / set a hash value. Key is an even-numbered form of user,value.
Each hash can store 2 to the power of 32-1, key-value pairs (more than 4 billion)
4. Redis is a simple list of strings, sorted in the order in which they are inserted, and you can add the header or tail of the element lead list.
/ / set a list type data named lanyulei, and the content is added and displayed sequentially.
Lpush lanyulei redis
Lpush lanyulei mongodb
Lpush lanyulei rabitmq
/ / to get the value,0 10 of this list "lanyulei" means to get the data before the subscript 0 to 10.
Lrange lanyulei 0 10
5. Unordered collection creation
/ / set an unordered collection
Sadd lanyulei redis
Sadd lanyulei mongodb
Sadd lanyulei mysql
Sadd lanyulei mysql
/ / get the contents of this collection
Smembers lanyulei
6. Creation of ordered sets
/ / an ordered collection, like a collection, is a collection of elements of type string, and duplicate members are not allowed.
/ / the members of an ordered set are unique, but the score can be repeated.
Zadd lanyulei redis
Zadd lanyulei mongodb
Zadd lanyulei mysql
Zadd lanyulei mysql
/ / get the contents of this collection
Zmembers lanyulei