Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Must I get Length of List first and then query List in Redis?

Tags:

redis

I wanna know if only lrange could get a List in Redis? It needs the end parameter, and if I wanna the full List, I must use llen to get the length first. Like this:

redis.lrange("myList", 0, llen("myList"));

Whether there's any method can get a full List directly?

like image 207
Hesey Avatar asked Apr 16 '12 08:04

Hesey


1 Answers

You can use -1 as an index of last element. This will get you the whole list:

lrange mylist 0 -1

And this will get whole list but the last element

lrange mylist 0 -2

And so forth...

By the way, it's all written in the documentation.

like image 138
Sergio Tulentsev Avatar answered Oct 31 '22 01:10

Sergio Tulentsev