Method: Redis::Commands::Strings#getex

Defined in:
lib/redis/commands/strings.rb

#getex(key, ex: nil, px: nil, exat: nil, pxat: nil, persist: false) ⇒ String

Get the value of key and optionally set its expiration. GETEX is similar to GET, but is a write command with additional options. When no options are provided, GETEX behaves like GET.

Parameters:

  • key (String)
  • options (Hash)
    • :ex => Integer: Set the specified expire time, in seconds.
    • :px => Integer: Set the specified expire time, in milliseconds.
    • :exat => true: Set the specified Unix time at which the key will expire, in seconds.
    • :pxat => true: Set the specified Unix time at which the key will expire, in milliseconds.
    • :persist => true: Remove the time to live associated with the key.

Returns:

  • (String)

    The value of key, or nil when key does not exist.



293
294
295
296
297
298
299
300
301
302
# File 'lib/redis/commands/strings.rb', line 293

def getex(key, ex: nil, px: nil, exat: nil, pxat: nil, persist: false)
  args = [:getex, key]
  args << "EX" << Integer(ex) if ex
  args << "PX" << Integer(px) if px
  args << "EXAT" << Integer(exat) if exat
  args << "PXAT" << Integer(pxat) if pxat
  args << "PERSIST" if persist

  send_command(args)
end