Common commands for redis O & M

Source: Internet
Author: User

In normal work, you need to perform operations on the redis database as needed.

Can refer to redis official website http://redis.io/commands for detailed understanding

1. Select to switch Databases

redis 127.0.0.1:6379[1]> HELP SELECT  SELECT index  summary: Change the selected database for the current connection  since: 1.0.0  group: connectionredis 127.0.0.1:6379[1]> SELECT 2OK

2. llen to get the length of a list

redis 127.0.0.1:6379[2]> HELP LLEN  LLEN key  summary: Get the length of a list  since: 1.0.0  group: listredis 127.0.0.1:6379[2]> LLEN bi(integer) 412

3. lrange obtains all elements in a list.

The lrange index starts with 0. 0 indicates the first element, and-1 indicates the last element.

redis 127.0.0.1:6379[2]> HELP LRANGE  LRANGE key start stop  summary: Get a range of elements from a list  since: 1.0.0  group: listredis 127.0.0.1:6379[2]> LRANGE bi 0 5

4. lpush add one or more values to the beginning of a list

 

redis 127.0.0.1:6379[2]> HELP LPUSH  LPUSH key value [value ...]  summary: Prepend one or multiple values to a list  since: 1.0.0  group: listredis 127.0.0.1:6379[2]> LPUSH bi http://abc.com/logUserLogin?event_id=25&uid=de721bcef5cba1fc182d18

5. rpush append one or more values to the end of a list.

redis 127.0.0.1:6379[2]> HELP RPUSH  RPUSH key value [value ...]  summary: Append one or multiple values to a list  since: 1.0.0  group: listredis 127.0.0.1:6379[2]> RPUSH bi http://abc.com/logUserLogin?event_id=25&uid=de721bcef5cba1fc182d18

6. Save to synchronize data to the disk

The connection will be blocked when the Save command is executed, so it is best to use the bgsave command to generate the environment.

redis 127.0.0.1:6379[2]> HELP SAVE  SAVE -  summary: Synchronously save the dataset to disk  since: 1.0.0  group: serverredis 127.0.0.1:6379[2]> SAVEOK(1.33s)

7. bgsave asynchronous data to disk

When bgsave is used, redis will save data in the background, without affecting normal client connections. redis will fork a sub-process for saving data, and the parent process will continue to process client requests.

redis 127.0.0.1:6379[2]> HELP BGSAVE  BGSAVE -  summary: Asynchronously save the dataset to disk  since: 1.0.0  group: serverredis 127.0.0.1:6379[2]> BGSAVEBackground saving started

8. type determines the type of a key.

redis 127.0.0.1:6379[2]> HELP TYPE  TYPE key  summary: Determine the type stored at key  since: 1.0.0  group: genericredis 127.0.0.1:6379[2]> TYPE bilist


This article is from the "Linux SA John" blog, please be sure to keep this source http://john88wang.blog.51cto.com/2165294/1440267

Common commands for redis O & M

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.