Class: Redstruct::String
- Includes:
- Utils::Scriptable
- Defined in:
- lib/redstruct/string.rb
Overview
Manipulation of redis strings
Direct Known Subclasses
Instance Attribute Summary
Attributes inherited from Struct
Lua Scripts collapse
Instance Method Summary collapse
-
#delete_if_equals(value) ⇒ Boolean
True if deleted, false otherwise.
-
#get ⇒ String?
The string value stored in the database.
-
#getset(value) ⇒ String
The old value before setting it.
-
#length ⇒ Integer
The length of the string.
-
#set(value, expiry: nil, nx: false, xx: false) ⇒ Boolean
True if set, false otherwise.
-
#slice(start = 0, length = -1)) ⇒ Array<String>
The requested slice from <start> with length <length>.
Methods inherited from Struct
#delete, #dump, #exists?, #expire, #expire_at, #initialize, #inspectable_attributes, #persist, #restore, #ttl, #type
Constructor Details
This class inherits a constructor from Redstruct::Struct
Instance Method Details
#delete_if_equals(value) ⇒ Boolean
Returns True if deleted, false otherwise
30 31 32 |
# File 'lib/redstruct/string.rb', line 30 def delete_if_equals(value) coerce_bool(delete_if_equals_script(keys: @key, argv: value)) end |
#delete_if_equals_script(keys = [], argv = []) ⇒ Integer
57 58 59 60 61 62 |
# File 'lib/redstruct/string.rb', line 57 local deleted = false if redis.call("get", KEYS[1]) == ARGV[1] then deleted = redis.call("del", KEYS[1]) end return deleted |
#get ⇒ String?
Returns the string value stored in the database
12 13 14 |
# File 'lib/redstruct/string.rb', line 12 def get return self.connection.get(@key) end |
#getset(value) ⇒ String
Returns The old value before setting it
36 37 38 |
# File 'lib/redstruct/string.rb', line 36 def getset(value) self.connection.getset(@key, value) end |
#length ⇒ Integer
Returns The length of the string
41 42 43 |
# File 'lib/redstruct/string.rb', line 41 def length self.connection.strlen(@key) end |
#set(value, expiry: nil, nx: false, xx: false) ⇒ Boolean
Returns true if set, false otherwise
21 22 23 24 25 26 |
# File 'lib/redstruct/string.rb', line 21 def set(value, expiry: nil, nx: false, xx: false) = { nx: nx, xx: xx } [:ex] = expiry.to_i unless expiry.nil? coerce_bool(self.connection.set(@key, value, )) end |
#slice(start = 0, length = -1)) ⇒ Array<String>
Returns The requested slice from <start> with length <length>
48 49 50 51 |
# File 'lib/redstruct/string.rb', line 48 def slice(start = 0, length = -1) length = start + length if length >= 0 return self.connection.getrange(@key, start, length) end |