redis - 如何使用redis将元数据与对象相关联

标签 redis

例如,我在 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/

相关文章:

Redis——AOF持久化

java - 将 spring boot 与 redis 混合

每个缓存键的 Azure Redis 缓存统计信息

.net - Windows 上的 Redis 用于 session 状态性能和 protobuf

python - Django channel 不会使用 CHANNEL_LAYERS 启动 redis 服务器

amazon-web-services - 在 Elasticache (Redis) 中分区数据的正确方法

redis - Jedis如何使用套接字连接到redis服务器?

laravel - 从缓存laravel中的数组获取对象值

node.js - Socket.IO RedisStore 和 xhr 轮询

docker - redis官方docker镜像端口暴露给windows