Redis Common Commands

Source: Internet
Author: User

Key command

keys patternGet all keys to find all keys that match a given pattern pattern
del keyDelete one or more keys, the nonexistent key is ignored, the return value: the number of deleted keys
exists keyCheck if key exists
Expire key secondSet expiration time for key
ttl keyReturns the remaining valid time for a given key, in seconds
persist keyClears the expiration time of the key. Key persistence.

String:key-value (do Cache)

All data in Redis is a string. The command is case-insensitive, and key is casing-sensitive. Redis is single-threaded. Redis is not suitable for storing large-content data.

get keyReturns the string value associated with key, or returns an error if the value stored by key is not a string type.
set key valueAssociating a string value to a key
incr keyIncrease the numeric value stored in key by one. Failure to convert to a number is an error.
decr keySubtract one of the numeric values stored in the key. Key does not exist, the value of the 0,key type incorrectly returns an error.

Hash:key-fields-values (do Cache)

Equivalent to a key for a map,map and key-value, use hash to classify key.

hset key field valueSet the value of the Field field in hash table key to value
hget key fieldReturns the value of the given field field in the hash table key
hel key fieldDeletes one or more specified domains in the hash table key, and the nonexistent fields are ignored.
hgetall keyReturns the hash table key, all fields and values
hexists key fieldView Hash table key, whether a given domain field exists
hkeys keyReturns all the fields in the hash table key
hvals keyReturns the value of all fields in the hash table key

List: Sequential and repeatable

lpush key valueInserts one or more value values into the table header of the list key
lpop keyRemove and return the header element of the list key
rpush key valueInserts one or more value values into the footer of the list key
rpop keyRemove and return the tail element of the list key
lrange list 0 -1Returns the element in the specified interval in the list key, with the interval specified by the offset start and stop

Set: elements are not sequential and cannot be duplicated

sadd key memberAdding one or more member elements to the collection key, member elements that already exist in the collection will be ignored
smembers set1Returns all members in the collection key
srem key memberRemoves one or more member elements from the collection key, and the nonexistent member element is ignored

SortedSet (Zset): sequential, cannot repeat

zadd key memberAdds one or more member elements and their score values to the ordered set key
zrem key memberRemove one or more members from an ordered set key, the nonexistent member will be ignored
zrange key 0 -1Returns the member within the specified range (small to large) in the ordered set key
zrevrange key 0 -1Returns the rank of the member member in the ordered set key. Where ordered set members are sorted by score value descending (from large to small)
zrange key 0 -1 withscoresReturns the member within the specified interval in the ordinal set key, including the value of the

Redis Common Commands

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.