TAGS :Viewed: 1 - Published at: a few seconds ago

[ Add to Redis Set ]

I am reading Redis, from the ground up and I can't understand this part:

redis> MULTI
OK
redis> SET article.technology.1021 "In today's technology news, ..."
QUEUED
redis> SADD article.technology 1021
QUEUED
redis> PUBLISH new.article.technology 1021
QUEUED
redis> EXEC
1. OK
2. (integer) 1
3. (integer) 1

why there is a SET and then a SADD?, and why the SADD call receives a 1021, instead of the value of the article?

Answer 1


The first command - SET article.technology.1021 "In today's technology news, ..." - is used to set the article's content/topic as the value of a key called article.technology.1021. Note that the article's id is a part of the key's name.

Then, the next command, i.e. SADD article.technology 1021, adds that article (id) to the set called article. technology. That set can be used to retrieve all the articles (actual ids) that belong to the technology category, e.g. by doing SMEMBERS article.technology. The response will be all of the article ids that are in that set (belong to the technology category) so you could, potentially, fetch or process those.