Class: Familia::Horreum::MultiResult

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

Overview

The magical MultiResult, keeper of Redis’s deepest secrets!

This quirky little class wraps up the outcome of a Redis “transaction” (or as I like to call it, a “Redis dance party”) with a bow made of pure Ruby delight. It knows if your commands were successful and keeps the results safe in its pocket dimension.

Examples:

Summoning a MultiResult from the void

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

Divining the success of your Redis ritual

if result.successful?
  puts "Huzzah! The Redis spirits smile upon you!"
else
  puts "Alas! The Redis gremlins have conspired against us!"
end

Peering into the raw essence of results

result.results.each_with_index do |value, index|
  puts "Command #{index + 1} whispered back: #{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



547
548
549
550
# File 'lib/familia/horreum/serialization.rb', line 547

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



535
536
537
# File 'lib/familia/horreum/serialization.rb', line 535

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



535
536
537
# File 'lib/familia/horreum/serialization.rb', line 535

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



573
574
575
# File 'lib/familia/horreum/serialization.rb', line 573

def successful?
  @success
end

#to_hObject



566
567
568
# File 'lib/familia/horreum/serialization.rb', line 566

def to_h
  { success: successful?, results: results }
end

#tupleArray Also known as: to_a

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.



561
562
563
# File 'lib/familia/horreum/serialization.rb', line 561

def tuple
  [successful?, results]
end