Interface ExpirationClient

自动过期

interface ExpirationClient {
    expire: ((key, seconds) => number);
    ttl: ((key) => number);
}

Hierarchy (view full)

Properties

Properties

expire: ((key, seconds) => number)

为给定 key 设置生存时间,当 key 过期时(生存时间为 0 ),它会被自动删除。

可以对一个已经带有生存时间的 key 执行 EXPIRE 命令,新指定的生存时间会取代旧的生存时间。

设置成功返回 1 。 当 key 不存在或者不能为 key 设置生存时间时(比如在低于 2.1.3 版本的 Redis 中你尝试更新 key 的生存时间),返回 0 。

Type declaration

    • (key, seconds): number
    • Parameters

      • key: string

        键值

      • seconds: number

        生存时间(秒)

      Returns number

ttl: ((key) => number)

以秒为单位,返回给定 key 的剩余生存时间(TTL, time to live)。

当 key 不存在时,返回 -2 。 当 key 存在但没有设置剩余生存时间时,返回 -1 。 否则,以秒为单位,返回 key 的剩余生存时间。

Type declaration

    • (key): number
    • Parameters

      • key: string

        键值

      Returns number