Redis无需迭代也无需弹出即可获取列表的所有值 [英] Redis fetch all value of list without iteration and without popping

查看:57
本文介绍了Redis无需迭代也无需弹出即可获取列表的所有值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有简单的 redis 列表键 => "supplier_id"

I have simple redis list key => "supplier_id"

现在我只希望它检索列表的所有值,而无需实际迭代或从列表中弹出值

Now all I want it retrieve all value of list without actually iterating over or popping the value from list

从列表中检索所有值的示例现在我已经遍历了 redis 长度

Example to retrieve all the value from a list Now I have iterate over redis length

element = []
0.upto(redis.llen("supplier_id")-1) do |index| 
  element << redis.lindex("supplier_id",index)
 end

这可以在没有迭代的情况下完成,也许可以通过更好的 redis 建模来完成.谁能推荐一下

can this be done without the iteration perhap with better redis modelling . can anyone suggest

推荐答案

要使用 Redis 检索列表的所有项目,您无需迭代和获取每个单独的项目.这将是非常低效的.

To retrieve all the items of a list with Redis, you do not need to iterate and fetch each individual items. It would be really inefficient.

您只需使用 LRANGE 命令即可一次检索所有项目.

You just have to use the LRANGE command to retrieve all the items in one shot.

elements = redis.lrange( "supplier_id", 0, -1 )

将返回列表中的所有项目而不改变列表本身.

will return all the items of the list without altering the list itself.

这篇关于Redis无需迭代也无需弹出即可获取列表的所有值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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