Skip to content

Commit 43c7463

Browse files
committed
Merge pull request #544 from rranelli/fix-ttl-doc-non-existing-key
Fix Redis#{ttl,pttl} doc when key doesn't exist
2 parents 5af8c80 + 74053c3 commit 43c7463

File tree

1 file changed

+17
-4
lines changed

1 file changed

+17
-4
lines changed

lib/redis.rb

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -329,8 +329,15 @@ def expireat(key, unix_time)
329329
# Get the time to live (in seconds) for a key.
330330
#
331331
# @param [String] key
332-
# @return [Fixnum] remaining time to live in seconds, or -1 if the
333-
# key does not exist or does not have a timeout
332+
# @return [Fixnum] remaining time to live in seconds.
333+
#
334+
# In Redis 2.6 or older the command returns -1 if the key does not exist or if
335+
# the key exist but has no associated expire.
336+
#
337+
# Starting with Redis 2.8 the return value in case of error changed:
338+
#
339+
# - The command returns -2 if the key does not exist.
340+
# - The command returns -1 if the key exists but has no associated expire.
334341
def ttl(key)
335342
synchronize do |client|
336343
client.call([:ttl, key])
@@ -362,8 +369,14 @@ def pexpireat(key, ms_unix_time)
362369
# Get the time to live (in milliseconds) for a key.
363370
#
364371
# @param [String] key
365-
# @return [Fixnum] remaining time to live in milliseconds, or -1 if the
366-
# key does not exist or does not have a timeout
372+
# @return [Fixnum] remaining time to live in milliseconds
373+
# In Redis 2.6 or older the command returns -1 if the key does not exist or if
374+
# the key exist but has no associated expire.
375+
#
376+
# Starting with Redis 2.8 the return value in case of error changed:
377+
#
378+
# - The command returns -2 if the key does not exist.
379+
# - The command returns -1 if the key exists but has no associated expire.
367380
def pttl(key)
368381
synchronize do |client|
369382
client.call([:pttl, key])

0 commit comments

Comments
 (0)