Skip to content
章节导航

Redis 常用命令

启动客户端

shell
./redis-cli -h 192.168.3.4 -p 6379 -a root

-h: host 的意思, redis 启动地址的 ip
-p: 端口, 默认是 6379
-a: 设置的密码

如果是本机启动, 端口不变, 则可以省略 -h -p, 直接运行 ./redis-cli -a root, 没有密码直接执行 ./redis-cli

退出

shell
quit

String 类型基本操作

插入数据, 插入的大数据, 默认在 0 号库

shell
语法: set key value

例如: set username itdachen

查看数据

shell
语法: get key

例如: get username

切换 Redis 库

shell
语法: select index

例如: select 2

层级存储: 层级存储, 针对 key 做层级, 简单点讲, 就像文件夹, 一个套一个, 中间用冒号连接

shell
语法: set xxx:ccc:vvv

例如: set com:itdachen:username itdachen

获取数据: get com:itdachen:username

查看当前库有多少 key

shell
keys *

关于 info

查看 cpu

shell
info CPU

查看主从

shell
info repilication

查看集群

shell
info cluster

查看详细 info 信息

shell
info

清除 key

shell
FLUSHALL

该命令清除全部 key, 包括其他库