Class: Redstruct::Factory
- Inherits:
-
Object
- Object
- Redstruct::Factory
- Extended by:
- Deserialization
- Includes:
- Creation, Utils::Inspectable
- Defined in:
- lib/redstruct/factory.rb,
lib/redstruct/factory/creation.rb,
lib/redstruct/factory/deserialization.rb
Overview
Main interface of the gem; this class should be used to build all Redstruct objects, even when deserializing them.
Defined Under Namespace
Modules: Creation, Deserialization
Instance Attribute Summary collapse
-
#connection ⇒ Connection
readonly
The connection proxy to use when executing commands.
Instance Method Summary collapse
- #initialize(connection: nil, pool: nil, namespace: nil) ⇒ Factory constructor
-
#inspectable_attributes ⇒ Object
Helper method for serialization.
-
#isolate(key) ⇒ String
Returns a namespaced version of the key (unless already namespaced).
Methods included from Utils::Inspectable
Methods included from Creation
#counter, #factory, #hash, #list, #lock, #queue, #script, #set, #sorted_set, #string, #struct
Constructor Details
#initialize(connection: nil, pool: nil, namespace: nil) ⇒ Factory
15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/redstruct/factory.rb', line 15 def initialize(connection: nil, pool: nil, namespace: nil) namespace ||= Redstruct.config.namespace if connection.nil? pool ||= Redstruct.config.connection_pool raise(Redstruct::Error, 'A connection pool is required to create a factory, but none was given') if pool.nil? connection = Redstruct::Connection.new(pool) end @connection = connection @namespace = namespace @script_cache = {}.tap { |hash| hash.extend(MonitorMixin) } end |
Instance Attribute Details
#connection ⇒ Connection (readonly)
Returns The connection proxy to use when executing commands. Shared by all factory produced objects.
9 10 11 |
# File 'lib/redstruct/factory.rb', line 9 def connection @connection end |
Instance Method Details
#inspectable_attributes ⇒ Object
Helper method for serialization
39 40 41 |
# File 'lib/redstruct/factory.rb', line 39 def inspectable_attributes return { namespace: @namespace, script_cache: @script_cache.keys } end |
#isolate(key) ⇒ String
Returns a namespaced version of the key (unless already namespaced)
32 33 34 |
# File 'lib/redstruct/factory.rb', line 32 def isolate(key) return @namespace.nil? || key.start_with?(@namespace) ? key : "#{@namespace}:#{key}" end |