Class: RedisRds::String

Inherits:
Object
  • Object
show all
Defined in:
lib/redis_rds/string.rb

Direct Known Subclasses

Counter, Mutex

Instance Attribute Summary

Attributes inherited from Object

#redis_key

Instance Method Summary collapse

Methods inherited from Object

configure, #connection, connection, #delete, #dump, #exists?, #expire, #expireat, flushdb, #initialize, #namespace, #persist, #pttl, #ttl, #type

Constructor Details

This class inherits a constructor from RedisRds::Object

Instance Method Details

#append(suffix) ⇒ Object



26
27
28
# File 'lib/redis_rds/string.rb', line 26

def append(suffix)
  return connection.append(@redis_key, suffix)
end

#decrObject



46
47
48
# File 'lib/redis_rds/string.rb', line 46

def decr
  return connection.decr(@redis_key)
end

#decrby(decrement) ⇒ Object



50
51
52
# File 'lib/redis_rds/string.rb', line 50

def decrby(decrement)
  return connection.decrby(@redis_key, decrement)
end

#getObject



3
4
5
# File 'lib/redis_rds/string.rb', line 3

def get
  return connection.get(@redis_key)
end

#incrObject



30
31
32
# File 'lib/redis_rds/string.rb', line 30

def incr
  return connection.incr(@redis_key)
end

#incrby(increment) ⇒ Object



34
35
36
# File 'lib/redis_rds/string.rb', line 34

def incrby(increment)
  return connection.incrby(@redis_key, increment)
end

#lengthObject



38
39
40
# File 'lib/redis_rds/string.rb', line 38

def length
  return connection.strlen(@redis_key)
end

#set(value, expiry: nil, nx: nil, xx: nil) ⇒ Boolean

Lifted from npepine/restruct

Parameters:

  • value (Object)

    The object to store; note, it will be stored using a string representation

  • expiry (Integer) (defaults to: nil)

    The expiry time in seconds; if nil, will never expire

  • nx (Boolean) (defaults to: nil)

    Not Exists: if true, will not set the key if it already existed

  • xx (Boolean) (defaults to: nil)

    Already Exists: if true, will set the key only if it already existed

Returns:

  • (Boolean)

    True if set, false otherwise



13
14
15
16
17
18
19
20
# File 'lib/redis_rds/string.rb', line 13

def set(value, expiry: nil, nx: nil, xx: nil)
  options = {}
  options[:ex] = expiry.to_i unless expiry.nil?
  options[:nx] = nx unless nx.nil?
  options[:xx] = xx unless xx.nil?

  connection.set(@redis_key, value, options)
end

#setex(value, expiry) ⇒ Object



22
23
24
# File 'lib/redis_rds/string.rb', line 22

def setex(value, expiry)
  return connection.setex(@redis_key, expiry, value)
end

#setnx(value) ⇒ Object



42
43
44
# File 'lib/redis_rds/string.rb', line 42

def setnx(value)
  return connection.setnx(@redis_key, value)
end