redis-cli
是 Redis 提供的命令行客户端工具,用于与 Redis 服务器进行交互。它并不会启动 Redis 服务器,而是用于连接到已启动的 Redis 服务器并执行 Redis 命令(如 SET
, GET
, HSET
, DEL
等)。
redis-cli
一般随 Redis 一起提供的,将redis加入环境变量后,直接Linux 运行redis-cli,Windows运行redis-cli.exe。
执行后,进入 Redis 命令行界面,你会看到类似以下的提示符:
127.0.0.1:6379>
连接到指定的 Redis 主机和端口: 如果 Redis 运行在不同的主机或端口,使用 -h
和 -p
参数:
$ redis-cli -h 192.168.1.100 -p 6380
连接到带密码保护的 Redis: 如果你的 Redis 配置了密码,可以使用 -a
参数传递密码:
$ redis-cli -h 127.0.0.1 -p 6379 -a yourpassword
字符串类型操作(String)
设置键值对:
SET mykey “Hello, Redis!”
获取键的值:
GET mykey
删除键:
DEL mykey