In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly explains the "order arrangement commonly used in Redis". The content of the explanation is simple and clear, and it is easy to learn and understand. Please follow the editor's train of thought to study and learn "Command arrangement commonly used in Redis".
Basic articles of common commands in Redis
Keys command
? Match a character
KEYS h?llo matches hello, hallo, hxllo and so on.
* match any (including 0) characters
KEYS h*llo matches hllo, heeeeello, and so on.
[] to match any character between parentheses, you can use the "-" symbol to indicate a range, such as "ab", "ac", "ad".
KEYS h [ae] llo matches hello and hallo but does not match hillo.
\ x matches the character x, which is used to escape symbols, if you want to match "?" You need to use\?
Determine whether a key value exists
Exists key
Returns integer type 1 if it exists, otherwise 0
Delete key
Del key [key.]
You can delete one or more keys, and the return value is the number of keys deleted.
Note: wildcard deletion is not supported
Get the data type of the key value
Type key
The return value may be string (string type) hash (hash type) list (list type) set (collection type) zset (ordered collection type)
Assignment and selection
Set key value assignment
EX second: sets the expiration time of the key to second seconds. The SET key value EX second effect is equivalent to SETEX key second value.
PX millisecond: sets the expiration time of the key to millisecond milliseconds. The SET key value PX millisecond effect is equivalent to PSETEX key millisecond value.
NX: set the key only when the key does not exist. The SET key value NX effect is equivalent to SETNX key value.
XX: set the key only if it already exists.
Get key value
Returns nil when key does not exist; otherwise, returns the value of key.
If key is not a string type, an error is returned.
Increasing number
Incr key
When the stored string is in the form of an integer, redis provides a command incr that is used to increment the current key value and return the incremented value
The default key value is 0 when the key to be operated does not exist, so the result after the first increment is 1, and redis will prompt an error when the key value is not an integer
Increase the specified integer
Incrby key increment
The incrby command is basically the same as the incr command, except that the former can specify an increment of values such as:
Incrby num 2
Incrby num 3
Reduce the specified integer
Decr key
Decrby key increment
The desc command uses the same as the incr command, except that the key value is decremented.
The decrby command is used the same as the incrby command
Increase the specified floating point number
Incrbyfloat key increment
The incrbyfloat command is similar to the incrby command, except that the former increments a double-precision floating-point number, such as:
Incrbyfloat num 2.7
Add value to the tail
Append key value
The function is to append value to the end of the key value, and if the key does not exist, set the key value to value, which is equivalent to set key value. The returned value is the length of the appended string
Such as: append foo "hello word!"
Get string length
Strlen key
Returns the length of the key value, or 0 if the key does not exist
Get / set multiple keys at the same time
Mget key [key.]
If a key does not exist in a given key, the key returns a special value, nil. Therefore, the command never fails.
Mset key value [key value.]
If a given key already exists, MSET will overwrite the old value with the new value, and if this is not what you want, consider using the MSETNX command: it will only set it if none of the given key exists.
Bit operation
A byte consists of eight binary bits, and redis provides four commands to operate directly on the binary bits
Getbit key offset
The getbit command can get the value (0 or 1) of the binary bit at the specified position of a string type key. The index starts at 0. If the index of the binary bit to be obtained exceeds the actual length of the binary bit of the key value, the default bit value is 0.
Setbit key offset value
The setbit command can set the value of the binary bit of the specified position of the string type key, and the return value is the old value of that position. If the position to be set exceeds the length of the binary bit of the key value, the setbit command will automatically set the middle binary bit to 0. Similarly, setting the specified binary bit value of a non-existent key will automatically assign the preceding bit to 0.
Bitcount key [strart] [end]
The bitcount command can get the number of binary bits in which the value of the string type key is 1. You can limit the byte range of statistics by parameter, for example, we want to count the first two bytes (i.e. "aa") command: bitcount foo 0 1
Bitop operation destkey key [key.]
The bittop command can perform bit operations on multiple string type keys and store the results in the key specified by the destkey parameter. The operations supported by this command are AND, OR, XOR, and NOT
For example, we perform OR operations on bar and aar:
Set foo1 bar
Set foo2 aar
Bitop OR res foo1 foo2
Get res
Thank you for your reading, the above is the content of "order arrangement commonly used in Redis". After the study of this article, I believe you have a deeper understanding of the command arrangement problem commonly used in Redis, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!
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.