Redis的限制列表长度 [英] Limit list length in redis

查看:1778
本文介绍了Redis的限制列表长度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Redis列表,并将新项目推送到列表中。问题是我真的只需要列表中最近的10个项目。

I'm using redis lists and pushing to new items to a list. The problem is I really only need the most recent 10 items in a list.

我正在使用 lpush 将项目添加到列表中,并添加 lrange 以获取最新的10。

I'm using lpush to add items to a list and lrange to get the most recent 10.

是否有一定数目的物品掉落物品?我将得到可能包含1,000个项目的列表,这些列表可能会导致性能延迟。

Is there anyway to drop items after a certain number? I'll end up with lists that may have 1,000's of items and can cause performance issues with latency.

谢谢!

推荐答案

在每次 lpush 之后,调用 ltrim 进行修剪列表中的10个元素

After every lpush, call ltrim to trim the list to 10 elements

请参见 http:// redis。 io / commands / ltrim

这篇关于Redis的限制列表长度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆