1 首先 redis 和 php 是配置好的
2 vi /etc/redis/redis.conf
把 notify-keyspace-events“”改成 notify-keyspace-events “Ex” 然后重启 redis service redis restart
3
<?php
ini_set('default_socket_timeout', -1); //不超时
require_once 'Redis2.php';
require_once 'db.php';
$redis = new Redis2();
$redis->setOption1();
$redis->psubscribe1(array('__keyevent@0__:expired'),function ($redis, $pattern, $chan, $msg){
最主要的是$msg 是过期的键值 用于自己的业务逻辑
Redis2 和 db.Php 贴上
<?php
class Redis2
{
private $redis;
public function __construct($host = '127.0.0.1', $port = 6379)
{
$this->redis = new Redis();
$this->redis->connect($host, $port);
}
public function setex($key, $time, $val)
{
return $this->redis->setex($key, $time, $val);
}
public function set($key, $val)
{
return $this->redis->set($key, $val);
}
public function get($key)
{
return $this->redis->get($key);
}