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

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.

Parameters:

  • dbclient_proc (Proc)

    Lambda that returns the Redis connection

  • block (Proc)

    Block containing Redis commands to execute

Returns:

  • (MultiResult)

    Result object with collected command results



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

Parameters:

  • operation_type (Symbol)

    Either :transaction or :pipeline

Returns:

  • (Symbol)

    The configured mode (:strict, :warn, :permissive)



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

Parameters:

  • operation_type (Symbol)

    Either :transaction or :pipeline

  • dbclient_proc (Proc)

    Lambda that returns the Redis connection

  • handler_class (Class)

    The connection handler that blocked operation

  • block (Proc)

    Block containing Redis commands to execute

Returns:

  • (MultiResult)

    Result from individual command execution or raises error



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

Parameters:

  • operation_type (Symbol)

    Either :transaction or :pipeline

  • handler_class (Class)

    The connection handler class



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)
  message = "#{operation_type.capitalize} unavailable with #{handler_class.name}. Using individual commands."

  if Familia.respond_to?(:logger) && Familia.logger
    Familia.logger.warn message
  else
    warn message
  end
end