例如,我在 redis 中有一篇新闻文章:
SET article:id '{ "title": "this is the title", "content": "this is the content" }'
现在说我想像标签一样关联一些元数据,比如“政治”。执行此操作的惯用方法是什么?
是否会按照 article:<id>:tags
这样的约定为具有集合 ID 的标签添加一个集合? ?
SADD article:id:tags 'politics'
最佳答案
您可能要考虑使用 redis hash为此
HMSET article:id "title" "this is the title" "content" "this is the content" "tag" "politics"
如果你想通过标签获取文章,反向集可能会更好
SADD tags:politics article_id
关于redis - 如何使用redis将元数据与对象相关联,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45053821/