Skip to content

Commit c543140

Browse files
author
Joao Fernandes
committed
Making the code valid Ruby 1.8.x
Issue #545
1 parent 2bc8f6b commit c543140

File tree

2 files changed

+25
-25
lines changed

2 files changed

+25
-25
lines changed

lib/redis.rb

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1429,9 +1429,11 @@ def zcard(key)
14291429
# pairs that were **added** to the sorted set.
14301430
# - `Float` when option :incr is specified, holding the score of the member
14311431
# after incrementing it.
1432-
def zadd(key, *args, options)
1432+
def zadd(key, *args) #, options
14331433
zadd_options = []
1434-
if options.is_a?(Hash)
1434+
if args.last.is_a?(Hash)
1435+
options = args.pop
1436+
14351437
nx = options[:nx]
14361438
zadd_options << "NX" if nx
14371439

@@ -1445,8 +1447,6 @@ def zadd(key, *args, options)
14451447

14461448
incr = options[:incr]
14471449
zadd_options << "INCR" if incr
1448-
else
1449-
args << options
14501450
end
14511451

14521452
synchronize do |client|
@@ -1456,7 +1456,7 @@ def zadd(key, *args, options)
14561456
client.call([:zadd, key] + zadd_options + args[0])
14571457
elsif args.size == 2
14581458
# Single pair: return float if INCR, boolean if !INCR
1459-
client.call([:zadd, key, *zadd_options, args[0], args[1]], &(incr ? _floatify : _boolify))
1459+
client.call([:zadd, key] + zadd_options + [args[0], args[1]], &(incr ? _floatify : _boolify))
14601460
else
14611461
raise ArgumentError, "wrong number of arguments"
14621462
end

test/lint/sorted_sets.rb

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -14,44 +14,44 @@ def test_zadd
1414
target_version "3.0.2" do
1515
# XX option
1616
assert_equal 0, r.zcard("foo")
17-
assert_equal false, r.zadd("foo", 1, "s1", xx: true)
17+
assert_equal false, r.zadd("foo", 1, "s1", :xx => true)
1818
r.zadd("foo", 1, "s1")
19-
assert_equal false, r.zadd("foo", 2, "s1", xx: true)
19+
assert_equal false, r.zadd("foo", 2, "s1", :xx => true)
2020
assert_equal 2, r.zscore("foo", "s1")
2121
r.del "foo"
2222

2323
# NX option
2424
assert_equal 0, r.zcard("foo")
25-
assert_equal true, r.zadd("foo", 1, "s1", nx: true)
26-
assert_equal false, r.zadd("foo", 2, "s1", nx: true)
25+
assert_equal true, r.zadd("foo", 1, "s1", :nx => true)
26+
assert_equal false, r.zadd("foo", 2, "s1", :nx => true)
2727
assert_equal 1, r.zscore("foo", "s1")
2828
assert_equal 1, r.zcard("foo")
2929
r.del "foo"
3030

3131
# CH option
3232
assert_equal 0, r.zcard("foo")
33-
assert_equal true, r.zadd("foo", 1, "s1", ch: true)
34-
assert_equal false, r.zadd("foo", 1, "s1", ch: true)
35-
assert_equal true, r.zadd("foo", 2, "s1", ch: true)
33+
assert_equal true, r.zadd("foo", 1, "s1", :ch => true)
34+
assert_equal false, r.zadd("foo", 1, "s1", :ch => true)
35+
assert_equal true, r.zadd("foo", 2, "s1", :ch => true)
3636
assert_equal 1, r.zcard("foo")
3737
r.del "foo"
3838

3939
# INCR option
40-
rv = r.zadd("foo", 1, "s1", incr: true)
40+
rv = r.zadd("foo", 1, "s1", :incr => true)
4141
assert_equal 1.0, rv
4242

43-
rv = r.zadd("foo", 10, "s1", incr: true)
43+
rv = r.zadd("foo", 10, "s1", :incr => true)
4444
assert_equal 11.0, rv
4545

46-
rv = r.zadd("bar", "-inf", "s1", incr: true)
46+
rv = r.zadd("bar", "-inf", "s1", :incr => true)
4747
assert_equal(-Infinity, rv)
4848

49-
rv = r.zadd("bar", "+inf", "s2", incr: true)
49+
rv = r.zadd("bar", "+inf", "s2", :incr => true)
5050
assert_equal(+Infinity, rv)
5151
r.del "foo", "bar"
5252

5353
# Incompatible options combinations
54-
assert_raise(ArgumentError) { r.zadd("foo", 1, "s1", xx: true, nx: true) }
54+
assert_raise(ArgumentError) { r.zadd("foo", 1, "s1", :xx => true, :nx => true) }
5555
end
5656
end
5757

@@ -79,9 +79,9 @@ def test_variadic_zadd
7979
target_version "3.0.2" do
8080
# XX option
8181
assert_equal 0, r.zcard("foo")
82-
assert_equal 0, r.zadd("foo", [1, "s1", 2, "s2"], xx: true)
82+
assert_equal 0, r.zadd("foo", [1, "s1", 2, "s2"], :xx => true)
8383
r.zadd("foo", [1, "s1", 2, "s2"])
84-
assert_equal 0, r.zadd("foo", [2, "s1", 3, "s2", 4, "s3"], xx: true)
84+
assert_equal 0, r.zadd("foo", [2, "s1", 3, "s2", 4, "s3"], :xx => true)
8585
assert_equal 2, r.zscore("foo", "s1")
8686
assert_equal 3, r.zscore("foo", "s2")
8787
assert_equal nil, r.zscore("foo", "s3")
@@ -90,8 +90,8 @@ def test_variadic_zadd
9090

9191
# NX option
9292
assert_equal 0, r.zcard("foo")
93-
assert_equal 2, r.zadd("foo", [1, "s1", 2, "s2"], nx: true)
94-
assert_equal 1, r.zadd("foo", [2, "s1", 3, "s2", 4, "s3"], nx: true)
93+
assert_equal 2, r.zadd("foo", [1, "s1", 2, "s2"], :nx => true)
94+
assert_equal 1, r.zadd("foo", [2, "s1", 3, "s2", 4, "s3"], :nx => true)
9595
assert_equal 1, r.zscore("foo", "s1")
9696
assert_equal 2, r.zscore("foo", "s2")
9797
assert_equal 4, r.zscore("foo", "s3")
@@ -100,16 +100,16 @@ def test_variadic_zadd
100100

101101
# CH option
102102
assert_equal 0, r.zcard("foo")
103-
assert_equal 2, r.zadd("foo", [1, "s1", 2, "s2"], ch: true)
104-
assert_equal 2, r.zadd("foo", [1, "s1", 3, "s2", 4, "s3"], ch: true)
103+
assert_equal 2, r.zadd("foo", [1, "s1", 2, "s2"], :ch => true)
104+
assert_equal 2, r.zadd("foo", [1, "s1", 3, "s2", 4, "s3"], :ch => true)
105105
assert_equal 3, r.zcard("foo")
106106
r.del "foo"
107107

108108
# INCR option
109-
assert_raise(ArgumentError) { r.zadd("foo", [1, "s1"], incr: true) }
109+
assert_raise(ArgumentError) { r.zadd("foo", [1, "s1"], :incr => true) }
110110

111111
# Incompatible options combinations
112-
assert_raise(ArgumentError) { r.zadd("foo", [1, "s1"], xx: true, nx: true) }
112+
assert_raise(ArgumentError) { r.zadd("foo", [1, "s1"], :xx => true, :nx => true) }
113113
end
114114
end
115115

0 commit comments

Comments
 (0)