当前位置:网站首页>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
你好
边栏推荐
- Redis学习笔记—单个键管理
- 2022-06-22:golang选择题,以下golang代码输出什么?A:3;B:1;C:4;D:编译失败。
- Spirit matrix for leetcode topic analysis
- 一个采用直接映射方式的32KB缓存......存储器课后习题
- Le rapport d'analyse de l'industrie chinoise des bases de données a été publié en juin. Le vent intelligent se lève, les colonnes se régénèrent
- MySQL故障案例 | ERROR 1071 (42000): Specified key was too long
- Best time to buy and sell stock
- Geoserver添加mongoDB数据源
- ARM中常见的英文解释
- Jog运动模式
猜你喜欢

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

简易学生管理

点击添加下拉框
Redis学习笔记—慢查询分析

"Coach, I want to play basketball" -- AI Learning Series booklet for students who are making systems

JS mask important data of ID card and mobile phone number with * *
Redis学习笔记—Pipeline
![[learning resources] understand and love mathematics](/img/a3/e1b0915c48c85d17c48a4bee523424.png)
[learning resources] understand and love mathematics

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

297. Serialize and Deserialize Binary Tree
随机推荐
"Coach, I want to play basketball" -- AI Learning Series booklet for students who are making systems
2022.6.22-----leetcode.513
[cloud native | kubernetes] kubernetes principle and installation (II)
力扣之滑动窗口《循序渐进》(209.长度最小的子数组、904. 水果成篮)
Leetcode topic analysis group anagrams
173. Binary Search Tree Iterator
[advanced Android] kotlin notes
位绑定
Basic process of code scanning login
简易学生管理
Use of type dependent names must be prefixed with 'typename'
@Response
438. Find All Anagrams in a String
The sliding window of the force button "step by step" (209. sub array with the smallest length, 904. fruit basket)
297. Serialize and Deserialize Binary Tree
ARM处理器与51单片机程序编写的区别
'教练,我想打篮球!' —— 给做系统的同学们准备的 AI 学习系列小册
三层架构与SSM之间的对应关系
Quartz Crystal Drive Level Calculation
Leetcode topic analysis h-index II