Skip to content

Commit 74053c3

Browse files
committed
Fix Redis#{ttl,pttl} doc when key doesn't exist
The doc states that Redis#{ttl,pttl} return -1 if the key does not exist **or** if the key exists but has no associated expire. This is incorrect with respect to the Redis' doc [here](http://redis.io/commands/ttl) The documentation is also incorrent with respect to the current library behavior: ``` irb(main):059:0* conn = Redis.new => #<Redis client v3.1.0 for redis://127.0.0.1:6379/0> irb(main):060:0> conn.ttl 'asdf' => -2 irb(main):065:0> conn.set 'asdf', 123 => "OK" irb(main):070:0> conn.ttl 'asdf' => -1 irb(main):071:0> conn.expire 'asdf', 100 => true irb(main):082:0> conn.ttl 'asdf' => 99 irb(main):059:0* conn = Redis.new => #<Redis client v3.1.0 for redis://127.0.0.1:6379/0> irb(main):085:0> conn.pttl 'jkl;' => -2 irb(main):086:0> conn.set 'jkl;', 123 => "OK" irb(main):089:0> conn.pttl 'jkl;' => -1 irb(main):090:0> conn.expire 'jkl;', 100 => true irb(main):093:0> conn.pttl 'jkl;' => 91225 irb(main):097:0> ``` This commit adds the mention to a `-2` return value.
1 parent 98e3e7a commit 74053c3

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)