Client.ttl(key)
返回具有超时的键的剩余生存时间。
参数
参数 | 类型 | 描述 |
---|---|---|
key | string | 要获取 TTL 的键。 |
返回值
类型 | 成功时返回 | 失败时拒绝 |
---|---|---|
Promise<number> | 成功时,Promise 将返回以秒为单位的 TTL 值。 |
示例
import redis from 'k6/experimental/redis';
// Instantiate a new redis client
const redisClient = new redis.Client('redis://:6379');
export default async function () {
await redisClient.set('mykey', 'myvalue', 10);
await redisClient.expire('mykey', 100);
const ttl = await redisClient.ttl('mykey');
if (ttl <= 10) {
throw new Error('mykey should have a ttl of 10 <= x < 100');
}
await redisClient.persist('mykey', 100);
}