当前位置:网站首页>A complete tutorial for getting started with redis: redis shell
A complete tutorial for getting started with redis: redis shell
2022-07-04 22:53:00 【Gu Ge academic】
Redis Provides redis-cli、redis-server、redis-benchmark etc. Shell Tools . they
Although it's relatively simple , But although the sparrow is small, it has all five internal organs , Sometimes you can solve some problems skillfully .
3.2.1 redis-cli Detailed explanation
The first 1 Zhang Zeng introduced redis-cli, Include -h、-p Parameters , But in addition to these parameters , And there's a lot more
What useful parameters , To understand redis-cli All the parameters of , It can be executed redis-cli-help Orders come in
Row view , The following will explain the meaning of some important parameters and the usage scenarios .
1.-r
-r(repeat) Option represents executing the command multiple times , For example, the following operations will be performed three times ping
command :
redis-cli -r 3 ping
PONG
PONG
PONG
2.-i
-i(interval) Option represents executing commands every few seconds , however -i The options must be with -r choose
Use with , The following operations will be performed every 1 Once per second ping command , A total of execution 5 Time :
$ redis-cli -r 5 -i 1 ping
PONG
PONG
PONG
PONG
PONG
Be careful -i In seconds , Milliseconds are not supported , But if you want to do it every 10 Execution in milliseconds
once , It can be used -i0.01, for example :
$ redis-cli -r 5 -i 0.01 ping
PONG
PONG
PONG
PONG
PONG
For example, the following operations utilize -r and -i Options , every other 1 Second output memory usage , Total output
100 Time :
redis-cli -r 100 -i 1 info | grep used_memory_human
used_memory_human:2.95G
used_memory_human:2.95G
......................
used_memory_human:2.94G
3.-x
-x The options represent input from the standard (stdin) Read data as redis-cli The last reference of
Count , For example, the following operation will string world As set hello Value :
$ echo "world" | redis-cli -x set hello
OK
4.-c
-c(cluster) The option is to connect Redis Cluster Nodes are used for ,-c Option can prevent
stop moved and ask abnormal , of Redis Cluster In the fourth 10 Chapter introduction .
5.-a
If Redis Configured password , It can be used -a(auth) Options , With this option, you don't need
Manual input auth command .
6.--scan and --pattern
--scan Options and --pattern Option is used to scan keys for the specified mode , It is equivalent to using scan life
Make .
7.--slave
--slave The option is to simulate the current client as the current Redis The slave node of the node , Can be used to
Get current Redis Node update operation , About Redis The copy will be made on 6 Chapter gives a detailed introduction
Shao . Reasonable use of this option can record the current connection Redis Some update operations of nodes , this
Some update operations are likely to be the data needed for the actual development of the business .
Now open the first client , Use --slave Options , See that synchronization is complete :
$ redis-cli --slave
SYNC with master, discarding 72 bytes of bulk transfer...
SYNC done. Logging commands from master.
Then open another client to do some update operations :
redis-cli
127.0.0.1:6379> set hello world
OK
127.0.0.1:6379> set a b
OK
127.0.0.1:6379> incr count
1
127.0.0.1:6379> get hello
"world"
The first client will receive Redis Node update operation :
redis-cli --slave
SYNC with master, discarding 72 bytes of bulk transfer...
SYNC done. Logging commands from master.
"PING"
"PING"
"PING"
"PING"
"PING"
"SELECT","0"
"set","hello","world"
"set","a","b"
"PING"
"incr","count"
Be careful
PING The command is generated by master-slave replication , The first 6 This chapter will introduce master-slave replication .
8.--rdb
--rdb The option requests Redis Instance generation and sending RDB Persistent files , Keep it locally .
It can be used for regular backup of persistent files . of Redis Persistence will occur in the 5 Chapter gives a detailed introduction
Shao .
9.--pipe
--pipe Option to encapsulate the command as Redis Data format defined by communication protocol , Bulk delivery
to Redis perform , of Redis The communication protocol will be in 4 Chapter gives a detailed introduction , For example, the following operation
At the same time set hello world and incr counter Two orders :
echo -en '*3\r\n$3\r\nSET\r\n$5\r\nhello\r\n$5\r\nworld\r\n*2\r\n$4\r\nincr\r\
n$7\r\ncounter\r\n' | redis-cli --pipe
10.--bigkeys
--bigkeys Option to use scan Command to Redis The key to sample , Find the memory usage ratio
Larger key values , These keys can be the bottleneck of the system .
11.--eval
--eval Option is used to perform the specified Lua Script , of Lua The use of scripts will be in 3.4 Section introduction .
12.--latency
latency There are three options , Namely --latency、--latency-history、--latency-dist.
They all detect network latency , about Redis It's very helpful to develop and maintain .
(1)--latency
This option can test client to target Redis Network delay for , For example, the current topology, such as
chart 3-4 Shown . client B and Redis In the computer room B, client A In the computer room A, Computer room A And the computer room B yes
Trans regional .
client B:
redis-cli -h {machineB} --latency
min: 0, max: 1, avg: 0.07 (4211 samples)
client A:
redis-cli -h {machineB} --latency
min: 0, max: 2, avg: 1.04 (2096 samples)
You can see the client A Because of the distance Redis Far away , The average network latency will be slightly higher .
(2)--latency-history
--latency There is only one result , If you want to know the delay information in the form of time division ,
have access to --latency-history Options :
redis-cli -h 10.10.xx.xx --latency-history
min: 0, max: 1, avg: 0.28 (1330 samples) -- 15.01 seconds range …
min: 0, max: 1, avg: 0.05 (1364 samples) -- 15.01 seconds range
You can see the delay information every 15 Output once per second , Can pass -i Parameter control interval time .
(3)--latency-dist
This option outputs delay statistics from the console in the form of a statistical chart .
13.--stat
--stat Options are available in real time Redis Important statistics , although info The statistical letter in the command
The rest is more complete , But you can see some incremental data in real time ( for example requests) about Redis Operation and maintenance of
There is still some help , As shown below :
redis-cli --stat
------- data ------ --------------------- load -------------------- - child -
keys mem clients blocked requests connections
2451959 3.43G 1162 0 7426132839 (+0) 1337356
2451958 3.42G 1162 0 7426133645 (+806) 1337356 …
2452182 3.43G 1161 0 7426150275 (+1303) 1337356
14.--raw and --no-raw
--no-raw The option requires that the return result of the command must be in the original format ,--raw Just like
back , Returns the formatted result .
stay Redis Set a Chinese value:
$redis-cli set hello " Hello "
OK
If it works get Or use --no-raw Options , Then the returned result is binary lattice
type :
$redis-cli get hello
"\xe4\xbd\xa0\xe5\xa5\xbd"
$redis-cli --no-raw get hello
"\xe4\xbd\xa0\xe5\xa5\xbd"
If used --raw Options , Will return to Chinese :
$redis-cli --raw get hello Hello
3.2.2 redis-server Detailed explanation
redis-server In addition to starting Redis Outside , One more --test-memory Options .redis-server-
-test-memory Can be used to detect whether the current operating system can stably allocate the specified amount of memory to
Redis, Through this kind of detection can effectively avoid the memory problems caused by Redis collapse , For example, the following
Operation check whether the current operating system can provide 1G The memory for Redis:
redis-server --test-memory 1024
The whole memory detection takes a long time . When the output passed this test It means that the memory detection is completed
BI , At the end of the day --test-memory It's just a simple test , If there is doubt, you can use more professional
Memory detection tool based on :
Please keep the test running several minutes per GB of memory.
Also check http:// www.memtest86.com/ and http:// pyropus.ca/software/memtester/
................ Ignore detection details ................
Your memory passed this test.
Please if you are still in doubt use the following two tools:
1) memtest86: http:// www.memtest86.com/
2) memtester: http:// pyropus.ca/software/memtester/
Usually it doesn't have to be turned on every time Redis Instance --test-memory Options , This function is more inclined to
For debugging and testing , for example , Want to quickly fill up the memory of the machine to do some extreme condition tests , This achievement
Can be a good choice .
3.2.3 redis-benchmark Detailed explanation
redis-benchmark It can be for Redis Do benchmark performance testing , It provides many options to help open
Send and O & M personnel to test Redis Related performance of , Here are the options .
1.-c
-c(clients) Option represents the number of concurrent clients ( The default is 50).
2.-n<requests>
-n(num) Option represents the total number of client requests ( The default is 100000).
for example redis-benchmark-c100-n20000 representative 100 Each client requests Redis, One
In total 20000 Time .redis-benchmark Will test all kinds of data structure commands , And give
Performance index :
====== GET ======
20000 requests completed in 0.27 seconds
100 parallel clients
3 bytes payload
keep alive: 1
99.11% <= 1 milliseconds
100.00% <= 1 milliseconds
73529.41 requests per second
For example, all of the above are implemented 20000 Time get operation , stay 0.27 Seconds to complete , Amount of data per request
yes 3 Bytes ,99.11% The command execution time of is less than 1 millisecond ,Redis It can be processed per second
73529.41 Time get request .
3.-q
-q The options just show redis-benchmark Of requests per second Information , for example :
$redis-benchmark -c 100 -n 20000 -q
PING_INLINE: 74349.45 requests per second
PING_BULK: 68728.52 requests per second
SET: 71174.38 requests per second …
LRANGE_500 (first 450 elements): 11299.44 requests per second
LRANGE_600 (first 600 elements): 9319.67 requests per second
MSET (10 keys): 70671.38 requests per second
4.-r
In an empty Redis On the implementation of redis-benchmark Will find only 3 Key :
127.0.0.1:6379> dbsize
(integer) 3
127.0.0.1:6379> keys *
1) "counter:__rand_int__"
2) "mylist"
3) "key:__rand_int__"
If you want to Redis Insert more keys , Can be executed using -r(random) Options , Can be directed to
Redis Insert more random keys .
$redis-benchmark -c 100 -n 20000 -r 10000
-r The options will be in key、counter Add one to the key 12 Suffix of position ,-r10000 Represents only the last four
Bits are processed randomly (-r It's not a random number ). For example, after the above operation ,key Quantity and settlement of
The fruit structure is as follows :
127.0.0.1:6379> dbsize
(integer) 18641
127.0.0.1:6379> scan 0
1) "14336"
2) 1) "key:000000004580"
2) "key:000000004519"
…
10) "key:000000002113"
5.-P
-P Options represent each request pipeline The amount of data ( The default is 1).
6.-k<boolean>
-k Option represents whether the client uses keepalive,1 For the use of ,0 For not using , The default value is
1.
7.-t
-t Option to benchmark the specified command .
redis-benchmark -t get,set -q
SET: 98619.32 requests per second
GET: 97560.98 requests per second
8.--csv
--csv Option will follow the result as csv Format output , It is convenient for subsequent processing , Export to Excel
etc. .
redis-benchmark -t get,set --csv
"SET","81300.81"
"GET","79051.38"
边栏推荐
- 共创软硬件协同生态:Graphcore IPU与百度飞桨的“联合提交”亮相MLPerf
- 攻防世界 MISC 进阶区 3-11
- Redis: redis configuration file related configuration and redis persistence
- 繁華落盡、物是人非:個人站長該何去何從
- 企业如何跨越数字化鸿沟?尽在云原生2.0
- Solana chain application crema was shut down due to hacker attacks
- 集群的概述与定义,一看就会
- Redis入门完整教程:GEO
- Redis入门完整教程:有序集合详解
- Wake up day, how do I step by step towards the road of software testing
猜你喜欢
Analysis of the self increasing and self decreasing of C language function parameters
业务太忙,真的是没时间搞自动化理由吗?
Duplicate ADMAS part name
10 schemes to ensure interface data security
Tla+ introductory tutorial (1): introduction to formal methods
Redis入门完整教程:事务与Lua
Logo Camp d'entraînement section 3 techniques créatives initiales
Introducing QA into the software development lifecycle is the best practice that engineers should follow
Redis的持久化机制
攻防世界 MISC 進階區 Erik-Baleog-and-Olaf
随机推荐
Sobel filter
攻防世界 MISC 进阶区 Ditf
Attack and defense world misc advanced grace-50
Create Ca and issue certificate through go language
环境加密技术解析
MySQL Architecture - logical architecture
Google Earth Engine(GEE)——基于 MCD64A1 的 GlobFire 日常火灾数据集
Attack and defense world misc advanced area can_ has_ stdio?
How diff are the contents of the same configuration item in different environments?
关于栈区、堆区、全局区、文字常量区、程序代码区
Detailed explanation of flask context
Test will: bug classification and promotion solution
Google Earth engine (GEE) - tasks upgrade enables run all to download all images in task types with one click
Three stage operations in the attack and defense drill of the blue team
In Linux, I call odspcmd to query the database information. How to output silently is to only output values. Don't do this
Duplicate ADMAS part name
繁华落尽、物是人非:个人站长该何去何从
攻防世界 MISC 进阶区 3-11
Erik baleog and Olaf, advanced area of misc in the attack and defense world
Mongodb aggregation operation summary