I am using geo-support on Redis.
Adding new geolocations this way:
"GEOADD" "report-geo-set" "30.52439985197" "50.56539003041" "john"
I want to expire john key from report-geo-set after X hours.
Any suggestions doing that?
Thank you, ray.
To create a Redis with an expiration time, use the SET command and the EX option to set the expiration time. The EX option takes a number in seconds and sets the number of seconds the key is valid until expiration. You can also use PX to specify the expiration time in Milliseconds.
Normally Redis keys are created without an associated time to live. The key will simply live forever, unless it is removed by the user in an explicit way, for instance using the DEL command.
There is no default TTL. By default, keys are set to live forever.
How does it work? The way the sorted set is populated is using a technique called Geohash. Latitude and Longitude bits are interleaved to form a unique 52-bit integer.
Not possible with built-in commands. Keep in mind that geo-support based on zset and your question is look`s like "How to use TTL for individual keys in ZSET".
You may use something like that:
Example of given suggestion. Add items:
MULTI
GEOADD report-geo-set 30.52439985197 50.56539003041 john
ZADD geo-timeout 1452600528 john //1452600528 is unix time stamp current + X hours
EXEC
Clean up script called from time to time (with 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;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With