redis中获取没有设置ttl过期时间的key
需求:redis作为一个内存型的数据库,我们需要对过期key保持关注,从info keyspace中可以看出有多少key没有设置过期时间,那么到底是哪些呢?
说明:关于redis ttl 的返回值,请参考http://redisdoc.com/key/ttl.html
测试数据:
5.5.5.101:6379> get c_100
"100"
5.5.5.101:6379> ttl c_100
(integer) -1
5.5.5.101:6379> expire c_100 600
(integer) 1
5.5.5.101:6379> expire c_1000 600
(integer) 1
5.5.5.101:6379> expire c_888 600
(integer) 1
5.5.5.101:6379> dbsize
(integer) 10000
5.5.5.101:6379> info keyspace
# Keyspace
db0:keys=10000,expires=3,avg_ttl=583699
获取没有设置ttl过期的key名字
db_ip=5.5.5.101
db_port=6379
password=abc123
cursor=0
cnt=100
new_cursor=0 redis-cli -h $db_ip -p $db_port -a $password scan $cursor count $cnt > scan_tmp_result
new_cursor=`sed -n '1p' scan_tmp_result`
sed -n '2,$p' scan_tmp_result > scan_result
cat scan_result |while read line
do
ttl_result=`redis-cli -h $db_ip -p $db_port -a $password ttl $line`
if [[ $ttl_result == -1 ]];then
echo $line >> no_ttl.log
fi
done while [ $cursor -ne $new_cursor ]
do
redis-cli -h $db_ip -p $db_port -a $password scan $new_cursor count $cnt > scan_tmp_result
new_cursor=`sed -n '1p' scan_tmp_result`
sed -n '2,$p' scan_tmp_result > scan_result
cat scan_result |while read line
do
ttl_result=`redis-cli -h $db_ip -p $db_port -a $password ttl $line`
if [[ $ttl_result == -1 ]];then
echo $line >> no_ttl.log
fi
done
done
rm -rf scan_tmp_result
rm -rf scan_result
查看结果:
[redis@lxd-vm1 ~]$ wc -l no_ttl.log
9997 no_ttl.log
[redis@lxd-vm1 ~]$
redis中获取没有设置ttl过期时间的key的更多相关文章
- 在Redis中设置了过期时间的Key,需要注意哪些问题?
熟悉Redis的同学应该知道,Redis的每个Key都可以设置一个过期时间,当达到过期时间的时候,这个key就会被自动删除. 在为key设置过期时间需要注意的事项 1. DEL/SET/GETSET等 ...
- php中实现精确设置session过期时间的方法
http://www.jb51.net/article/52309.htm 大多数据情况下我们对于session过期时间使用的是默认设置的时间,而对于一些有特殊要求的情况下我们可以设置一下sessio ...
- 转:php中实现精确设置session过期时间的方法
原文来自于:http://www.jb51.net/article/52309.htm 大多数据情况下我们对于session过期时间使用的是默认设置的时间,而对于一些有特殊要求的情况下我们可以设置一下 ...
- 查询redis中没有设置过期时间的key
#!/bin/sh ## 该脚本用来查询redis集群中,哪些key是没有设置过期时间,对应只需要修改redis的其中一个实例的 host和port ## 脚本会自动识别出该集群的所有实例,并查出对应 ...
- spring boot整合redis,以及设置缓存过期时间
spring-boot 整合 redis 注:redis服务器要先开启 pom文件: <dependency> <groupId>org.springframework.boo ...
- C# asp.net IIS 在web.config和IIS中设置Session过期时间
有时候在web.config设置sessionState 或者类文件里设置Session.Timeout,在IIS里访问时每次都是达不到时间就超时,原因是因为在IIS中设置了Session的超时时间, ...
- asp中设置session过期时间方法总结
http://www.jb51.net/article/31217.htm asp中设置session过期时间方法总结 作者: 字体:[增加 减小] 类型:转载 asp中默认session过期时间 ...
- Redis自学笔记:4.2进阶-过期时间
4.2过期时间 **4.2.1命令介绍* 在redis中使用 expire 命令设置一个键的过期时间后redis会自动删除它. expire key seconds (seconds单位是秒,必须是整 ...
- Redis学习笔记(十)——过期时间、访问限制与缓存
http://irfen.me/redis-learn-10-time-expire-limit-cache/ 过期时间 之前应该提到过 redis 的特性之一是可以设置键的超时时间.命令是expir ...
随机推荐
- [Python]pip 国内源
临时使用方法 pip install -i http://pypi.douban.com/simple/ --trusted-host pypi.douban.com celery END
- Day17-18前端学习之路——常用语句资料库
一.var 与 let 的区别 var: 可以先初始化再声明该变量; 可以根据需要多次声明相同名称的变量 var myName = 'Chris'; var myName = 'Bob'; let m ...
- 前缀和&差分
一:差分数组概念 一.差分数组的定义及用途 1.定义:对于已知有n个元素的数列d,建立记录它每项与前一项差值的差分数组f:显然,f[1]=d[1]-0=d[1];对于整数i∈[2,n],我们让f[i ...
- HTML连载68-形变中心点、形变中心轴
一. 形变中心点介绍 <style> ul li { width: 100px; height: 100px; list-style: none; float:left; margin:0 ...
- 剑指offer-面试题63-股票的最大利润-数组
/* 题目: 给定一个股价序列,求一次交易的最大利润. */ #include<iostream> #include<vector> using namespace std; ...
- SpringCloud入门学习
我相信,如果小伙伴们能来到这里,肯定对微服务有一定的认识. 我们之前创建web项目的时候,常见的有两种方式: 1).创建一个war包,然后放在servlet容器中运行(比如Tomcat等); 2).使 ...
- Linux系统的安装和常用命令
(1)切换到目录 /usr/bin: (2)查看目录/usr/local 下所有的文件: (3)进入/usr 目录,创建一个名为 test 的目录,并查看有多少目录存在: (4)在/usr 下新建目录 ...
- SQL内容补充
一.where和having 1.where 后不能跟聚合函数,因为where执行顺序大于聚合函数. 2. where 子句的作用是在对查询结果进行分组前,将不符合where条件的行去掉,即在分组之前 ...
- opencv —— imread、namedWindow & imshow、cvtColor、imwrite 加载、显示、修改、保存图像
加载图像:imread 函数 Mat imread(const string& filename, int flags = 1): filename:需要载入的图像的路径名. flags:加载 ...
- cf1214E
题意简述:构造一棵包含2*n个节点的树,要求2*i 和 2*i-1之间的距离等于d[i]<=n 1<=i<=n 给出N和d数组,输入对应的边 题解:对d数组按照从大到小排序,然后首先 ...