Idiom to manage on-demand cache in Redis' set
Redis 2.0. (Solutions for 2.2 are also interesting, but, sadly, I can't upgrade yet.)
I need to store some data in Redis set:
SADD mycache apple
SADD mycache orange
This cached data would be used with SINTER
commands:
SADD foo apple
SADD foo pear
... later ...
SINTER foo mycache
I want to be able to create the mycache
set on-demand. That is, check if set is there when SINTER
is issued, and create it if it is missing.
But I can't see how can I achieve this effectively. The only solution I see is as follows:
MULTI
EXISTS mycache
SINTER foo mycache
EXEC
...And check o开发者_StackOverflow社区n client if first command returned true. Is it the best solution available?
Or maybe I am going against the Redis "way of things"?
Well, I ended up using the solution included in the question. It works.
If you know anything better than that — please post it here.
精彩评论