1

I'm not expert in redis so does anyone knows how can I create a key that can have subkeys, and these subkeys must have an expire time each one. Is this possible in Redis??

It would be something like this:

[:keyX]
  |
  V
[:keyZ][:value]
   |
   V
EXPIRE keyZ 100

PS. the app is in ruby.

Thanks!

Roman Kiselenko
  • 43,210
  • 9
  • 91
  • 103
betoharres
  • 1,736
  • 2
  • 19
  • 25

1 Answers1

2

Redis does not have nested keys, although the Hash data type could work for you. Also, Redis expiry is only for keys - Hash fields, List elements or Sorted and regular Sets members can not be assigned with an independent TTL.

Your question does not detail why you're looking to do that (i.e. store keys under a "root" key and have each key expire on its own). You can get the per-key expiration effect by using plain ol' regular keys, or use a Hash to aggregate all the fields under one common key - but not both at the same time.

That said, if you really need this sort of functionality you can always try implementing it yourself - see here for a possible direction: Redis: To set timeout for a key value pair in Set

Community
  • 1
  • 1
Itamar Haber
  • 47,336
  • 7
  • 91
  • 117