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