Module: Redis::Commands::Transactions
- Included in:
- Redis::Commands
- Defined in:
- lib/redis/commands/transactions.rb
Instance Method Summary collapse
-
#discard ⇒ String
Discard all commands issued after MULTI.
-
#exec ⇒ nil, Array<...>
Execute all commands issued after MULTI.
-
#multi {|multi| ... } ⇒ String, Array<...>
Mark the start of a transaction block.
-
#unwatch ⇒ String
Forget about all watched keys.
-
#watch(*keys) ⇒ Object, String
Watch the given keys to determine execution of the MULTI/EXEC block.
Instance Method Details
#discard ⇒ String
Discard all commands issued after MULTI.
Only call this method when ‘#multi` was called without a block.
134 135 136 |
# File 'lib/redis/commands/transactions.rb', line 134 def discard send_command([:discard]) end |
#exec ⇒ nil, Array<...>
Execute all commands issued after MULTI.
Only call this method when ‘#multi` was called without a block.
122 123 124 |
# File 'lib/redis/commands/transactions.rb', line 122 def exec send_command([:exec]) end |
#multi {|multi| ... } ⇒ String, Array<...>
Mark the start of a transaction block.
Passing a block is optional.
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/redis/commands/transactions.rb', line 36 def multi(&block) # :nodoc: if block_given? if block&.arity == 0 Pipeline.deprecation_warning("multi", Kernel.caller_locations(1, 5)) end synchronize do |prior_client| pipeline = Pipeline::Multi.new(prior_client) pipelined_connection = PipelinedConnection.new(pipeline) yield pipelined_connection prior_client.call_pipeline(pipeline) end else send_command([:multi]) end end |
#unwatch ⇒ String
Forget about all watched keys.
108 109 110 |
# File 'lib/redis/commands/transactions.rb', line 108 def unwatch send_command([:unwatch]) end |
#watch(*keys) ⇒ Object, String
Watch the given keys to determine execution of the MULTI/EXEC block.
Using a block is optional, but is necessary for thread-safety.
An ‘#unwatch` is automatically issued if an exception is raised within the block that is a subclass of StandardError and is not a ConnectionError.
83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 |
# File 'lib/redis/commands/transactions.rb', line 83 def watch(*keys) synchronize do |client| res = client.call([:watch, *keys]) if block_given? begin yield(self) rescue ConnectionError raise rescue StandardError unwatch raise end else res end end end |