Method: Redis#ttl

Defined in:
lib/redis.rb

#ttl(key) ⇒ Integer

Get the time to live (in seconds) for a key.

In Redis 2.6 or older the command returns -1 if the key does not exist or if the key exist but has no associated expire.

Starting with Redis 2.8 the return value in case of error changed:

- The command returns -2 if the key does not exist.
- The command returns -1 if the key exists but has no associated expire.

Parameters:

  • key (String)

Returns:

  • (Integer)

    remaining time to live in seconds.



453
454
455
456
457
# File 'lib/redis.rb', line 453

def ttl(key)
  synchronize do |client|
    client.call([:ttl, key])
  end
end