当前位置: 首页 > news >正文

redis-7.4.4使用

redis-7.4.4 使用

1.redis数据库-info 的使用

redis-cli -h 地址 -p 端口 -a 密码

推荐如下方式登录

redis-cli --askpass
Please input password: *********
127.0.0.1:6379> ping
PONG

[root@zabbix71 bin]# redis-cli -a Root_123!
Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
127.0.0.1:6379> info Server
# Server
redis_version:7.4.4
redis_git_sha1:00000000
redis_git_dirty:1
redis_build_id:54d55e8918e5ab68
redis_mode:standalone
os:Linux 4.19.90-89.11.v2401.ky10.x86_64 x86_64
arch_bits:64
monotonic_clock:POSIX clock_gettime
multiplexing_api:epoll
atomicvar_api:c11-builtin
gcc_version:7.3.0
process_id:197423
process_supervised:no
run_id:daad50e6795d89374e90e3e7d770664118982627
tcp_port:6379
server_time_usec:1749782438068836
uptime_in_seconds:62845
uptime_in_days:0
hz:10
configured_hz:10
lru_clock:4951974
executable:/usr/local/bin/redis-server
config_file:/etc/redis/redis.conf
io_threads_active:0
listener0:name=tcp,bind=127.0.0.1,bind=-::1,port=6379
  • info Server: 关于 Redis 服务器的基本信息,包括版本号、运行时长、操作系统等
  • info Clients: 客户端连接的相关统计信息,比如已连接客户端的数量
  • info Memory: 内存使用情况,包括 Redis 使用了多少内存、峰值内存使用量等
  • info Persistence: RDB 和 AOF 持久化相关的状态和统计信息
  • info Stats: 通用统计信息,例如处理了多少命令、网络流量等
  • info Replication: 主从复制的状态信息
  • info CPU: CPU 使用情况,包括用户态和内核态的时间消耗
  • info Keyspace: 数据库中键值对的统计信息,包括键的数量、过期键的数量等

可以接多个

127.0.0.1:6379> info keyspace cpu  Cluster
# CPU
used_cpu_sys:22.954634
used_cpu_user:128.059632
used_cpu_sys_children:0.003687
used_cpu_user_children:0.000000
used_cpu_sys_main_thread:22.953574
used_cpu_user_main_thread:128.059577# Cluster
cluster_enabled:0# Keyspace
db0:keys=1,expires=0,avg_ttl=0,subexpiry=0

2.常用

# 1. 创建key
127.0.0.1:6379> set name 2222
OK# 2.获取key
127.0.0.1:6379> get name
"2222"# 3.查看key的数量
127.0.0.1:6379> dbsize
(integer) 1# 4.查看是否存在
127.0.0.1:6379> exists name1
(integer) 0
127.0.0.1:6379> exists name
(integer) 1# 5.设置有效期
127.0.0.1:6379> set name1 333 ex 30
OK# 6.查看有效期
127.0.0.1:6379> ttl name1
(integer) 19# 7.设置key 的过期时间,单位:s
127.0.0.1:6379> expire name2 30
(integer) 1
127.0.0.1:6379> ttl name2
(integer) 26
127.0.0.1:6379> ttl name2
(integer) -2
127.0.0.1:6379> get name2
(nil)# 8.删除key
127.0.0.1:6379> get name3
"111"
127.0.0.1:6379> del name3
(integer) 1
127.0.0.1:6379> get name3
(nil)# 9.INCR: 将键对应的整数值增加1。
127.0.0.1:6379> set name2 23
OK
127.0.0.1:6379> get name2
"23"
127.0.0.1:6379> incr name2
(integer) 24# 10.INCRBY: 将键对应的整数值增加指定的整数
127.0.0.1:6379> incrby name2 100
(integer) 124# 11.DECR: 将键对应的整数值减少1
127.0.0.1:6379> decr name2
(integer) 123# 12.DECRBY: 将键对应的整数值减少指定的整数。
127.0.0.1:6379> decrby name2 10
(integer) 113
127.0.0.1:6379> get name2
"113"# 13.查看key的数量
127.0.0.1:6379> dbsize
3# 14.查看key 的类型
127.0.0.1:6379> type name5
string

非交互式的获取值(有告警,密码显示,不推荐)

[root@zabbix71 bin]# redis-cli -a Root_123! get name2
Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
"113"

3. 脚本

vi get_info.sh#!/bin/bash
redis-cli <<EOF
AUTH Root_123!
GET name2
info cpu
EOFchmod +x get_info.sh
./get_info.sh./get_info.sh
OK
"113"
# CPU
used_cpu_sys:26.437929
used_cpu_user:145.338280
used_cpu_sys_children:0.009529
used_cpu_user_children:0.001899
used_cpu_sys_main_thread:26.436822
used_cpu_user_main_thread:145.337989

4.获取key的中文值

#普通模式下
[root@zabbix71 ~]# redis-cli --askpass
Please input password: *********
127.0.0.1:6379> ping
PONG127.0.0.1:6379> set name5 张三▒
OK
127.0.0.1:6379> get name5
"\xe5\xbc\xa0\xe4\xb8\x89\xe6\x98"
127.0.0.1:6379> get name5 --raw
(error) ERR wrong number of arguments for 'get' command# 显示中文
[root@zabbix71 ~]# redis-cli --raw --askpass
Please input password: *********
127.0.0.1:6379> get name5
张三▒
127.0.0.1:6379> set name5 脚本解码
OK
127.0.0.1:6379> get name5
脚本解码

更多使用规则: 菜鸟教程

http://www.xdnf.cn/news/1021681.html

相关文章:

  • 详解deeplabv3+改进思路
  • conda pack迁出环境异常
  • AKS升级路线最佳实践方案
  • dockercompose部署应用
  • 实战案例-JESD204B 多器件同步
  • 协同开发中的移动端网页调试流程:一次团队实战的经验总结(含WebDebugX)
  • Unity 接入抖音小游戏一
  • linux 黑马 第1-2章
  • ELK日志采集系统
  • 通过iframe使用Jupyter notebook
  • shell、bash、cmd、git 和 PowerShell 的区别与关系的详细解析
  • 吃透 Golang 基础:函数
  • 混合云战略规划深度解析:多云管理的技术架构与治理框架
  • 动态规划: 背包DP大合集
  • 【android bluetooth 框架分析 04】【bt-framework 层详解 7】【AdapterProperties介绍】
  • 触觉智能RK3576核心板,工业应用之4K超高清HDMI IN视频输入
  • 基于Python的二手房源信息爬取与分析的设计和实现,7000字论文编写
  • 改写爬虫, unsplash 图片爬虫 (网站改动了,重写爬虫)
  • 给element-plus的table表格加上连续序号
  • Kubernetes 从入门到精通-资源限制
  • 清理电脑C磁盘,方法N:使用【360软件】中的【清理C盘空间】
  • Visual Studio Code 1.101.0 官方版
  • 晶晨S905L/S905L-B芯片-安卓7.1.2_【通刷】线刷固件包及教程
  • 解析Android SETUP_DATA_CALL 链路信息字段
  • MultiTalk 是一种音频驱动的多人对话视频生成模型
  • Java 实现 Excel 转化为图片
  • 亚远景-如何高效实施ASPICE认证标准:汽车软件企业的实践指南
  • nvue全攻略:从入门到性能优化
  • 如何使用 Python 对Bing搜索进行抓取
  • DSPC6678使用CCS开发的任务/中断分析功能(RTOS Analyzer)