Class: Redstruct::Types::Struct
- Includes:
- Utils::Inspectable
- Defined in:
- lib/redstruct/types/struct.rb
Instance Attribute Summary
Attributes inherited from Base
Instance Method Summary collapse
-
#delete ⇒ Fixnum
0 if nothing was deleted in the DB, 1 if it was.
-
#exists? ⇒ Boolean
Returns true if it exists in redis, false otherwise.
-
#expire(ttl, ms: false) ⇒ Object
Sets the key to expire after ttl seconds.
-
#expire_at(time, ms: false) ⇒ Object
Sets the key to expire at the given timestamp.
-
#inspectable_attributes ⇒ Object
:nocov:.
-
#persist ⇒ Object
Removes the expiry time from a key.
-
#type ⇒ String
The underlying redis type.
Methods included from Utils::Inspectable
Methods inherited from Base
Constructor Details
This class inherits a constructor from Redstruct::Types::Base
Instance Method Details
#delete ⇒ Fixnum
Returns 0 if nothing was deleted in the DB, 1 if it was.
14 15 16 |
# File 'lib/redstruct/types/struct.rb', line 14 def delete self.connection.del(@key) end |
#exists? ⇒ Boolean
Returns true if it exists in redis, false otherwise
9 10 11 |
# File 'lib/redstruct/types/struct.rb', line 9 def exists? return self.connection.exists(@key) end |
#expire(ttl, ms: false) ⇒ Object
Sets the key to expire after ttl seconds
21 22 23 24 25 26 27 |
# File 'lib/redstruct/types/struct.rb', line 21 def expire(ttl, ms: false) if ms self.connection.pexpire(@key, ttl.to_i) else self.connection.expire(@key, ttl.to_i) end end |
#expire_at(time, ms: false) ⇒ Object
Sets the key to expire at the given timestamp.
32 33 34 35 36 37 38 39 |
# File 'lib/redstruct/types/struct.rb', line 32 def expire_at(time, ms: false) if ms time = (time.to_f * 1000) if time.is_a?(Time) self.connection.pexpire_at(@key, time.to_i) else self.connection.expire_at(@key, time.to_i) end end |
#inspectable_attributes ⇒ Object
:nocov:
52 53 54 |
# File 'lib/redstruct/types/struct.rb', line 52 def inspectable_attributes super.merge(key: @key) end |
#persist ⇒ Object
Removes the expiry time from a key
42 43 44 |
# File 'lib/redstruct/types/struct.rb', line 42 def persist self.connection.persist(@key) end |
#type ⇒ String
Returns the underlying redis type.
47 48 49 |
# File 'lib/redstruct/types/struct.rb', line 47 def type self.connection.type(@key) end |