Class: Familia::Connection::IndividualCommandProxy

Inherits:
Object
  • Object
show all
Defined in:
lib/familia/connection/individual_command_proxy.rb

Overview

Proxy class that executes Redis commands individually instead of in a transaction

This class intercepts Redis method calls and executes them immediately against the underlying connection, collecting results as if they were part of a transaction. Used as a fallback when transaction mode is unavailable but graceful degradation is preferred over raising an error.

Examples:

Usage in transaction fallback

conn = dbclient
proxy = IndividualCommandProxy.new(conn)

proxy.set('key1', 'value1')  # Executes immediately
proxy.incr('counter')        # Executes immediately
proxy.get('key1')           # Executes immediately

results = proxy.collected_results  # => ["OK", 1, "value1"]

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(redis_connection) ⇒ IndividualCommandProxy

Returns a new instance of IndividualCommandProxy.



27
28
29
30
# File 'lib/familia/connection/individual_command_proxy.rb', line 27

def initialize(redis_connection)
  @connection = redis_connection
  @collected_results = []
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method_name, *args, **kwargs, &block) ⇒ Object

Intercepts Redis method calls and executes them immediately

Parameters:

  • method_name (Symbol)

    The Redis method being called

  • args (Array)

    Arguments passed to the Redis method

  • kwargs (Hash)

    Keyword arguments passed to the Redis method

  • block (Proc)

    Block passed to the Redis method

Returns:

  • The result of the Redis command execution



40
41
42
43
44
45
46
47
48
# File 'lib/familia/connection/individual_command_proxy.rb', line 40

def method_missing(method_name, *args, **kwargs, &block)
  if @connection.respond_to?(method_name)
    result = @connection.public_send(method_name, *args, **kwargs, &block)
    @collected_results << result
    result
  else
    super
  end
end

Instance Attribute Details

#collected_resultsObject (readonly)

Returns the value of attribute collected_results.



25
26
27
# File 'lib/familia/connection/individual_command_proxy.rb', line 25

def collected_results
  @collected_results
end

Instance Method Details

#debug_infoHash

Returns debug information about the proxy state

Returns:

  • (Hash)

    Debug information including connection class and result count



57
58
59
60
61
62
63
# File 'lib/familia/connection/individual_command_proxy.rb', line 57

def debug_info
  {
    connection_class: @connection.class.name,
    results_count: @collected_results.size,
    results: @collected_results.dup
  }
end

#respond_to_missing?(method_name, include_private = false) ⇒ Boolean

Returns:

  • (Boolean)


50
51
52
# File 'lib/familia/connection/individual_command_proxy.rb', line 50

def respond_to_missing?(method_name, include_private = false)
  @connection.respond_to?(method_name, include_private) || super
end