In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-13 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly introduces "what are the Redis string commands". In the daily operation, I believe many people have doubts about the Redis string commands. The editor consulted all kinds of materials and sorted out simple and easy-to-use operation methods. I hope it will be helpful for you to answer the doubts about "what are the Redis string commands?" Next, please follow the editor to study!
APPEND
When using the APPEND command, if key already exists, the value will be appended directly after value. If key does not exist, a key with an empty string value will be created first, and then appended:
127.0.0.1 APPEND hello (integer) 5127.0.0.1 integer 6379 > GET K1 "hello" 127.0.0.1 GET 6379 > APPEND K1 world (integer) 10127.0.1 DECR > GET K1 "helloworld" DECR
The DECR command can subtract 1 from value. If key does not exist, the initial value of key will be set to 0. If the value of key is not a number, an error will be reported as follows:
127.0.0.1 SET 19OK127.0.0.1:6379 > DECR K3 (integer) 18127.0.1 DECR 6379 > GET K3 "18" 127.0.1 DECR 6379 > SET K4 aaOK127.0.0.1:6379 > DECR K4 (error) ERR value is not an integer or out of rangeDECRBY
DECRBY is similar to DECR, except that DECRBY can specify the step size as follows:
127.0.0.1 GET 6379 > GET K3 "8" 127.0.0.1 integer 6379 > GET K3 "4" GET
The GET command is used to get the value of the corresponding key, and returns nil if the key does not exist, as follows:
127.0.0.1 GETRANGE 6379 > GET K5 (nil)
GETRANGE is used to return the substring of the value corresponding to key. The substring is determined by start and end and is calculated from left to right. If the subscript is negative, it is calculated from right to left, where-1 represents the last character and-2 is the penultimate character. , as follows:
127.0.0.1 SET helloworldOK127.0.0.1:6379 > GETRANGE K10 2 "hel" 127.0.0.1 GETRANGE 6379 > GETRANGE K1-3-1 "rld" GETSET
The GETSET command can be used to obtain the value corresponding to key and reset the key, as follows:
127.0.0.1 vv 6379 > SET K1 v1OK127.0.0.1:6379 > GET K1 "v1" 127.0.0.1 vv 6379 > GET K1 "vv" INCR
The INCR operation can add 1 to the value of the specified key. If the specified key does not exist, the value of the key will be set to 0 before the add 1 operation. If the value of the key is not a number, an error will be reported. As follows:
127.0.0.1 1INCRBY 6379 > INCR K2 (integer)
The functions of INCRBY and INCR are similar, except that you can specify the step size for growth, as follows:
127.0.0.1 100INCRBYFLOAT 6379 > INCRBY k2 99 (integer)
The INCRBYFLOAT command can be used to grow floating-point numbers, as follows:
127.0.0.1 MGET 6379 > SET K1 0.5OK127.0.0.1:6379 > INCRBYFLOAT K1 0.33 "0.83" MGET and MSET
MGET and MSET are used to set and obtain values in batches, respectively, as follows:
127.0.0.1 MGET 6379 > MSET K1 v1 K2 v2 K3 v3OK127.0.0.1:6379 > MGET K1 K2 K31) "v1" 2) "v2" 3) "v3" SETEX
SETEX is used to set value and expiration time for key, which is equivalent to setting value for key and then expiration time for key, as shown below:
127.0.0.1 TTL 6379 > GET K1 "v1" PSETEX > TTL K1 30 v1OK127.0.0.1:6379 > TTL K1 (integer) 26127.0.1
The function of PSETEX is similar to that of SETEX, except that the expiration time is set in milliseconds, as follows:
127.0.1 PTTL 6379 > PSETEX K1 60000 v1OK127.0.0.1:6379 > PTTL K1 (integer) 55412SETNX
SETNX is an abbreviation for SET if Not eXists. When the SET command is executed, if key already exists, the new value overwrites the old value, while for the SETNX command, if key already exists, nothing is done, and if key does not exist, the effect is equivalent to the SET command. As follows:
127.0.0.1 vv 6379 > SETNX K1 v1 (integer) 1127.0.0.1 vv (integer) 0127.0.1 vv 6379 > GET K1 "v1" MSETNX
MSETNX has the characteristics of both SETNX and MSET, but when MSETNX is executed, if there is a key, none of it will be executed, as follows:
127.0.0.1 6379 > MSETNX K1 v1 K2 v2 (integer) 0
Because K1 already exists, K2 does not execute successfully.
SETRANGE
SETRANGE is used to overwrite the value of an existing key, as follows:
127.0.0.1 set helloworldOK127.0.0.1:6379 > get K1 "helloworld" 127.0.0.1 get 6379 > SETRANGE K1 5 redis (integer) 10127.0.0.1 get 6379 > get K1 "helloredis"
However, if the value length of the existing key is less than offset, the deficiency is made up with 0, as follows:
127.0.0.1 set K1 helloredisOK127.0.0.1:6379 > SETRANGE K1 20-- java (integer) 26127.0.0.1 SETRANGE 6379 > GET K1 "helloredis\ X00\ x00--java" STRLEN
STRLEN is used to calculate the length of the value of key, as follows:
127.0.1 STRLEN 6379 > Redis K1 (integer) 26 at this point, the study of "what are the Redis string commands" is over. I hope I can solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!
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.