Sword redis Data Structure

Source: Internet
Author: User
Redis supports five data types: String, hash, list, set, and zset ).
String is the most basic type of redis. A key corresponds to a value. The string type is binary secure. It means that the redis string can contain any data. For example, JPG images or serialized objects. The string type is the most basic data type of redis, and the string type value can be stored at most 512 MB. Command Line syntax (redis> set key value Note: A key can store up to 512 MB.
Hash redis hash is a set of key-value (Key => value) pairs. Redis hash is a string-type field-value ing table. Hash is especially suitable for storing objects (in simple terms, it is similar to STD: map ). Using the redis hmset and hget commands, hmset sets two field => value pairs, and hget gets the value corresponding to the field. Each hash can store 232-1 key-value pairs (more than 4 billion ). Command Line syntax (redis commands are case-insensitive) redis> hmset hash structure name key of the first element value of the first element... redis> hget hash structure name key example: redis> hmset stinfo "name" "Tom" "Age" 15 -- defines a stinfo hash structure, the key of the first element is "name", and the value of the first element is "Tom" redis> hget stinfo "Age" -- get the value of the key "Age"
List (list) The redis list is a simple string list, sorted by the insertion order. You can add an element to the header (left) or tail (right) of the list ). The list can store up to 232-1 elements (4294967295, each list can store more than 4 billion ). Command Line Syntax -- insert an element from the header redis> lpush list structure name list element -- insert an element from the end redis> rpush list structure name list element -- print list element (as if there is no reverse print) redis> lrange list structure name start subscript (subscript starts from 0) end subscript (subscript can cross-border)

Set (SET) redis's set is a string-type unordered set (Set set is a list that cannot be repeated ). A set is implemented through a hash table. Therefore, the complexity of adding, deleting, and searching is O (1 ). If the key already holds another value, set overwrites the old value, regardless of the type. For a key with a TTL, when the set command is successfully executed on the key, the original TTL of the key will be cleared. The maximum number of members in a set is 232-1 (4294967295, each set can store more than 4 billion members ). The optional parameter starts with redis 2.6.12. The set command can be modified using a series of parameters: Ex Second: Set the key expiration time to second seconds. Set key value ex second is equivalent to setex key second value. Px millisecond: Set the key expiration time to millisecond in milliseconds. Set key value PX millisecond is equivalent to psetex key millisecond value. NX: Set the key only when the key does not exist. Set key value NX is equivalent to setnx key value. XX: Set the key only when the key already exists. Returned value: Before redis 2.6.12, the set command always returns OK. Starting from redis 2.6.12, set returns OK only when the setting operation is successful. If NX or XX is set, but the setting operation is not executed because the condition is not met, the command returns an empty batch reply (null bulk reply ). Command Line syntax-add an element regardless of its type, stored in the set will be converted to string type redis> sadd set structure name element -- view the set element list redis> smembers set structure name
Zset (sorted set: ordered set) redis zset and set are also a set of string elements, and repeated members are not allowed. The difference is that each element is associated with a score of the double type. Redis uses scores to sort members in a set from small to large. Zset members are unique, but scores can be repeated. The zadd command adds elements to the set, if an element exists in the Set, the corresponding score command line syntax is updated. -- add the element redis> zadd zset struct score member -- print the element redis> zrangebyscore runoob 0 1 according to the score range.

 

Sword redis Data Structure

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.