class MockRedis::TransactionWrapper
Public Class Methods
new(db)
click to toggle source
# File lib/mock_redis/transaction_wrapper.rb, line 11 def initialize(db) @db = db @transaction_futures = [] @multi_stack = [] @multi_block_given = false end
Public Instance Methods
discard()
click to toggle source
# File lib/mock_redis/transaction_wrapper.rb, line 41 def discard unless in_multi? raise Redis::CommandError, 'ERR DISCARD without MULTI' end pop_multi @transaction_futures = [] 'OK' end
exec()
click to toggle source
# File lib/mock_redis/transaction_wrapper.rb, line 51 def exec unless in_multi? raise Redis::CommandError, 'ERR EXEC without MULTI' end pop_multi return if in_multi? @multi_block_given = false responses = @transaction_futures.map do |future| result = send(*future.command) future.store_result(result) future.value rescue StandardError => e e end @transaction_futures = [] responses end
in_multi?()
click to toggle source
# File lib/mock_redis/transaction_wrapper.rb, line 71 def in_multi? @multi_stack.any? end
initialize_copy(source)
click to toggle source
Calls superclass method
# File lib/mock_redis/transaction_wrapper.rb, line 34 def initialize_copy(source) super @db = @db.clone @transaction_futures = @transaction_futures.clone @multi_stack = @multi_stack.clone end
method_missing(method, *args, &block)
click to toggle source
# File lib/mock_redis/transaction_wrapper.rb, line 18 def method_missing(method, *args, &block) if in_multi? future = MockRedis::Future.new([method, *args], block) @transaction_futures << future if @multi_block_given future else 'QUEUED' end else @db.expire_keys @db.send(method, *args, &block) end end
multi() { |self| ... }
click to toggle source
# File lib/mock_redis/transaction_wrapper.rb, line 83 def multi if block_given? push_multi @multi_block_given = true begin yield(self) exec rescue StandardError => e discard raise e end else raise Redis::CommandError, 'ERR MULTI calls can not be nested' if in_multi? push_multi 'OK' end end
pipelined() { |self| ... }
click to toggle source
# File lib/mock_redis/transaction_wrapper.rb, line 101 def pipelined yield(self) if block_given? end
pop_multi()
click to toggle source
# File lib/mock_redis/transaction_wrapper.rb, line 79 def pop_multi @multi_stack.pop end
push_multi()
click to toggle source
# File lib/mock_redis/transaction_wrapper.rb, line 75 def push_multi @multi_stack.push(@multi_stack.size + 1) end
respond_to?(method, include_private = false)
click to toggle source
Calls superclass method
# File lib/mock_redis/transaction_wrapper.rb, line 7 def respond_to?(method, include_private = false) super || @db.respond_to?(method) end
unwatch()
click to toggle source
# File lib/mock_redis/transaction_wrapper.rb, line 105 def unwatch 'OK' end
watch(*_) { |self| ... }
click to toggle source
# File lib/mock_redis/transaction_wrapper.rb, line 109 def watch(*_) if block_given? yield self else 'OK' end end