Client.exists(keys)
返回存在的 key
参数数量。请注意,如果同一个存在的 key 在参数中被多次提及,它将被多次计数。
参数
参数 | 类型 | 描述 |
---|---|---|
keys | string[] | 要检查其是否存在的键。 |
返回值
类型 | 解析为 | 何时拒绝 |
---|---|---|
Promise<number> | 成功时,Promise 将解析为参数中指定的、存在的 key 的数量。 |
示例
import redis from 'k6/experimental/redis';
// Instantiate a new redis client
const redisClient = new redis.Client('redis://:6379');
export default async function () {
let exists = await redisClient.exists('mykey');
if (exists === true) {
throw new Error('mykey should not exist');
}
await redisClient.set('mykey', 'myvalue', 0);
exists = await redisClient.exists('mykey');
if (exists === false) {
throw new Error('mykey should exist');
}
await redisClient.del('mykey');
}