Latest web development tutorials

Redis Lrange 命令

Redis列表(List)

Redis Lrange 返回列表中指定區間內的元素,區間以偏移量START 和END 指定。 其中0 表示列表的第一個元素, 1 表示列表的第二個元素,以此類推。 你也可以使用負數下標,以-1 表示列表的最後一個元素, -2 表示列表的倒數第二個元素,以此類推。

語法

redis Lrange 命令基本語法如下:

redis 127.0.0.1:6379> LRANGE KEY_NAME START END

可用版本

>= 1.0.0

返回值

一個列表,包含指定區間內的元素。

實例

redis 127.0.0.1:6379> LPUSH list1 "foo"
(integer) 1
redis 127.0.0.1:6379> LPUSH list1 "bar"
(integer) 2
redis 127.0.0.1:6379> LPUSHX list1 "bar"
(integer) 0
redis 127.0.0.1:6379> LRANGE list1 0 -1
1) "bar"
2) "bar"
3) "foo"

Redis列表(List)