Class: Familia::Horreum::MultiResult

Inherits:
Object
  • Object
show all
Defined in:
lib/familia/horreum/serialization.rb

Overview

Represents the result of a multiple Redis commands.

This class encapsulates the outcome of a Redis “transaction”, providing both a success indicator and the raw results from the Redis commands executed during the transaction (“MULTI”).

Examples:

Creating a MultiResult

result = MultiResult.new(true, ["OK", "OK"])

Checking the success of a commit

if result.successful?
  puts "All commands succeeded"
else
  puts "Some commands failed"
end

Accessing raw results

result.results.each_with_index do |value, index|
  puts "Command #{index + 1} returned: #{value}"
end

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(success, results) ⇒ MultiResult

Creates a new MultiResult instance.

Parameters:

  • success (Boolean)

    Whether all commands succeeded

  • results (Array<String>)

    The raw results from Redis commands



416
417
418
419
# File 'lib/familia/horreum/serialization.rb', line 416

def initialize(success, results)
  @success = success
  @results = results
end

Instance Attribute Details

#resultsArray<String> (readonly)

Returns The raw return values from the Redis commands.

Returns:

  • (Array<String>)

    The raw return values from the Redis commands



404
405
406
# File 'lib/familia/horreum/serialization.rb', line 404

def results
  @results
end

#successBoolean (readonly)

Returns true if all commands in the transaction succeeded, false otherwise.

Returns:

  • (Boolean)

    true if all commands in the transaction succeeded, false otherwise



404
405
406
# File 'lib/familia/horreum/serialization.rb', line 404

def success
  @success
end

Instance Method Details

#successful?Boolean Also known as: success?

Convenient method to check if the commit was successful.

Returns:

  • (Boolean)

    true if all commands succeeded, false otherwise



437
438
439
# File 'lib/familia/horreum/serialization.rb', line 437

def successful?
  @success
end

#tupleArray

Returns a tuple representing the result of the transaction.

Examples:

[true, ["OK", true, 1]]

Returns:

  • (Array)

    A tuple containing the success status and the raw results. The success status is a boolean indicating if all commands succeeded. The raw results is an array of return values from the Redis commands.



430
431
432
# File 'lib/familia/horreum/serialization.rb', line 430

def tuple
  [successful?, results]
end