我看到你的标签 php
所以你的代码可以是:
$id = 3453451244;
$int = 1;
if ($redis->get("active:$id") === false) {
$redis->set("active:$id", $int);
$redis->expire("active:$id", 86400);
} else {
$_timePassed = $redis->ttl("active:$id");
$redis->set("active:$id", $redis->get("active:$botid") + 1);
$redis->expire("active:$id", $_timePassed);
}
解释:
第一个设置密钥和它对我来说过期我设置它有一天你可以使用:
function seconds2human($ss) {
$s = $ss%60;
$m = floor(($ss%3600)/60);
$h = floor(($ss%86400)/3600);
$d = floor(($ss%2592000)/86400);
$M = floor($ss/2592000);
return "$M months, $d days, $h hours, $m minutes, $s seconds";
}
转换秒 => $M 月,$d 天,$h 小时,$m 分钟,$s 秒
第二:
您必须将 ttl 保存在变量中 ..($_timePassed)
并使用 set&expire 为您设置新值...
如果您想重置为原始时间,只需更改 ($_timePassed) 以秒为单位的原始时间变量
$_timePassed = 86400; // 1 day
我在 php 上将这个库用于 redis:
https://github.com/phpredis/phpredis#expire-settimeout-pexpire
希望能回答您的问题。