开发者社区 问答 正文

redis 控制hash同一实体数量的疑问

最近学习redis,还是有一些疑问。麻烦大家指导下
现在我用redis存储一些对象,用 media:id作为key,hash结构 来存储多个属性。
但是我不想所有的media都存,我只想要最新的500条数据存到redis就够了。
我知道redis提供了expire方法,但是这个满足不了我的需求。
我看资料都只是list数据结构有只存最新多少个的方法。对于hash存储对象这种方式,难道就没有办法吗?
谢谢!

展开
收起
落地花开啦 2016-02-22 10:05:38 3073 分享 版权
1 条回答
写回答
取消 提交回答
  • A hash with a few fields (where few means up to one hundred or so) is stored in a way that takes very little space, so you can store millions of objects in a small Redis instance. While Hashes are used mainly to represent objects, they are capable of storing many elements, so you can use Hashes for many other tasks as well. Every hash can store up to 2^32 - 1 field-value pairs (more than 4 billion). 摘自Redis官网的Data type章节,意思是内存允许的情况下,可以存超过40亿数据。 网页链接

    2019-10-14 19:57:16
    赞同 展开评论