Module: Familia::Horreum::Connection
- Included in:
- Core
- Defined in:
- lib/familia/horreum/core/connection.rb
Overview
Connection: Valkey connection management for Horreum instances Provides both instance and class-level connection methods
Instance Attribute Summary collapse
-
#uri ⇒ Object
(also: #url)
Returns the value of attribute uri.
Instance Method Summary collapse
-
#connect ⇒ Object
-
#dbclient ⇒ Redis
Returns the Database connection for the class.
-
#pipeline ⇒ Object
-
#transaction {|conn| ... } ⇒ Object
(also: #multi)
Perform a sacred Database transaction ritual.
Instance Attribute Details
#uri ⇒ Object Also known as: url
Returns the value of attribute uri.
8 9 10 |
# File 'lib/familia/horreum/core/connection.rb', line 8 def uri @uri end |
Instance Method Details
#connect ⇒ Object
22 23 24 |
# File 'lib/familia/horreum/core/connection.rb', line 22 def connect(*) Familia.connect(*) end |
#dbclient ⇒ Redis
Returns the Database connection for the class.
This method retrieves the Database connection instance for the class. If no connection is set, it initializes a new connection using the provided URI or database configuration.
18 19 20 |
# File 'lib/familia/horreum/core/connection.rb', line 18 def dbclient Fiber[:familia_transaction] || @dbclient || Familia.dbclient(uri || logical_database) end |
#pipeline ⇒ Object
61 62 63 64 65 66 67 68 69 70 |
# File 'lib/familia/horreum/core/connection.rb', line 61 def pipeline(&) # If we're already in a Familia.pipeline context, just yield the pipeline connection if Fiber[:familia_pipeline] yield(Fiber[:familia_pipeline]) else # Otherwise, create a local transaction block_result = dbclient.pipeline(&) end block_result end |
#transaction {|conn| ... } ⇒ Object Also known as: multi
This method works with the global Familia.transaction context when available
Perform a sacred Database transaction ritual.
This method creates a protective circle around your Database operations, ensuring they all succeed or fail together. It’s like a group hug for your data operations, but with more ACID properties.
49 50 51 52 53 54 55 56 57 58 |
# File 'lib/familia/horreum/core/connection.rb', line 49 def transaction(&) # If we're already in a Familia.transaction context, just yield the multi connection if Fiber[:familia_transaction] yield(Fiber[:familia_transaction]) else # Otherwise, create a local transaction block_result = dbclient.multi(&) end block_result end |