In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-23 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >
Share
Shulou(Shulou.com)06/01 Report--
Set key value [ex seconds] / [px milliseconds] [nx] / [xx]
For example, set a 1 ex 10, valid for 10 seconds
Set a 1 px 9000, valid for 9 seconds
Note: if ex,px writes at the same time, the later period of validity shall prevail.
For example, set a 1 ex 100 px 9000 is valid for 9000 milliseconds
Nx: indicates that the operation is performed when the key does not exist
Xx: indicates that the operation is performed when key exists
Mset multi set, which sets multiple keys at a time
Example: mset key1 v1 key2 v2....
Get key
Function: get the value of key
Mget key1 key2.. keyn
Function: get the values of multiple key
Setrange key offset value
Function: change the offset offset byte of a string to value
Redis 127.0.0.1 6379 > set greet hello
OK
Redis 127.0.0.1 6379 > setrange greet 2 x
(integer) 5
Redis 127.0.0.1 6379 > get greet
"hexlo"
Note: if offset > character length, the character automatically complements 0x00
Redis 127.0.0.1 6379 > setrange greet 6!
(integer) 7
Redis 127.0.0.1 6379 > get greet
"heyyo\ X00!"
Append key value
Function: append value to the original value of key
Getrange key start stop
Function: to get the value in the range of [start, stop] in the string
Note: for the subscript of a string, the left number starts at 0 and the right number starts at-1
Redis 127.0.0.1 redis 6379 > set title 'chinese'
OK
Redis 127.0.0.1 6379 > getrange title 0 3
"chin"
Redis 127.0.0.1 6379 > getrange title 1-2
"hines"
Note:
1: start > = length, an empty string is returned
2: stop > = length, truncate to the end of the character
3: if start is located to the right of stop, an empty string is returned.
Getset key newvalue
Function: get and return the old value, set the new value
Redis 127.0.0.1 6379 > set cnt 0
OK
Redis 127.0.0.1 6379 > getset cnt 1
"0"
Redis 127.0.0.1 6379 > getset cnt 2
"1"
Incr key
Function: add 1 to the specified value of key, and return the value after adding 1
Note:
1: key that does not exist is regarded as 0, and then incr operation
2: the range is 64 signed
Incrby key number
Redis 127.0.0.1 6379 > incrby age 90
(integer) 92
Incrbyfloat key floatnumber
Redis 127.0.0.1 6379 > incrbyfloat age 3.5
"95.5"
Decr key
Redis 127.0.0.1 6379 > set age 20
OK
Redis 127.0.0.1 6379 > decr age
(integer) 19
(second kill, panic buying can be done with decr)
Decrby key number
Redis 127.0.0.1 6379 > decrby age 3
(integer) 16
Getbit key offset
Function: get the binary representation of the value, the value on the corresponding bit (from the left, numbered from 0)
Redis 127.0.0.1 6379 > set char A
OK
Redis 127.0.0.1 6379 > getbit char 1
(integer) 1
Redis 127.0.0.1 6379 > getbit char 2
(integer) 0
Redis 127.0.0.1 6379 > getbit char 7
(integer) 1
Setbit key offset value
Set the value on the binary bit corresponding to offset
Return: the old value on this bit
Note:
1: if the offset is too large, 0 will be filled in the middle
2: what is the maximum offset?
The maximum 3:offset is 2 ^ 32-1, and the maximum string that can be deduced is 512m.
Case conversion:
Bitop operation destkey key1 [key2...]
Operation the key1,key2..keyN and save the results to destkey.
Operation can be AND, OR, NOT, XOR
Redis 127.0.0.1 6379 > setbit lower 7 0
(integer) 0
Redis 127.0.0.1 6379 > setbit lower 2 1
(integer) 0
Redis 127.0.0.1 6379 > get lower
"
Redis 127.0.0.1 6379 > set char Q
OK
Redis 127.0.0.1 6379 > get char
"Q"
Redis 127.0.0.1 6379 > bitop or char char lower
(integer) 1
Redis 127.0.0.1 6379 > get char
"Q"
Note: for NOT operations, key cannot have more than one
Note:
When saving session, it should be in hash!
(1) Strings are only used in small-scale data records. If the amount of data exceeds the million level, using strings to save simple mapping relationships will waste a lot of memory. At this point, you need to use another data structure of Redis-Hash. To store data of the same order of magnitude, the memory consumed by the Hash structure is only 1x4 of the string structure, but the query speed is no worse than the string. The structure of Hash will be explained in Chapter 9.
(2) if there is a large amount of Key in the Redis, the execution of the "keys *" command will have a temporary impact on the performance of the Redis, and even cause the Redis to lose its response. Therefore, you should never rashly list all the current Key without knowing how many Key there are.
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.