基本命令
| directive | function |
|---|---|
| quit /exit | 退出客户端 |
| redis-cli -p xxxx | 从命令行登陆redis |
| redis-cli -h host -p port -a password | 登陆远程redis |
| info | 显示数据库所有信息 |
| select X | 选择某个数据库 |
| keys * | 列出所有键值 |
| exists x | 查看当前数据库是否存在x这个key |
| set key value | 设置key为value,不存在建立一个新的key,存在就覆原value |
| get key | 获得key的value |
| del x | 删除key x |
| expire key seconds | 设置key ttl为seconds |
| ttl key | 获取key的有效时长 |
| pttl key | 获取key的有效时长(毫秒) |
| move key db | 将当前数据库的key移动到db |
| persist key | 移除key的过期时间 |
| randomkey | 随机返回一个库中的key |
| rename oldkey new key | 将oldkey重命名为newkey |
| renamenx oldkey new key | 仅当newkey不存在时将oldkey重命名为newkey |
| type key | 返回key的类型 |
| dbsize | 返回当前数据库所有key的数量 |
| flushdb | 删除当前数据库中的所有key |
| flushall | 删除所有数据库中的数据库 |
高级命令
| directive | function |
|---|---|
| dump key | 序列化key并返回序列化的值 |
| exporeat key unix-timestamp | 设置key ttl为unix-timestamp |
| pexpire key milliseconds | 设置key ttl为milliseconds |
| pexpireat key milliseconds-unix-timestamp | 设置key ttl为milliseconds-unix-timestamp |
| keys pattern | 查找所有符合pattern的key |