如何使redis上的地理位置过期
How to expire gelocations on redis
我在 Redis 上使用地理支持。
以这种方式添加新的地理位置:
"GEOADD" "report-geo-set" "30.52439985197" "50.56539003041" "john"
我想在 X 小时后使来自 report-geo-set 的 john key 过期。
有什么建议吗?
谢谢,
射线。
built-in 命令不可能。请记住,geo-support 基于 zset,您的问题看起来像 "How to use TTL for individual keys in ZSET"。
你可以使用类似的东西:
- 将 "john" 添加到额外的特殊超时 ZSET 与 time() + X 小时分数。
- 不时运行 script/worker 从超时 zset 中获取所有过时的密钥并为您的 "john" 密钥执行 ZREM。
给定建议的示例。添加项目:
MULTI
GEOADD report-geo-set 30.52439985197 50.56539003041 john
ZADD geo-timeout 1452600528 john //1452600528 is unix time stamp current + X hours
EXEC
清理不时调用的脚本(LUA):
local currentTime = redis.call('TIME');
local list = redis.call('ZRANGEBYSCORE', 'geo-timeout', 0, currentTime[0]);
local keysRemoved = 0;
for i, name in ipairs(list) do
redis.call('ZREM', 'geo-timeout', name);
redis.call('ZREM', 'report-geo-set', name);
keysRemoved = keysRemoved + 1;
end
return keysRemoved;
我在 Redis 上使用地理支持。
以这种方式添加新的地理位置:
"GEOADD" "report-geo-set" "30.52439985197" "50.56539003041" "john"
我想在 X 小时后使来自 report-geo-set 的 john key 过期。
有什么建议吗?
谢谢, 射线。
built-in 命令不可能。请记住,geo-support 基于 zset,您的问题看起来像 "How to use TTL for individual keys in ZSET"。
你可以使用类似的东西:
- 将 "john" 添加到额外的特殊超时 ZSET 与 time() + X 小时分数。
- 不时运行 script/worker 从超时 zset 中获取所有过时的密钥并为您的 "john" 密钥执行 ZREM。
给定建议的示例。添加项目:
MULTI
GEOADD report-geo-set 30.52439985197 50.56539003041 john
ZADD geo-timeout 1452600528 john //1452600528 is unix time stamp current + X hours
EXEC
清理不时调用的脚本(LUA):
local currentTime = redis.call('TIME');
local list = redis.call('ZRANGEBYSCORE', 'geo-timeout', 0, currentTime[0]);
local keysRemoved = 0;
for i, name in ipairs(list) do
redis.call('ZREM', 'geo-timeout', name);
redis.call('ZREM', 'report-geo-set', name);
keysRemoved = keysRemoved + 1;
end
return keysRemoved;