Module: Familia::Horreum::Connection
- Included in:
- Familia::Horreum
- Defined in:
- lib/familia/horreum/connection.rb
Overview
Familia::Horreum::Connection
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.
9 10 11 |
# File 'lib/familia/horreum/connection.rb', line 9 def uri @uri end |
Instance Method Details
#connect ⇒ Object
23 24 25 |
# File 'lib/familia/horreum/connection.rb', line 23 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.
19 20 21 |
# File 'lib/familia/horreum/connection.rb', line 19 def dbclient Fiber[:familia_transaction] || @dbclient || Familia.dbclient(uri || logical_database) end |
#pipeline ⇒ Object
64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/familia/horreum/connection.rb', line 64 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 do |conn| yield(conn) end end block_result end |
#transaction {|conn| ... } ⇒ Object Also known as: multi
Note:
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.
50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/familia/horreum/connection.rb', line 50 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 do |conn| yield(conn) end end block_result end |