Skip to content

Commit 4f9bc0e

Browse files
committed
Update #multi documentation
1 parent 7587668 commit 4f9bc0e

File tree

3 files changed

+7
-70
lines changed

3 files changed

+7
-70
lines changed

lib/redis.rb

Lines changed: 7 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -2451,46 +2451,28 @@ def pipelined
24512451

24522452
# Mark the start of a transaction block.
24532453
#
2454-
# Passing a block is optional.
2455-
#
2456-
# @example With a block
2454+
# @example
24572455
# redis.multi do |multi|
24582456
# multi.set("key", "value")
24592457
# multi.incr("counter")
24602458
# end # => ["OK", 6]
24612459
#
2462-
# @example Without a block
2463-
# redis.multi
2464-
# # => "OK"
2465-
# redis.set("key", "value")
2466-
# # => "QUEUED"
2467-
# redis.incr("counter")
2468-
# # => "QUEUED"
2469-
# redis.exec
2470-
# # => ["OK", 6]
2471-
#
24722460
# @yield [multi] the commands that are called inside this block are cached
24732461
# and written to the server upon returning from it
24742462
# @yieldparam [Redis] multi `self`
24752463
#
24762464
# @return [String, Array<...>]
2477-
# - when a block is not given, `OK`
2478-
# - when a block is given, an array with replies
24792465
#
24802466
# @see #watch
24812467
# @see #unwatch
24822468
def multi
24832469
synchronize do |prior_client|
2484-
if !block_given?
2485-
prior_client.call([:multi])
2486-
else
2487-
begin
2488-
@client = Pipeline::Multi.new(prior_client)
2489-
yield(self)
2490-
prior_client.call_pipeline(@client)
2491-
ensure
2492-
@client = prior_client
2493-
end
2470+
begin
2471+
@client = Pipeline::Multi.new(prior_client)
2472+
yield(self)
2473+
prior_client.call_pipeline(@client)
2474+
ensure
2475+
@client = prior_client
24942476
end
24952477
end
24962478
end

test/distributed_transactions_test.rb

Lines changed: 0 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -5,22 +5,6 @@
55
class TestDistributedTransactions < Minitest::Test
66
include Helper::Distributed
77

8-
def test_multi_discard
9-
r.set("foo", 1)
10-
11-
r.watch("foo")
12-
r.multi
13-
r.set("foo", 2)
14-
15-
assert_raises Redis::Distributed::CannotDistribute do
16-
r.set("bar", 1)
17-
end
18-
19-
r.discard
20-
21-
assert_equal('1', r.get("foo"))
22-
end
23-
248
def test_multi_discard_without_watch
259
@foo = nil
2610

@@ -83,22 +67,4 @@ def test_watch_multi_with_block
8367
assert_equal [3, 6, 10], result
8468
end
8569
end
86-
87-
def test_watch_multi_exec_without_block
88-
r.set("{qux}baz", 1)
89-
90-
assert_equal "OK", r.watch("{qux}foo", "{qux}bar", "{qux}baz")
91-
assert_equal '1', r.get("{qux}baz")
92-
93-
assert_raises Redis::Distributed::CannotDistribute do
94-
r.get("{foo}baz")
95-
end
96-
97-
assert_equal "OK", r.multi
98-
assert_equal "QUEUED", r.incrby("{qux}baz", 1)
99-
assert_equal "QUEUED", r.incrby("{qux}baz", 1)
100-
assert_equal [2, 3], r.exec
101-
102-
assert_equal "OK", r.set("{other}baz", 1)
103-
end
10470
end

test/transactions_test.rb

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,6 @@
55
class TestTransactions < Minitest::Test
66
include Helper::Client
77

8-
def test_multi_discard
9-
r.multi
10-
11-
assert_equal "QUEUED", r.set("foo", "1")
12-
assert_equal "QUEUED", r.get("foo")
13-
14-
r.discard
15-
16-
assert_nil r.get("foo")
17-
end
18-
198
def test_multi_exec_with_a_block
209
r.multi do |multi|
2110
multi.set "foo", "s1"

0 commit comments

Comments
 (0)