Redis data type string and its command

Source: Internet
Author: User
Tags time in milliseconds
String type

String-type stored value types include string, integer, floating point, and string-type commands that can process strings and integer elements.

Native commands

1. Set key value: Set the key value to value; instance: Set string1 'testyyy '.

2. Get key: Get the value of the specified key; instance: Get string1, returns testyyy.

3. getrange key start end: return the substring of the value of the specified key; instance: getrange string1 0 1; Return Value: Te, getrange string1 0-1; Return Value: testyyy, getrange string1-3-1, return value: yyy.

4. getSet key value: set the value of the specified key to value, and return the old value of the key (old value); instance: GetSet string1 youshuo, return value: testyyy, run get string1 again, return Value: youshuo.

5. getbit key offset: obtains the bit on the specified offset for the string value stored in the key. instance: getbit string1 1, return value: 1

6. mget key1, key2: Get the value of one or more given keys; instance: mget string1 string2; Return Value: "youshuo", "tettou ".

7. mset key value [key value]: set one or more key-value pairs at the same time. if and only if all the given keys do not exist, the instance: mset K1 'k111' K2 'k222 ', mget K1 K2, output "k111", "k222 ".

8. msetnx key value [key value]: one or more key-value pairs are set at the same time. if and only if none of the keys exist, instance: msetnx K3 'k3333 'K4 'k444444 ', run mget K3 K4 AND return values: k333 and k444.

9. setbit key offset value: set or clear the BIT (BIT) on the specified offset for the string value stored in the key. instance: setbit string1 15 0. Run get string1 and return: ynushuo, (each character is composed of 8-bit binary codes. If you modify one of the digits, the value is changed.) offset refers to the data offset at which point, value indicates the offset: 0 or 1.

10. setex key seconds value: Associate the value with the key, and set the expiration time of the key to seconds (in seconds); instance: setex string1 12 PPPP, run get string1 immediately, returned value: PPPP. After 12 seconds, run get string1. The returned value is null nil.

11. setnx key value: Set the key value only when the key does not exist. instance: setnx nokey 'llll ', run get nokey, return value: 'llll', and run setnx nokey 'kkkkk 'again ', return Value: 'llll '. The value of nokey remains unchanged.

12. setrange key offset value: the value parameter is used to overwrite the string value stored in the fixed key, starting from the offset. For example, if the value of string1 is youshuo, run setrange string1 3 'test ', the value of string1 is youtest.

13. strlen key: return the length of the string stored in the key; instance: strlen string1; Return Value: 7.

14. psetex key milliseconds value: similar to setex, but set the key survival time in milliseconds. instance: psetex pkey 4000 'ppp '.

15. incr key: add the number value stored in the key to one. For example, set NUM 1, incr num, and get num, the output num value is 2.

16. incrby key increment: add the value stored in the key to the given increment value; instance: incrby num 3, get num output num value: 5.

17. incrbyfloat key increment: add the value stored in the key to the given floating point increment value; incrbyfloat num 1.2, execute this command to directly return the num value: 6.2.

18. decr key: Reduce the number value stored in the key by one. For example, set num 6 and decr num, the output num value is 5.

19. decrby key decrement: The value stored by the key minus the given subtraction value; instance: decrby num 6, the output num value is-1.

20. append key value: if the key already exists and is a string, the APPEND Command appends the specified value to the end of the original value of the key. instance: append string1 'pop', get string1 output: youtestpop

Redis data type string and its command

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.