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 ...
随机推荐
- 一键安装apache-2.4.38脚本
[root@lamp scripts]# cat /etc/redhat-release CentOS Linux release 7.5.1804 (Core) [root@lamp scripts ...
- CentOS6.5下部署SVN
查看系统版本,安装SVN软件及创建目录 [root@A-linux ~]# uname -r 2.6.32-431.el6.x86_64 [root@A-linux ~]# cat /etc/redh ...
- matplotlib如何显示中文
问题:matplotlib不能渲染中文 想设定为中文字体,网上搜索的方法几乎都是下面这样,已经把字体拷贝到了程序目录下了,然而并没有生效 plt.rcParams [ font.sans-serif' ...
- C#基础知识学习(1)方法的重写和隐藏
做了1年多了C#,发现些项目过程中很多基础东西都不是很清晰,基础不够牢固.现在开始复习基础知识并做重点记录 方法需要被重写的时候,可以在方法前加入virtual使方法变成虚方法. 这样我们可以重新写个 ...
- 为什么我不建议在C#中用下划线_开头来表示私有字段
我在C#官方文档的使用属性里看到这种代码: public class Date { private int _month = 7; // Backing store public int Month ...
- eclipse创建java和web工程
JAVA Eclipse→File→New→Project.. WEB 右键mvn项目→Properties src/main/webapp pom.xml <project xmlns=&qu ...
- CentOS安装python3环境
CentOS7.4安装python3环境 (Python 3.8.1) (stable version, Dec.18, 2019) # .从官网下载Python - Dec. , [stable v ...
- 【转载】sql-builder介绍
原文链接:sql-builder介绍 关于sql-builder sql-builder尝试使用java对象,通过类SQL的拼接方式,动态快速的生成SQL.它可作为稍后的开源项目ibit-mybati ...
- css基本概念与css核心语法介绍
css基本概念 css是什么?不需要了解太多文字类介绍,记住css是层叠样式表,HTML是页面结构,css负责页面样式,javascrt负责静态页面的交互.CSS 能够对网页中元素位置的排版进行像素级 ...
- Android中动态改变Listview中字体的颜色
效果如下: 账目显示用的是Listview,要实现的功能为使其根据所在Item是“收入”还是“支出”来把数字设置成绿色或红色 方法是自定义适配器,并重写其中getView()函数,实现如下: //自定 ...