You can only expire entire keys (a whole set, hash, zset, list, or
string) at a time.
Generally, sets are not terribly good queues, as fast read/remove
access patterns for individual items involve randomly popping items.
Most people choose to use lists as queues, as they have obvious
first-in-first-out (or last-in-first-out) behavior.
To get a queue with expiration behavior, I can think of a two
different ways of building it with Redis.
1. Store your queue items in a list or set or whatever
2. When you add an item X to the queue, also set a key 'item:X' to an
empty string with an expiration.
3. When you fetch an item from the queue, delete the representative
key. If the deletion occurred, then execute the queue item, otherwise
discard it (because it expired)
1. Store your queue items in a sorted set, with members being your
queue items, and the score being your expiration time
2. You manually expire old items by removing items with expiration
times in the past
3. You can fetch items based on their expiration times with "ZRANGE
QUEUE 0 0", or randomly with "count = ZCARD QUEUE; index =
floor(random() * count); ZRANGE QUEUE index index", but you need to
ZREM items once you've pulled them from the queue.