module Oxblood::Commands::Transactions
Public Instance Methods
Discard all commands issued after MULTI @see redis.io/commands/discard
@return [String] 'OK' @return [RError] if called without transaction started
# File lib/oxblood/commands/transactions.rb, line 51 def discard run(:DISCARD).tap { connection.transaction_mode = false } end
Execute all commands issued after MULTI @see redis.io/commands/exec
@return [Array] each element being the reply to each of the commands
in the atomic transaction
@return [nil] when WATCH was used and execution was aborted
# File lib/oxblood/commands/transactions.rb, line 42 def exec run(:EXEC).tap { connection.transaction_mode = false } end
Mark the start of a transaction block @see redis.io/commands/multi
@example {#exec} will be executed automatically at the end of a block.
session.multi do session.ping session.ping end # => ['PONG', 'PONG']
@example Blockless variant.
session.multi session.incr(:counter0) session.incr(:counter1) session.exec
@return [String] 'OK' @return [RError] if multi called inside transaction
# File lib/oxblood/commands/transactions.rb, line 23 def multi response = run(:MULTI).tap do |resp| connection.transaction_mode = true if resp == 'OK' end if block_given? yield exec else response end end
Forget about all watched keys @see redis.io/commands/unwatch
@return [String] 'OK'
# File lib/oxblood/commands/transactions.rb, line 74 def unwatch run(:UNWATCH) end
Watch the given keys to determine execution of the MULTI/EXEC block @see redis.io/commands/watch
@example
session.set(:cnt, 0) session.watch(:cnt) value = session.get(:cnt).to_i value += 1 session.multi { session.set(:cnt, value) } # => `['OK']` or `nil` if `cnt` was modified while was watched
@return [String] 'OK'
# File lib/oxblood/commands/transactions.rb, line 66 def watch(*keys) run(:WATCH, keys) end