In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >
Share
Shulou(Shulou.com)06/01 Report--
What are the common commands of redis? Redis commonly used commands, many people do not know, today Xiaobian in order to let everyone know more about redis commonly used commands, so to summarize the following content for everyone, look down together. I'm sure you'll find something.
Key related:
(1) redis allows fuzzy query key (keys *) with 3 wildcards *,?, []
(2) randomkey: Return random key
(3) key type: returns the type of key stored
(4) exists key: determine whether a key exists
5) Delete key: delete key
FLUSHALL: Delete all keys (caution)
II. Data manipulation:
Redis supports five data types: string, hash, list, set, and zset.
1. string (character string)
A key corresponds to a value. One key can store up to 512MB. String type is binary safe.
(1) set key value [ex seconds] [px milliseconds] [nx/xx]
If ex and px are written at the same time, the validity period after shall prevail.
nx: Create if key does not exist
xx: modify the value of key if it exists
(2) Get key: value
(3) mset key1 value1 key2 value2 set multiple values at once
(4) mget key1 key2: get multiple values at once
(5) setrange key offset value: change the offset byte of the string to value
If offset> string length, the character is automatically complemented by 0x00
(6) append key value: appends value to the original value of the key
(7) getrange key start stop: Get the value of the [start, stop] range in the string
For subscripts of strings, the left starts at 0 and the right starts at-1.
Note:
When start>length, return empty string
When stop>=length, truncate to end of string
If start is to the right of stop, return an empty string
(8) getset key nrevalue: get and return the old value, set the new value
2. hash
Redis hash is a mapping table of field and value of type string, hash is especially suitable for storing objects. Each hash can store 232 - 1 key-value pairs (more than 4 billion).
hset myhash field value: Set myhash field value to value
(2) hsetnx myhash field value: if it does not exist, set myhash field to value.
hmset myhash field1 value1 field2 value2: setting multiple fields simultaneously
(4) hget myhash field: get the specified hash field
hmget myhash field1 field2: Get multiple fields at once
(6) hincrby myhash field 5: The specified hash field plus the given value
hashes myhash field: tests whether the specified field exists
(8) hlen myhash: Number of fields that return hash
(9) hdel myhash field: delete the specified field
(10) hkeys myhash: returns hash all fields
(11) hvals myhash: Returns all values of hash
(12) hgetall myhash: Get all fields and values in a hash
3. List
A Redis list is a simple list of strings, sorted in insertion order. You can add an element to the list either at the head (left) or at the tail (right). Lists can store up to 232 - 1 elements (4294967295, more than 4 billion per list).
(1) lpush key value: insert the value into the head of the list
push key value: insert the value at the end of the list
(3) lpop key: Return and delete the head element of the list
(4) rpop key: Return and delete the tail element of the linked list
(5) lrange key start stop: Returns the elements in the list [start, stop]
(6) lrem key count value: delete the value value from the list, delete the absolute value of count and end
count > 0 Remove from header
count < 0 Remove from end of table
count=0 Delete all
(7) ltrim key start stop: Cut the link corresponding to key, cut [start, stop] and assign the modification to key again.
(8) lindex key index: Returns the value on index
4. Set
A Set of Redis is an unordered collection of type string. Values are not repeated.
(1) sadd key value1 value2: add an element to a collection
smembers key: Gets all elements of the collection
(3) Srem key value: delete an element of the set
(4) spop key: returns and deletes 1 random element from the collection (can sit in the lottery, will not repeatedly draw someone)
(5) srandmember key: take an element at random
sismember key value: Determine whether the set has a value
scard key: Returns the number of elements in the collection
(8) Move source dest value: move the value of source to the dest set
(9) sinter key1 key2 key3: find the intersection of key1 key2 key3
sunion key1 key2: find the union of key1 key2
(11) sdiff key1 key2: find the difference set of key1 key2
(12) sinterstore res key1 key2: find the intersection of key1 key2 and exist in res
zset (sorted set)
Redis zset, like set, is a collection of string elements. Duplicate members are not allowed. The difference is that each element is associated with a fraction of type double. Redis uses scores to sort the members of a collection from small to large. The members of zset are unique, but scores can be repeated.
(1) zadd key score1 value1: add element
(2) zrange key start stop [discard]: After sorting the set, return the element ranked [start,stop]
The default is ascending arrangement withscores, which prints out score as well.
(3) zrank key member: query the ranking of members (starting from 0)
(4) zrangebyscore key min max [withscores] limit offset N: set (ascending order)
After sorting, take the elements whose score is within [min, max], skip offset, and take N.
(5) zrevrank key member: query member ranking (descending order starts with 0)
(6) zremrangebyscore key min max: delete elements according to score, delete score between [min, max]
(7) zrem key value1 value2: delete elements from the collection
(8) zremrangebyrank key start end: delete elements by rank, delete elements between [start, end]
(9) zcard key: Returns the number of elements in the collection
(10) zcount key min max: Returns the number of elements in the interval [min, max]
What are the common commands of redis? Redis common command complete details, after reading whether there is a harvest? If you want to know more, welcome to the industry news!
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.