Module: Familia::Connection::OperationCore
- Defined in:
- lib/familia/connection/operation_core.rb
Overview
Shared logic for transaction and pipeline operation fallback handling
Provides configurable fallback behavior when connection handlers don't support specific operation modes (transaction/pipeline).
Class Method Summary collapse
-
.execute_individual_commands(dbclient_proc, &block) ⇒ MultiResult
Executes commands individually using a proxy that collects results.
-
.get_operation_mode(operation_type) ⇒ Symbol
Gets the configured mode for the operation type.
-
.handle_fallback(operation_type, dbclient_proc, handler_class, &block) ⇒ MultiResult
Handles operation fallback based on configured mode.
-
.log_fallback_warning(operation_type, handler_class) ⇒ Object
Logs fallback warning message.
Class Method Details
.execute_individual_commands(dbclient_proc, &block) ⇒ MultiResult
Executes commands individually using a proxy that collects results
Creates an IndividualCommandProxy that executes each Redis command immediately instead of queuing them in a transaction or pipeline. Results are collected to maintain the same interface as normal operations.
81 82 83 84 85 86 87 88 89 90 91 |
# File 'lib/familia/connection/operation_core.rb', line 81 def self.execute_individual_commands(dbclient_proc, &block) conn = dbclient_proc.call proxy = IndividualCommandProxy.new(conn) # Execute the block with the proxy block.call(proxy) # Return MultiResult format for consistency results = proxy.collected_results MultiResult.new(results) end |
.get_operation_mode(operation_type) ⇒ Symbol
Gets the configured mode for the operation type
45 46 47 48 49 50 51 52 53 54 |
# File 'lib/familia/connection/operation_core.rb', line 45 def self.get_operation_mode(operation_type) case operation_type when :transaction Familia.transaction_mode when :pipeline Familia.pipelined_mode else :strict end end |
.handle_fallback(operation_type, dbclient_proc, handler_class, &block) ⇒ MultiResult
Handles operation fallback based on configured mode
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/familia/connection/operation_core.rb', line 21 def self.handle_fallback(operation_type, dbclient_proc, handler_class, &block) mode = get_operation_mode(operation_type) case mode when :strict raise Familia::OperationModeError, "Cannot start #{operation_type} with #{handler_class.name} connection. Use connection pools." when :warn log_fallback_warning(operation_type, handler_class) execute_individual_commands(dbclient_proc, &block) when :permissive execute_individual_commands(dbclient_proc, &block) else # Default to strict mode if invalid setting raise Familia::OperationModeError, "Cannot start #{operation_type} with #{handler_class.name} connection. Use connection pools." end end |
.log_fallback_warning(operation_type, handler_class) ⇒ Object
Logs fallback warning message
61 62 63 64 65 66 67 68 69 |
# File 'lib/familia/connection/operation_core.rb', line 61 def self.log_fallback_warning(operation_type, handler_class) = "#{operation_type.capitalize} unavailable with #{handler_class.name}. Using individual commands." if Familia.respond_to?(:logger) && Familia.logger Familia.logger.warn else warn end end |