Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/redis/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Time 在redis中创建密钥的时间_Time_Redis - Fatal编程技术网

Time 在redis中创建密钥的时间

Time 在redis中创建密钥的时间,time,redis,Time,Redis,假设我在2020年2月20日13:30在redis中这样做 > set foo "bar spam" OK 我想获得创建foo的时间。有类似的吗 > gettime foo 13:30 20 Feb 2020 ?Redis不存储此信息 您可以使用单独的密钥: MULTI SET foo "bar spam" SET foo:time "13:30 20 Feb 2020" EXEC GET foo:time 对于需要计时器检测过期值而不删除值本身的用例,还有另一个类似的选项来

假设我在2020年2月20日13:30在redis中这样做

> set foo "bar spam"
OK
我想获得创建
foo
的时间。有类似的吗

> gettime foo
13:30 20 Feb 2020

?Redis不存储此信息

您可以使用单独的密钥:

MULTI
SET foo "bar spam"
SET foo:time "13:30 20 Feb 2020"
EXEC

GET foo:time

对于需要计时器检测过期值而不删除值本身的用例,还有另一个类似的选项来解决此问题:

MULTI
SET foo "bar"
SET foo:alive 1 EX 30
EXEC
此处
30
-是所需的超时。然后,您可以通过以下方法确定值是否仍然“活动”:


我认为如果你知道最初的TTL是可能的

您可以这样做:

$init = 60; //initial time
$ttl = $redis->ttl("key"); //current ttl
$diff = $init - $ttl; //difference is the time passed after key was created
$creation = time() - $diff; //this is creation time in seconds since unix epoch

获取创建时间的内置命令对于调试非常有用……我认为这是在Redis中存储创建时间的一个很好的解决方法,但是如果您不希望密钥过期,请确保将其设置为一个很长的过期时间,这样就永远不会发生,比如30年(946080000)
$init = 60; //initial time
$ttl = $redis->ttl("key"); //current ttl
$diff = $init - $ttl; //difference is the time passed after key was created
$creation = time() - $diff; //this is creation time in seconds since unix epoch