Redis CLI Command _redis

Source: Internet
Author: User
Tags benchmark memory usage redis cli redis server

After the installation of Redis, there are several executable files that begin with Redis under SRC and/usr/local/bin, called Redis Shell, which can do many things.

1, redis-server start Redis
2, redis-cli redis command line tools
3, Redis-benchmark Benchmark tool
4. redis-check-aof aof Persistent file Detection tool and Repair tool
5. Redis-check-dump RDB Persistent file Detection tool and Repair tool
6, Redis-sentinel start Redis-sentinel

Two, you can connect the Redis server using both ways.

The first kind: interactive way

redis-cli-h {host}-p {port} is connected, and all operations are implemented in an interactive manner, and no further redis-cli are required.

$redis-cli-h 127.0.0.1-p 6379

127.0.0.1:6379>set Hello World

OK

127.0.0.1:6379>get Hello

"World"

The second way: Command mode

redis-cli-h {host}-p {port} {command} directly results in the return of the command.

$redis-cli-h 127.0.0.1-p 6379 get Hello

' world '

redis-cli contains many parameters, such as-h,-p, to understand all the parameters, the Redis-cli-help command is available.

The first part of the command mode

1.-R represents a repeat of the command multiple times

$redis-cli-r 3 ping

PONG

PONG

PONG

ping command can be used to detect if the Redis instance is alive and PONG if it survives.

2,-I.

Perform a command every few seconds (0.01 if you want to use MS, such as 10ms), and must be used with-R.

$redis-cli-r 3-i 1 ping

PONG

PONG

PONG
$redis-cli-r 10-i 1 info|grep used_memory_human

used_memory_human:2.95g

.....................................

used_memory_human:2.95g

every 1 seconds output memory usage, total output 10 times.



$redis-cli-h ip-p Port info server|grep process_id

process_id:999

Get Redis process number 999

3,-X

Represents reading data from standard input as the last parameter of the command.

$echo "World" |redis-cli-x set Hello

Ok

4,-C

used when connecting to cluster nodes, this option prevents moved and ask exceptions.

5, a

If you have a password configured, you can use the A option.

6, –scan and –pattern

The key used to scan the specified mode, equivalent to the scan command.

7, –slave

The current client is used to get the update operation of the current Redis node when it simulates the Redis node of the current node. Make reasonable use of some of the update operations that can be used to record the current connection Redis node, which may be the data needed to actually develop the business.

8, –rdb

The Redis instance is requested to generate and send the Rdb persisted file, which is saved locally. Can do regular backups.

9, –pipe

The command is encapsulated into the data format defined by the Redis communication protocol and is sent to Redis for execution in bulk.

10, –bigkeys

Statistics the distribution of Bigkey, using the Scan command to sample the keys of the Redis, to find the memory footprint of a relatively large key, these keys may be the bottleneck of the system.

11, –eval

Used to execute LUA scripts

12, –latency

There are three options, –latency, –latency-history, –latency-dist. They can detect network latency and exhibit different forms.

13, –stat

The important statistic information of Redis can be obtained in real time. The info command is relatively complete, but here you can see some additional data, such as requests (requests per second)

14, –raw and –no-raw

–no-raw requires that the original format be returned. –raw shows the formatting effect.

Part II
There are many redis-cli orders. Like what

Connection Operations Related commands

1, the default direct connection  remote connection-H 192.168.1.20-p 6379

2, Ping: Test the connection is alive if normal will return Pong

3, Echo: Print

4, select: Switch to the specified database, The database index number is specified with a numeric value of 0 as the starting index value

5, quit: Close the connection (connection)

6, auth: simple password Authentication

Service-Side related commands

1, Time: Back to the current server times

2, client list: Return all clients connected to the server information and statistics  see

3, Http://redisdoc.com/server/client_ List.html

4, client kill Ip:port: Close the address of Ip:port clients

5, Save: Synchronize data to disk

6, Bgsave: Asynchronously save data to disk

7, Lastsave: Returns the UNIX timestamp 8 that successfully saved data to disk last time,

shundown: Synchronize data to disk, then turn off service

9, Info: Provide server information and statistics

10, config Resetstat: Reset some statistics in the info command

11, config get: Obtain profile information

12, config set: Dynamically adjust the configuration of the Redis server (configuration) without rebooting, Configuration parameters can be modified by using command 

13, config get * to list

14, config Rewrite:redis server specified redis.conf file to overwrite

15, Monitor: Real-time dump received requests   

16, slaveof: Changing Replication policy settings

Publish subscription related commands

1. Psubscribe: Subscribe to one or more channels that conform to a given mode such as Psubscribe news.* tweet.*

2, publish: Send information message to a specified channel channel such as Publish Msg " Good Morning "

3, PubSub channels: List current active channels such as PubSub channels news.i*

4, PubSub numsub: Number of subscribers returning a given channel for example PubSub Numsub news.it news.internet news.sport 
news.music

5, PubSub Numpat: Returns the total number of all modes that the client subscribes to

6, Punsubscribe: Instructs the client to unsubscribe from all given modes.

7, Subscribe: Subscribe to the given one or more channels of information. For example Subscribe msg chat_room

8, Unsubscribe: Instructs the client to unsubscribe from a given channel.

Commands for key operations

1, exists (key): To confirm that a key exists

2, Del (key): Delete a key

3, type (key): Return the value of type

4, keys (pattern) : Returns all key

5, Randomkey: A random return key space of

6, Keyrename (Oldname, newname) that satisfies the given pattern: rename key

7, Dbsize: Returns the number of keys in the current database

8, expire: Set a key activity time (s)

9, TTL: To get a key activity time

10, Move (key, Dbindex) : Move key in current database to Dbindex database

11, FLUSHDB: Delete all key 12, Flushall in the current selection database

: Delete all keys in all databases

Commands for string operations

1. Set (key, value): Give value 2, get (key) to a string with the name key in the database

: Return values

3, Getset (key, value) of string that has the name key in the database : Give the last value

4, Mget (Key1, Key2,..., key N) to string named key: Returns value

5, SETNX (key, value) for multiple strings in the library: add string, Name is key, value

6, Setex (key, Time, value): Add string to library, set expiration time

7, Mset (key n, value N): Batch set multiple string values

8 , Msetnx (key n, value N): If all strings named key I do not exist

9, INCR (key): string with Name key + 1 operations

10, Incrby (Key, Integer) : string with the name key increases integer

11, DECR (key): string minus 1 with name key is

12, Decrby (Key, Integer): string with Name key reduces integer

13, append (key, value): String with Name key appended value

14, substr (key, start, end): A substring that returns the value of string with the name key

Commands for the list operation

1, Rpush (key, value): Add a value of element

2, Lpush (key, value) at the end of the list named key: Add an Element

3, Llen (value) to the list header named key ( Key): Returns the length of List

4, Lrange (key, start, end) with the name key: Returns the element

5, LTrim (key, start, end) between start and end in the list named key : Intercept name Key list

6, lindex (key, index): Returns the element

7, LSet (key, index, value) of the index position in the list named key : Assign a value of 8, Lrem (key, count, value) to the element of index in the list with name Key

: Delete element

9, Lpop (key) with value in List of Count key : Returns and deletes the first element in the list named key

10, Rpop (key): Returns and Deletes the tail element

11, Blpop (Key1, Key2,... key N, timeout) in the list named key : The block version of the Lpop command.

12, Brpop (Key1, Key2,... key N, timeout): Rpop version of the block.

13, Rpoplpush (Srckey, Dstkey): Returns and Deletes the tail element of the list named Srckey, and adds the element to the head of the list named Dstkey

Commands for set operations

1, Sadd (key, member): add Element member

2, Srem (key, member) to set with name key: Delete Element member

3, Spop (key) in set with Name key : Random return and delete one element of the set with Name Key

4, Smove (Srckey, Dstkey, member): Move to collection element

5, SCard (key): Returns the base 6 of the set with the name Key

, Sismember (Key, member): whether member is the element of set with name Key

7, sinter (Key1, Key2,... key N): Intersection

8, Sinterstore (Dstkey, keys) : Find the intersection and save the intersection to the Dstkey collection

9, Sunion (Key1, (keys)): Gather and set

10, Sunionstore (Dstkey, (keys)): Gather and save the set to the collection

of Dstkey 11, Sdiff (Key1, (keys)): The difference set

12, Sdiffstore (Dstkey, (keys)): The difference set and save the difference set to the Dstkey set

13, Smembers (key) : Returns all elements

14, Srandmember (key) of set with Name key: Random return of an element of set with name key

Commands for hash operations

1, Hset (Key, field, value): add Element field

2, Hget (Key, field) to the hash named key: Returns value 3, Hmget for the field corresponding to the hash in the name Key

( Key, (Fields)): Returns the value

4, Hmset (Key, (fields)) of the field I in the hash named key: add Element field

5, Hincrby (key) to the hash named key, field, integer): Adds the value of field in the hash named key to integer

6, Hexists (Key, field): Field 7 with key field in the hash named key,

Hdel (Key, field): Delete field 8, Hlen (key) with key in hash with name Key

: Returns the number of elements in the hash named key

9, Hkeys (key): Returns all keys

in a hash named key 10. Hvals (Key): Returns the value 11, Hgetall (key) corresponding to all keys in the hash named key

: Returns all keys (field) and their corresponding value in the hash named key

Instance
Query Online Analysis
REDIS-CLI MONITOR | Head-n 5000 |./redis-faina.py
Monitoring commands being requested to execute
Monitor is executed under CLI and the production environment is carefully used.

Analog Oom
REDIS-CLI Debug Oom

Analog downtime
REDIS-CLI Debug Segfault

Analog Hang
Redis-cli-p 6379 DEBUG Sleep 30

Get slow Query

Slowlog Get 10
The result is the query ID, the occurrence time, the run-time length, and the default 10 milliseconds for the original command, leaving only the last 128. Single-threaded model, a request takes up 10 milliseconds is a big deal, note that the set and display units in microseconds, note that this time is not including network latency.
Slowlog get fetch slow query log
Slowlog len get slow query log bar count
Slowlog Reset Empty Slow query

Configuration:

Config set Slow-log-slower-than 20000

Config set Slow-max-len 1000

Config rewrite

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.