Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What are the Redis commands?

2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)05/31 Report--

This article mainly introduces what the Redis command has, has a certain reference value, interested friends can refer to, I hope you can learn a lot after reading this article, the following let the editor take you to understand it.

Password login:

1. Redis-cli-h 127.0.0.1-p 6379-a flyvar

String type:

1. Set name ericzhao / / set key value [EX seconds] [PX milliseconds] [NX | XX]

2. Redis 127.0.0.1 SET KEY VALUE 6379 > SET KEY VALUE [EX seconds] [PX milliseconds] [NX | XX] EX seconds − sets the specified expiration time (in seconds). PX milliseconds-sets the specified expiration time in milliseconds. NX-set the key only if the key does not exist. XX-set only if the key already exists.

3. Redis 127.0.0.1 EX 6379 > SET mykey "redis" EX 60 NX / / if the key "mykey" does not exist, set the value of the key with an expiration time of 60 seconds.

4. Get name

5. Keys * / / View all key

6. Getrange name 0 1 / / getrange key start end gets the subcharacters in the string

7. Getset name zhao / / getset key value sets the value of key to value and returns the old value of key. No old value, return nil

8. Mget name age / / mget key [key2...] Get the values of multiple key

9. Mset name zhao age 18 / / set multiple key-value, atomicity

10. Setex name 1 zhao / / setex key seconds value sets the expiration time of key to seconds seconds [isn't setnx atomic?]

11. Psetex name 1 zhao / / psetex key milliseconds value sets the expiration time of key to milliseconds milliseconds

12. Setnx name zhao / / setnx key value sets the value of key to value when key does not exist

13. Msetnx name zhao age 10 / / msetnx key value [key1 value1...] Batch setting when key does not exist

14. Strlen name / / strlen key gets the length of the string value of key

15. Incr age / / incr key sets the numeric value in key + 1

16. Incrby age 7 / / incrby key increment changes the numeric value in key + increment

17. Decr age

18. Decrby age 7

19. Append name wei / / append key value if key exists and is a string, value is best to the end of the value of key, and the length of the string value of key is returned

20. Del age / / del key delete a single key

21. Redis-cli keys "*" | xargs redis-cli del / / Delete multiple key

twenty-two。 Flushdb / / Delete all Key in the current database

23. Flushall / / Delete key from all databases

Hash type:

1. Hset person family-name zhao

2. Hget people family-name

3. Hmset people family-name zhao first-name wei / / hmset key field value [field value...] Each hash can store up to 2 ^ 32-1 key-value pairs.

4. 127.0.0.1 hmset people family-name zhao first-name weiOK127.0.0.1:6379 > hget people family-name "zhao" 127.0.0.1 zhao > hgetall people1) "family-name" 2) "zhao" 3) "first-name" 4) "wei"

5. Hmget people family-name first-name / / hmget key field1 [field2...] Get the values of multiple fields in key

6. Hgetall people / / hgetall key gets all fields and values in key

7. Hdel people family-name / / hdel key field1 [field2...] Delete multiple hash fields

8. Hexists people family-name / / hexists key field to check whether the field field exists in key

9. Hincrby people age 12 / / hincrby key field increment is the integer value of field in key plus incremental increment

10. Hkeys people / / hkeys key gets all the fields in the hash key

11. Hvals people / / hvals key gets all the values in the hash key

12. Hlen people / / hlen key gets the number of fields in the hash key

13. Hsetnx people age 18 / / hsetnx key field value in the hash key, set the field value when field does not exist

List type:

1. Lpush friend qian yun yin / / lpush key value [value...] Add multiple elements to the list header

2. Lpop friend / / an element to the left of the pop-up list

3. Rpush friend qian yun yin

4. Rpop friend

5. Lpushx friend2 qian / / add elements to the existing list. If it does not exist, it will not be added.

6. Rpushx friend2 yun

7. Llen friend / / View the length of the friend list

8. Lindex friend 1 / / get elements from the friend list based on the index

9. Blpop friend10 / / blpop key [key...] Timeout deletes and gets the first element in the list, or blocks until an element is available

10. Brpop friend 10 / / brpop key [key...] Timeout deletes and gets the last element in the list, or blocks until an element is available

11. Linsert friend BEFORE yun yin / / linsert key BEFORE | AFTER pivot value inserts an element before | after an element

12. Lrange friend 0 1 / / lrange key start stop gets the elements of index 0room1 from the list

13. Lset friend 1 yin / / lset key index value sets elements according to the index

14. Ltrim friend 0 1 / / Let the friend list keep only the elements in the interval

Collection type:

1. Sadd address home school campany

2. Scard address / / get the number of members of address

3. Srem address school campany / / Delete school and campany elements in address

4. Smembers address / / returns all elements in address

5. Spop address / / randomly returns an element

6. Srandmember address 2 / / srandmember key [count] randomly returns one or more elements in the collection

7. Smove address location home / / smove source destination member to move specified elements from one collection to another

8. Sismember address shanghai / / sismember key member to determine whether member is a collection of elements in key

9. Sunion address location / / sunion key [key...] Returns the union of all given sets

10. Sunionstore location address address1 / / sunionstore destination key [key...] Returns the union of all given collections and stores them in destination

11. Sinter address location / / sinter key [key...] Returns the intersection of all given sets

12. Sinterstore location address address1 / / sinterstore destination key [key...] Returns the intersection of all given collections and stores them in destination

13. Sdiff address location / / sdiff key [key...] Returns the difference of all given sets

14. Sdiffstore location address address1 / / sdiffstore destination key [key...] Returns the difference of all given sets and stores them in destination

Ordered collection type:

1. Zadd locations 1 home 2 school / / zadd key [NX | XX] [CH] [INCR] score member [score member...] Add home and school to the ordered collection locations. The smaller the score, the higher the rank.-inf and + inf represent negative infinity and positive infinity, respectively.

2. Zcard locations / / gets the number of members of the ordered collection locations.

3. Zcount locations 030 / / zcount key min max, get the number of members in locations in the specified score range. Min and max are both inclusive.

4. Zincrby locations 2 home / / zincrby key increment member, adding increment to the score of the specified member in the ordered set.

5. Zscore locations home / / zscore key member, get the score of home in locations.

6. Zrange locations 0 2 withscores / / zrange key start stop [WITHSCORES]. Get the element in locations by index, and withscores indicates that the element is output with a score.

7. Zrangebyscore locations 1 2 withscores limit 22 / / zrangebyscore key min max [WITHSCORES] [LIMIT offset count], outputs the elements within the specified score range.

8. Zrem locations home school / / zrem key member [member...], delete the element in locations.

9. Zremrangebyscore locations 1 2 / / zremrangebyscore key min max, delete the elements within the specified score range, and return the number of deleted elements.

10. Zrank locations home / / zrank key member, get the ranking of elements (ranking from small to large, starting with 0).

11. Zrevrank locations home / / zrevrank key member, get the ranking of elements in reverse order (the scores are sorted from highest to lowest).

Thank you for reading this article carefully. I hope the article "what are the Redis commands" shared by the editor will be helpful to you. At the same time, I also hope that you will support us and pay attention to the industry information channel. More related knowledge is waiting for you to learn!

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.

Share To

Database

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report