Redis-x64-3.2 键空间通知(keyspace notification)
2021-08-24 19:14
791 查看
前言
Redis2.8 后可以通过键空间通知(设置 notify-keyspace-events)接收那些以某种方式改变了Redis数据空间的事件通知,关于 Redis 键空间通知的文章有很多,这里只是记录个人在 Redis-x64-3.2 版本下实现过程中出现的问题。
具体实现
键空间通知设置的两种方式
1.命令行设置
- redis启动后进入redis-cli模式
- 命令行设置 notify-keyspace-events
config set notify-keyspace-events Ex
- Ex说明
Ex,E(Keyevent events)代表键事件通知,x(Expired events)代表过期事件,每当有过期键被删除时发送
- 注:该设置会在 redis 终端关闭后失效
2.修改配置文件 redis.windows.conf
- 修改键空间通知事件 notify-keyspace-events
修改 - 887行 notify-keyspace-events Ex // 取消注释 修改 - 892行 notify-keyspace-events "" // 注释
- 注意事项:
1、notify-keyspace-events "" 为默认配置,需注释,否则键空间通知无法生效 2、notify-keyspace-events Ex 需顶格(不能有空格),否则启动会报错 " Invalid argument during startup: unknown conf file parameter "
Redis-x64-3.2 键空间通知的操作
- 启动reids
redis-server ./redis.windows.conf
- 新打开一个终端,添加过期事件订阅
redis-cli psubscribe __keyevent@0__:expired
- 新打开一个终端,添加过期事件
redis-cli setex name 10 coisini // 添加一个 key为name 过期时间为10s 值为coisini 的键
- 添加过期事件订阅经10秒后输出如下信息:
- Then:过期Key订阅成功了。
相关文章推荐
- redis键空间通知消息详解和例子
- SpringBoot + Redis 实现键空间通知(keyspace notification)
- Redis源码解析:09redis数据库实现(键值对操作、键超时功能、键空间通知)
- 解决Redis集群条件下键空间通知服务器接收不到消息的问题
- 10Redis键空间通知(keyspace notifications)
- 利用Redis keyspace notification(键空间通知)实现过期提醒
- 远程启动Redis,报错不能配置键空间通知(keyspace notifications)
- Redis键空间通知(keyspace notifications)
- redis中键空间通知
- Redis 键空间通知
- Redis 小白指南(三)- 事务、过期、消息通知、管道和优化内存空间
- Redis基础学习--Redis 事务(watch命令)、生存时间、排序、消息通知("发布/订阅"模式)、管道、节省空间
- Redis 小白指南(三)- 事务、过期、消息通知、管道和优化内存空间
- Redis 键空间通知
- Redis实践操作之—— keyspace notification(键空间通知)
- PHP对Redis键空间通知过期事件的应用实例
- 收集服务器硬盘空间,并用邮件通知管理员
- linux下热插拔事件的产生是怎样通知到用户空间,kobject_uevent_env之uevent , kset !!!
- Python3.2官方文档翻译--作用域和命名空间实例
- 在windows x64上部署使用Redis