English 中文(简体)
Rediis 不重复且不弹出获取列表的所有值
原标题:Redis fetch all value of list without iteration and without popping
  • 时间:2012-05-22 13:27:05
  •  标签:
  • redis

我有简单的 Redis 列表密钥 *\ gt; “ 供应商_ id ”

现在我要它全部取回列表的全部值, 而不实际循环或从列表中弹出此值

从列表中获取全部值的示例

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

它可以做到 < 坚固 >, 而不重复 < / 坚固 > perhap, 并有更好的 redis 建模 。 任何人都可以建议

最佳回答

要用 Redis 检索列表中的所有项目, 您不需要复制和获取每个单个项目。 这将非常低效 。

您只需使用 < a href= > "http://redis.io/commants/lrange" rel= "noreferrer" >LRANGE 命令即可在一个镜头中检索所有物品 。

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

将返回列表中的所有项目,而不更改列表本身 。

问题回答

我不太清楚你的问题,但如果供应商的代号是数字,为什么不使用 ?

添加这样的值 :

ZADD suppliers 1 "data f或 supplier 1"  
ZADD suppliers 2 "data f或 supplier 2"  
ZADD suppliers 3 "data f或 supplier 3"  

然后,你可以将所有东西除去至(但不包括供应方三),如:

ZREMRANGEBYSCORE suppliers -inf 2

ZREMRANGEBYSCORE suppliers -inf (3

如果您只想读的话,这也可以非常迅速地进入(供应商代号) 。

希望有帮助!





相关问题
How do you mix SQL DB vs. Key-Value store (i.e. Redis)

I m reviewing my code and realize I spend a tremendous amount of time taking rows from a database, formatting as XML, AJAX GET to browser, and then converting back into a hashed javascript object ...

Predis sharding (consistent hashing)

Predis claim to have Client-side sharding (support for consistent hashing of keys). http://github.com/nrk/predis I can do sharding using connect to an array of profiles (nodes) but it isn t ...

key value stores for extendable objects

http://www.infoq.com/presentations/newport-evolving-key-value-programming-model is a video about KV stores, and the whole premise is that redis promotes a column-based style for storing the attributes ...

nginx/redis and handling tracking params in url

I am using nginx and redis in my website. For several items on my site, I want to add tracking params to their urls so that when a user clicks on an item, I can collect statistics of user usage apart ...

热门标签