Wraith::HashStore(K, V)
Inherits Atomically / Struct / Value / Object
Constructors
Instance methods
Sets the value for the key. Keys set with the []= syntax do not support
an expiration.
Return value: The value of the key.
Example:
hash_store["k"] = 1
Returns the value of the key. If the key does not exist or has expired, nil is returned.
Return value: The value for the key.
Example:
hash_store.set("a", 1)
hash_store.get("a") => 1
hash_store.get("b") => nil
Returns the value of the key along with the remaining TTL, in ms, as a tuple. If the key does not have a TTL, the TTL portion of the tuple will be nil. If the key does not exist or has expired, nil is returned.
Return value: A tuple containing the value and expiration in ms.
Example:
hash_store.set("a", 1, ttl: 10.milliseconds)
hash_store.set("b", 2)
hash_store.get_with_expiration("a") => {1, 10}
hash_store.get_with_expiration("b") => {2, nil}
hash_store.get_with_expiration("c") => nil
Increments the value of a specified key. The class of the value needs
to either support + or have that method defined. If a magnitude is not
is not specified, it defaults to 1. If a key does not exist, the magnitude
will be set as the key's value and the key will not have an expiration.
Return value: The incremented value.
Examples:
hash_store.set("foo", 3) => 3
hash_store.inc("foo") => 4
hash_store.inc("foo", 3) => 7
hash_store.inc("foo", -2) => 5
hash_store.inc("bar") => 1
Sets the value for the key. Accepts a (time-to-live) ttl Time::Span
value. Keys that have exceeded their TTL will be purged.
Return value: The value of the key.
Example:
hash_store.set("key", 1)
hash_store.set(key: "key", val: 1)
hash_store.set("key", 1, ttl: 500.milliseconds)
hash_store.set(key: "key", val: 1, ttl: 2.days)
Returns the remaining time to live of a key. If a ttl is set
it will update the TTL for the key to the specified value.
Return value: Integer: TTL in seconds, or Nil to indicate the key does not exist.
Examples:
hash_store.ttl("foo", 3) => 3
hash_store.ttl("bar", 0) => 0
hash_store.ttl("bar") # => nil
Returns an array of all values in a hash. If a key is expired, its value will not be returned.