当前位置:网站首页>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
你好
边栏推荐
- An idea of using keep alive to cache data in vue3 form pages
- 6月《中國數據庫行業分析報告》發布!智能風起,列存更生
- Spirit matrix for leetcode topic analysis
- [cloud native | kubernetes] kubernetes principle and installation (II)
- node request模块cookie使用
- Intelligent operation and maintenance exploration | anomaly detection method in cloud system
- Linux MySQL installation
- Redis学习笔记—Redis与Lua
- 36 krypton launched | cloud native database company "tuoshupai" completed a new round of strategic financing, and the valuation has reached the level of quasi Unicorn
- 嵌入式系统概述(学习笔记)
猜你喜欢

297. Serialize and Deserialize Binary Tree

JS mask important data of ID card and mobile phone number with * *

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 数据库入门总结

Flink错误--Caused by: org.apache.calcite.sql.parser.SqlParseException: Encountered “time“

线性表(SequenceList)的顺序表示与实现----线性结构

Custom tag - JSP tag Foundation

'coach, I want to play basketball!'—— AI Learning Series booklet for system students

自定义标签——jsp标签增强

披萨订购设计----简单工厂模式
随机推荐
Community article | mosn building subset optimization ideas sharing
一个采用直接映射方式的32KB缓存......存储器课后习题
173. Binary Search Tree Iterator
65. Valid Number
670. Maximum Swap
6、 Web Architecture Design
“教练,我想打篮球“ —— 给做系统的同学们准备的 AI 学习系列小册
125. Valid Palindrome
986. Interval List Intersections
Mqtt+flink to subscribe and publish real-time messages
Leetcode topic analysis h-index II
986. Interval List Intersections
JSP入门总结
力扣之滑动窗口《循序渐进》(209.长度最小的子数组、904. 水果成篮)
披萨订购设计----简单工厂模式
点击添加下拉框
General paging (1)
JS mask important data of ID card and mobile phone number with * *
[qnx hypervisor 2.2 user manual]6.2 network
Leetcode topic analysis sort colors