Class: MultiResult
- Inherits:
-
Object
- Object
- MultiResult
- Defined in:
- lib/multi_result.rb
Overview
Represents the result of a Valkey/Redis transaction or pipeline operation.
This class encapsulates the outcome of a Database multi-command operation, providing access to both the command results and derived success status based on the presence of errors in the results.
Success is determined by checking for Exception objects in the results array. When Redis commands fail within a transaction or pipeline, they return exception objects rather than raising them, allowing other commands to continue executing.
Instance Attribute Summary collapse
-
#results ⇒ Array
readonly
The raw return values from the Database commands.
Instance Method Summary collapse
-
#errors ⇒ Array<Exception>
Returns all Exception objects from the results array.
-
#errors? ⇒ Boolean
Checks if any errors occurred during execution.
-
#initialize(results) ⇒ MultiResult
constructor
Creates a new MultiResult instance.
-
#size ⇒ Integer
Returns the number of results in the multi-operation.
-
#successful? ⇒ Boolean
(also: #success?, #areyouhappynow?)
Checks if all commands completed successfully (no exceptions).
-
#to_h ⇒ Hash
Returns a hash representation of the result.
-
#tuple ⇒ Array
(also: #to_a)
Returns a tuple representing the result of the operation.
Constructor Details
#initialize(results) ⇒ MultiResult
Creates a new MultiResult instance.
49 50 51 |
# File 'lib/multi_result.rb', line 49 def initialize(results) @results = results end |
Instance Attribute Details
#results ⇒ Array (readonly)
Returns The raw return values from the Database commands.
41 42 43 |
# File 'lib/multi_result.rb', line 41 def results @results end |
Instance Method Details
#errors ⇒ Array<Exception>
Returns all Exception objects from the results array.
This method is memoized for performance when called multiple times on the same MultiResult instance.
59 60 61 |
# File 'lib/multi_result.rb', line 59 def errors @errors ||= results.select { |ret| ret.is_a?(Exception) } end |
#errors? ⇒ Boolean
Checks if any errors occurred during execution.
66 67 68 |
# File 'lib/multi_result.rb', line 66 def errors? !errors.empty? end |
#size ⇒ Integer
Returns the number of results in the multi-operation.
99 100 101 |
# File 'lib/multi_result.rb', line 99 def size results.size end |
#successful? ⇒ Boolean Also known as: success?, areyouhappynow?
Checks if all commands completed successfully (no exceptions).
This is the primary method for determining if a multi-command operation completed without errors.
76 77 78 |
# File 'lib/multi_result.rb', line 76 def successful? errors.empty? end |
#to_h ⇒ Hash
Returns a hash representation of the result.
106 107 108 |
# File 'lib/multi_result.rb', line 106 def to_h { success: successful?, results: results } end |
#tuple ⇒ Array Also known as: to_a
Returns a tuple representing the result of the operation.
91 92 93 |
# File 'lib/multi_result.rb', line 91 def tuple [successful?, results] end |