当前位置:网站首页>Redis学习笔记—redis-cli详解
Redis学习笔记—redis-cli详解
2022-06-23 09:00:00 【爱锅巴】
输入 redis-cli 连接到命令行客户端(默认host=127.0.0.1,port=6379)
[[email protected] ~]# redis-cli
127.0.0.1:6379>
-h
-h(host:主机)选项代表主机IP,不输入默认为127.0.0.1
[[email protected] ~]# redis-cli -h 127.0.0.1
127.0.0.1:6379>
-p
-p(port:端口)选项代表端口号,不输入默认为6379
[[email protected] ~]# redis-cli -p 6379
127.0.0.1:6379>
-r
-r(repeat:重复)选项表示将命令执行多次,例如执行三次ping操作
[[email protected] ~]# redis-cli -r 3 ping
PONG
PONG
PONG
-i
-i(interval:间隔)选项表示间隔多少秒执行一次命令,但是 -i 必须要和 -r 一起使用,例如每隔1秒执行一次ping命令,总共执行3次
[[email protected] ~]# redis-cli -r 3 -i 1 ping
PONG
PONG
PONG
-x
-x选项表示从标准输入(stdin)读取数据作为redis-cli的最后一个参数,例如下面的操作会将字符串”It’s a dog”作为键Goofy的值(echo的-e表示开启转义,\c表示不换行)
[[email protected] ~]# echo -e "It's a dog\c" | redis-cli -x set Goofy
OK
[[email protected] ~]# redis-cli
127.0.0.1:6379> get Goofy
"It's a dog"
-c
-c(cluster:集群)选项是连接Redis Cluster节点时需要使用的,-c选项可以防止moved和ask异常
-a
-a(authority:权限)如果Redis配置了密码,可以用-a选项,有了这个选项就不需要手动输入auth命令。
–scan和–pattern
–scan选项和–pattern选项用于扫描指定模式的键,相当于使用scan命令
–slave
–slave项是把当前客户端模拟成当前Redis节点的从节点,可以用来获取当前Redis节点的更新操作
第一个客户端开启slave
[[email protected] ~]# redis-cli --slave
SYNC with master, discarding 884 bytes of bulk transfer...
SYNC done. Logging commands from master.
"PING"
"PING"
"PING"
"PING"
第二个客户端做set字符串操作
[[email protected] ~]# redis-cli
127.0.0.1:6379> set hello world
OK
此时第一个客户端
[[email protected] ~]# redis-cli --slave
SYNC with master, discarding 884 bytes of bulk transfer...
SYNC done. Logging commands from master.
"PING"
"PING"
"PING"
"PING"
"SELECT","0"
"set","hello","world"
–rdb
–rdb选项会请求Redis实例生成并发送RDB持久化文件,保存在本地。可使用它做持久化文件的定期备份
–pipe
–pipe选项用于将命令封装成Redis通信协议定义的数据格式,批量发送给Redis执行;例如下面操作同时执行了set hello world和incr counter两条命令
$ 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
–bigkeys
–bigkeys选项使用scan命令对Redis的键进行采样,从中找到内存占用比较大的键值,这些键可能是系统的瓶颈
–eval
–eval选项用于执行指定Lua脚本
–latency
latency有三个选项,分别是–latency、–latency-history、–latency-dist。它们都可以检测网络延迟,对于Redis的开发和运维非常有帮助
–stat
–stat(statistics:统计)选项可以实时获取Redis的重要统计信息,虽然info命令中的统计信息更全,但是能实时看到一些增量的数据(例如requests)对于Redis的运维还是有一定帮助的
[[email protected] ~]# redis-cli --stat
------- data ------ --------------------- load -------------------- - child -
keys mem clients blocked requests connections
27 2.06M 12 0 7696 (+0) 66
27 2.06M 12 0 7697 (+1) 66
27 2.06M 12 0 7698 (+1) 66
.
.
.
–raw和–no-raw
–no-raw选项是要求命令的返回结果必须是原始的格式,–raw恰恰相反,返回格式化后的结果,设置一个键为hello的value为中文“你好”,正常get会返回一个二进制格式的结果,加了–raw就会返回正常的中文字符
[[email protected] ~]# redis-cli set hello "你好"
OK
[[email protected] ~]# redis-cli get hello
"\xe4\xbd\xa0\xe5\xa5\xbd"
[[email protected] ~]# redis-cli --raw get hello
你好
边栏推荐
猜你喜欢

力扣之滑动窗口《循序渐进》(209.长度最小的子数组、904. 水果成篮)

Custom tags - JSP tag enhancements

Jog运动模式

Custom tag - JSP tag Foundation

297. Serialize and Deserialize Binary Tree

一个采用直接映射方式的32KB缓存......存储器课后习题

Simple student management

In depth interpretation of poca smart contract platform gear: the road to parallel architecture public chain

636. Exclusive Time of Functions

986. Interval List Intersections
随机推荐
125. Valid Palindrome
Subsets II of leetcode topic analysis
Fraction to recursing decimal
[event registration] sofastack × CSDN jointly held the open source series meetup, which was launched on June 24
New engine, new capability, new experience, Tencent host security flagship release
Leetcode topic analysis group anagrams
Basic process of code scanning login
如何在 FlowUs、Notion 等笔记软件中使用「番茄工作法」?
GeoServer adding mongodb data source
'coach, I want to play basketball!'—— AI Learning Series booklet for system students
Arthas vmtool命令小结
125. Valid Palindrome
3、 System analysis and design
523. Continuous Subarray Sum
297. Serialize and Deserialize Binary Tree
Servlet-02 生命周期
How to use matrix analysis to build your thinking scaffold in flowus, notation and other note taking software
Typora设置图片上传服务
Assembly (receive several n-digit decimal values (0~65535) from the keyboard and display their sum in different base numbers.)
Restore the default routing settings of the primary network card