Hello Tom!
the short answer is that it is not possible, but actually there are
patterns to make this possible.
This patterns have different tradeoffs. There are mainly three
patterns to do this:
1) Store the set element together with a timestamp. For instance if
your set is element is "foo", instead store "foo:<unix timestamp>",
where the unix timestamp is the time at which the element should no
longer be considered valid. So you handle this at application level.
The obvious problem is that if you don't access set elements this will
stay forever.
2) Use a sorted set (a single, global one for all the sets you have)
where the score is the unix time at which an expire will happen, and
the value is the encoded key-name+set-element, so that in a worker you
can get this data every second from the sorted set, and purge the old
entries.
3) mix 1+2 and just store in the sorted set an entry for every whole
set where you know you have at least one expire: use always the
nearest expire of the sorted set as key. In a worker check all the
elements of the set and purge only what's needed, then update the
score in the sorted set to the next-to-expire element in the set. This
is viable only if the sets are small.
Possibly there are other methods, but here the bottom line is: you
have to mount such a mechanism at application level using what Redis
provides.
One thing that we may do in future, is to provide timers. Ways to tell Redis:
AFTER 10
SREM myset foo
EXEC
That is, execute this command(s) in 10 seconds starting from now. Just
an idea... but may be an interesting experiment.
Cheers,
Salvatore
--
Salvatore 'antirez' Sanfilippo
http://invece.org
"Once you have something that grows faster than education grows,
you’re always going to get a pop culture.", Alan Kay
> So I thought about using KEYS to find, well, the keys according to my
> scope needs and then I would simply use strings to store the vehicle
> id's or even the the complete vehicle data to save one lookup.
> And then the keys could simply expire.
Well everything can be abused as long as it solves a problem, but
maybe you should look at sorted sets and the ZRANGEBYSCORE command.
Now maybe I'm understanding the expire problem better. What do you
want is dropping the vehicle form the set when you don't get fresh
information for N seconds? If this is what you are trying to do, I
think there is a good solution using a sorted set, that is simply to
remember in a sorted set the last time (use the unix time as score)
you got an updated location of a given vehicle, and in which key it is
located. So you can have the worker purging old info every second.
Salvatore
--
Salvatore 'antirez' Sanfilippo