Class: Familia::Validation::CommandRecorder::RecordedCommand

Inherits:
Object
  • Object
show all
Defined in:
lib/familia/validation/command_recorder.rb

Overview

Represents a single Redis command with full context

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(command:, args:, result:, timestamp:, duration_us:, context: {}) ⇒ RecordedCommand

Returns a new instance of RecordedCommand.



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

def initialize(command:, args:, result:, timestamp:, duration_us:, context: {})
  @command = command.to_s.upcase
  @args = args.dup.freeze
  @result = result
  @timestamp = timestamp
  @duration_us = duration_us
  @context = context.dup.freeze
  @command_type = determine_command_type
end

Instance Attribute Details

#argsObject (readonly)

Returns the value of attribute args.



38
39
40
# File 'lib/familia/validation/command_recorder.rb', line 38

def args
  @args
end

#commandObject (readonly)

Returns the value of attribute command.



38
39
40
# File 'lib/familia/validation/command_recorder.rb', line 38

def command
  @command
end

#command_typeObject (readonly)

Returns the value of attribute command_type.



38
39
40
# File 'lib/familia/validation/command_recorder.rb', line 38

def command_type
  @command_type
end

#contextObject (readonly)

Returns the value of attribute context.



38
39
40
# File 'lib/familia/validation/command_recorder.rb', line 38

def context
  @context
end

#duration_usObject (readonly)

Returns the value of attribute duration_us.



38
39
40
# File 'lib/familia/validation/command_recorder.rb', line 38

def duration_us
  @duration_us
end

#resultObject (readonly)

Returns the value of attribute result.



38
39
40
# File 'lib/familia/validation/command_recorder.rb', line 38

def result
  @result
end

#timestampObject (readonly)

Returns the value of attribute timestamp.



38
39
40
# File 'lib/familia/validation/command_recorder.rb', line 38

def timestamp
  @timestamp
end

Instance Method Details

#atomic_command?Boolean

Returns:

  • (Boolean)


75
76
77
# File 'lib/familia/validation/command_recorder.rb', line 75

def atomic_command?
  @context[:transaction] == true
end

#pipeline_command?Boolean

Returns:

  • (Boolean)


71
72
73
# File 'lib/familia/validation/command_recorder.rb', line 71

def pipeline_command?
  @context[:pipeline] == true
end

#to_hObject



55
56
57
58
59
60
61
62
63
64
65
# File 'lib/familia/validation/command_recorder.rb', line 55

def to_h
  {
    command: @command,
    args: @args,
    result: @result,
    timestamp: @timestamp,
    duration_us: @duration_us,
    context: @context,
    command_type: @command_type
  }
end

#to_sObject



50
51
52
53
# File 'lib/familia/validation/command_recorder.rb', line 50

def to_s
  args_str = @args.map(&:inspect).join(', ')
  "#{@command}(#{args_str})"
end

#transaction_command?Boolean

Returns:

  • (Boolean)


67
68
69
# File 'lib/familia/validation/command_recorder.rb', line 67

def transaction_command?
  %w[MULTI EXEC DISCARD].include?(@command)
end