Module: Redstruct::Factory::Creation
- Included in:
- Redstruct::Factory
- Defined in:
- lib/redstruct/factory/creation.rb
Overview
Module to hold all the factory creation methods.
Instance Method Summary collapse
-
#counter(key, **options) ⇒ Redstruct::Types::Counter
Builds a Redis counter struct from the key.
-
#factory(namespace) ⇒ Factory
Returns a factory with an isolated namespace.
-
#hash(key, **options) ⇒ Redstruct::Types::Hash
Builds a Redis hash struct from the key.
-
#list(key, **options) ⇒ Redstruct::Types::List
Builds a Redis list struct from the key.
-
#lock(key, **options) ⇒ Redstruct::Hls::Lock
Builds a Redis backed lock from the key.
-
#queue(key) ⇒ Redstruct::Hls::Queue
Builds a Redis backed queue from the key.
-
#script(id, script) ⇒ Object
Caveat: if the script with the given ID exists in the cache, we don’t bother updating it.
-
#set(key, **options) ⇒ Redstruct::Types::Set
Builds a Redis set struct from the key.
-
#sorted_set(key, **options) ⇒ Redstruct::Types::SortedSet
Builds a Redis sorted set (zset) struct from the key.
-
#string(key, **options) ⇒ Redstruct::Types::String
Builds a Redis string struct from the key.
-
#struct(key, **options) ⇒ Redstruct::Types::Struct
Builds a struct with the given key (namespaced) and sharing the factory connection Building a struct is only really useful if you plan on making only basic operations, such as delete, expire, etc.
Instance Method Details
#counter(key, **options) ⇒ Redstruct::Types::Counter
Builds a Redis counter struct from the key
60 61 62 |
# File 'lib/redstruct/factory/creation.rb', line 60 def counter(key, **) return create(Redstruct::Types::Counter, key, **) end |
#factory(namespace) ⇒ Factory
Returns a factory with an isolated namespace.
85 86 87 |
# File 'lib/redstruct/factory/creation.rb', line 85 def factory(namespace) return self.class.new(connection: @connection, namespace: isolate(namespace)) end |
#hash(key, **options) ⇒ Redstruct::Types::Hash
Builds a Redis hash struct from the key
46 47 48 |
# File 'lib/redstruct/factory/creation.rb', line 46 def hash(key, **) return create(Redstruct::Types::Hash, key, **) end |
#list(key, **options) ⇒ Redstruct::Types::List
Builds a Redis list struct from the key
25 26 27 |
# File 'lib/redstruct/factory/creation.rb', line 25 def list(key, **) return create(Redstruct::Types::List, key, **) end |
#lock(key, **options) ⇒ Redstruct::Hls::Lock
Builds a Redis backed lock from the key
53 54 55 |
# File 'lib/redstruct/factory/creation.rb', line 53 def lock(key, **) return create(Redstruct::Hls::Lock, key, **) end |
#queue(key) ⇒ Redstruct::Hls::Queue
Builds a Redis backed queue from the key
67 68 69 |
# File 'lib/redstruct/factory/creation.rb', line 67 def queue(key) return create(Redstruct::Hls::Queue, key) end |
#script(id, script) ⇒ Object
The script cache is actually based on the database you will connect to. Therefore, it might be smarter to move it to the connection used?
Caveat: if the script with the given ID exists in the cache, we don’t bother updating it. So if the script actually changed since the first call, the one sent during the first call will
74 75 76 77 78 79 |
# File 'lib/redstruct/factory/creation.rb', line 74 def script(id, script) return @script_cache.synchronize do @script_cache[id] = Redstruct::Types::Script.new(key: id, script: script, factory: self) if @script_cache[id].nil? @script_cache[id] end end |
#set(key, **options) ⇒ Redstruct::Types::Set
Builds a Redis set struct from the key
32 33 34 |
# File 'lib/redstruct/factory/creation.rb', line 32 def set(key, **) return create(Redstruct::Types::Set, key, **) end |
#sorted_set(key, **options) ⇒ Redstruct::Types::SortedSet
Builds a Redis sorted set (zset) struct from the key
39 40 41 |
# File 'lib/redstruct/factory/creation.rb', line 39 def sorted_set(key, **) return create(Redstruct::Types::SortedSet, key, **) end |
#string(key, **options) ⇒ Redstruct::Types::String
Builds a Redis string struct from the key
18 19 20 |
# File 'lib/redstruct/factory/creation.rb', line 18 def string(key, **) return create(Redstruct::Types::String, key, **) end |
#struct(key, **options) ⇒ Redstruct::Types::Struct
Builds a struct with the given key (namespaced) and sharing the factory connection Building a struct is only really useful if you plan on making only basic operations, such as delete, expire, etc. It is however recommended to always build your objects in the same way, e.g. if it’s a lock, use Factory#lock
11 12 13 |
# File 'lib/redstruct/factory/creation.rb', line 11 def struct(key, **) return create(Redstruct::Types::Struct, key, **) end |