Client.lset(key, index, element)
将列表在 index
位置的元素设置为 element
。
参数
参数 | 类型 | 描述 |
---|---|---|
key | string | 要设置元素的列表的 key。 |
index | number | 要设置的元素的索引。 |
element | string | 要设置给元素的 value。 |
返回值
类型 | 解析为 | 拒绝时 |
---|---|---|
Promise<string> | 成功时,Promise 解析为 OK 。 | 如果列表不存在,或者索引超出范围,则 Promise 将被拒绝并带有一个错误。 |
示例
import redis from 'k6/experimental/redis';
// Instantiate a new redis client
const redisClient = new redis.Client('redis://:6379');
export default async function () {
await redisClient.rpush('mylist', 'first');
await redisClient.rpush('mylist', 'second');
await redisClient.rpush('mylist', 'third');
await redisClient.lset('mylist', 0, 1);
await redisClient.lset('mylist', 1, 2);
}