/** * 获取键值 * @param string $key 键名 * @return mixed|false 键值,失败返回false */ public function get($key) { try { return $this->getValue($this->handler->get($key)); } catch (RedisException $ex) { self::exception($ex); //连接状态置为false $this->isConnected = false; } return false; }
/** * 获取延迟过期的键值理论生存剩余时间 * @param string $key 键名 * @return int|false 生存剩余时间(单位:秒) -1表示永不过期,-2表示键值不存在,失败返回false */ public function ttlDE($key) { try { $ttl = $this->handler->ttl($key); if ($ttl > 0) { $value = self::getValue($this->handler->get(self::timeKey($key))); if (isset($value['expire_time']) && isset($value['delay_time'])) { $ttl = $value['expire_time'] - $value['delay_time'] - time(); return $ttl > 0 ? $ttl : -2; } } return $ttl; } catch (RedisException $ex) { self::exception($ex); //连接状态置为false $this->isConnected = false; } return false; }