lRange 方法用于获取列表指定范围内的元素。
lRange(key: string, start, stop: number): string[]
参数
参数 | 类型 | 描述 |
key | string | 键名 |
start | string | 起始位置 |
stop | string | 结束位置 |
返回
类型 | 描述 |
string[] | 成功时,返回 [start, stop] 区间的元素 |
样例
import redis from "pts/redis";let client = new redis.Client("redis://:<password>@<host>:6379/0");export default function main() {let lPushResp = client.lPush("list", "foo", "bar", "zoo");console.log(`redis lPush ${lPushResp}`); // 3let lRangeResp = client.lRange("list", 0, 1);console.log(`redis lRange ${lRangeResp}`); // zoo,bar}