在linux中 批量操作redis中的 keys的方法:
统计个数:
redis中名称含有OMP_OFFLINE的key的个数;
src/redis-cli keys "*OMP_OFFLINE*"|wc -l
批量删除
批量删除 0号数据库中名称含有OMP_OFFLINE的key:
src/redis-cli -n 0 keys "*OMP_OFFLINE*"|xargs src/redis-cli -n 0 del
在redis的客户端环境中并不支持批量删除。
过期时间设置
统计个数:
redis中名称含有OMP_OFFLINE的key的个数;
src/redis-cli keys "*OMP_OFFLINE*"|wc -l
批量删除
批量删除 0号数据库中名称含有OMP_OFFLINE的key:
src/redis-cli -n 0 keys "*OMP_OFFLINE*"|xargs src/redis-cli -n 0 del
在redis的客户端环境中并不支持批量删除。
可以把某个keys的结果全部输出到文件中,比如keys.log
redis-cli -p port -c command > keys.log
Redis常用命令
Key-values
1 keys * 匹配键所有的键. 模糊匹配 keys my* 取出所有已my开头的键
2 exists 判断是否键 exists name判断是否有name这个键是否存在
3 del 删除键 del name 删除name的键
4 expire 设置过期时间 expire key time
5 ttl key 查看键的过期时间
6 select database 选择数据库
7 move key dababase1 讲key移动dao database1中的数据库中
8 persist 取消键的过期时间
9 randomkey 随机返回一个键的值
10 rename 重命名一个键
11 type key 判断key的数据类型
Server
1 ping ping我们的主机能否链接 链接是否存活
2 echo 命令 echo demo直接输出
3 select 选择数据库 select 0-16个数据库
4 quit exit 退出链接
5 dbsize 返回数据库的键的个数
6 info 返回服务器相关信息
7 config get 返回服务配置信息
8 flush db 清空数据库
9 flushall 删除所有数据库中所有的键
Key-values
1 keys * 匹配键所有的键. 模糊匹配 keys my* 取出所有已my开头的键
2 exists 判断是否键 exists name判断是否有name这个键是否存在
3 del 删除键 del name 删除name的键
4 expire 设置过期时间 expire key time
5 ttl key 查看键的过期时间
6 select database 选择数据库
7 move key dababase1 讲key移动dao database1中的数据库中
8 persist 取消键的过期时间
9 randomkey 随机返回一个键的值
10 rename 重命名一个键
11 type key 判断key的数据类型
Server
1 ping ping我们的主机能否链接 链接是否存活
2 echo 命令 echo demo直接输出
3 select 选择数据库 select 0-16个数据库
4 quit exit 退出链接
5 dbsize 返回数据库的键的个数
6 info 返回服务器相关信息
7 config get 返回服务配置信息
8 flush db 清空数据库
9 flushall 删除所有数据库中所有的键
redis> SET cache_page "www.google.com" OK redis> EXPIRE cache_page 30 # 设置过期时间为 30 秒 (integer) 1 redis> TTL cache_page # 查看剩余生存时间 (integer) 23 redis> EXPIRE cache_page 30000 # 更新过期时间 (integer) 1 redis> TTL cache_page (integer) 29996