Skip to content

Commit 84bff78

Browse files
committed
Updated internal APIs to match redis-rb 5.0
1 parent de1d772 commit 84bff78

File tree

11 files changed

+64
-60
lines changed

11 files changed

+64
-60
lines changed

CHANGELOG.rdoc

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
11
= Changelog for Redis::Objects
22

3+
== 2.0.0.beta (30 Mar 2023)
4+
5+
* Updated internal calls to match `redis-rb`
6+
7+
* INCOMPAT: `Redis.current` is no longer allowed due to changes in `redis-rb`
8+
9+
* INCOMPAT: The order of items popped off a list by the rarely-used command `list.pop(n)` to specify multiple elements is now reversed to match redis.
10+
311
== 1.7.0 (29 Apr 2022)
412

513
* Bumped version to 1.7.0 to revert redis-rb version lock [Nate Wiger]

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@ Currently 2.0 can be installed with `gem install redis-objects --pre` or by list
1212
explicitly in your Gemfile:
1313
~~~ruby
1414
# Gemfile
15-
gem 'redis-objects', '>= 2.0.0.alpha'
15+
gem 'redis-objects', '>= 2.0.0.beta'
1616
~~~
1717
You're encouraged to try it out in test code (not production) to ensure it works for you.
18-
Official release is expected later in 2022.
18+
Official release is expected later in 2023.
1919

2020
Key Naming Changes
2121
------------------

lib/redis/list.rb

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,7 @@ def push(*values)
3131
# Remove a member from the end of the list. Redis: RPOP
3232
def pop(n=nil)
3333
if n
34-
result, = redis.multi do
35-
redis.lrange(key, -n, -1)
36-
redis.ltrim(key, 0, -n - 1)
37-
end
38-
unmarshal result
34+
unmarshal redis.rpop(key, n)
3935
else
4036
unmarshal redis.rpop(key)
4137
end
@@ -65,11 +61,7 @@ def unshift(*values)
6561
# Remove a member from the start of the list. Redis: LPOP
6662
def shift(n=nil)
6763
if n
68-
result, = redis.multi do
69-
redis.lrange(key, 0, n - 1)
70-
redis.ltrim(key, n, -1)
71-
end
72-
unmarshal result
64+
unmarshal redis.lpop(key, n)
7365
else
7466
unmarshal redis.lpop(key)
7567
end

lib/redis/objects.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ def redis=(conn)
6262
@redis = Objects::ConnectionPoolProxy.proxy_if_needed(conn)
6363
end
6464
def redis
65-
@redis || $redis || Redis.current ||
65+
@redis || $redis ||
6666
raise(NotConnected, "Redis::Objects.redis not set to a Redis.new connection")
6767
end
6868

lib/redis/objects/version.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
class Redis
22
module Objects
3-
VERSION = "2.0.0.alpha"
3+
VERSION = "2.0.0.beta"
44
end
55
end

lib/redis/set.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@ def <<(value)
1515
# Redis: SADD
1616
def add(value)
1717
allow_expiration do
18-
redis.sadd(key, marshal(value)) if value.nil? || !Array(value).empty?
18+
value = '' if value.nil?
19+
redis.sadd(key, marshal(value)) if !Array(value).empty? # allow empty adds
1920
end
2021
end
2122

lib/redis/sorted_set.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ def intersection(*sets)
211211
result = redis.zrange(temp_key, 0, -1)
212212
end
213213

214-
result.value
214+
result
215215
end
216216
alias_method :intersect, :intersection
217217
alias_method :inter, :intersection
@@ -248,7 +248,7 @@ def union(*sets)
248248
result = redis.zrange(temp_key, 0, -1)
249249
end
250250

251-
result.value
251+
result
252252
end
253253
alias_method :|, :union
254254
alias_method :+, :union

redis-objects.gemspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ Gem::Specification.new do |spec|
1919
spec.require_paths = ["lib"]
2020

2121
# Only fix this one version or else tests break
22-
spec.add_dependency "redis"
22+
spec.add_dependency "redis", '~> 5.0'
2323

2424
# Ignore gemspec warnings on these. Trying to fix them to versions breaks TravisCI
2525
spec.add_development_dependency "bundler"

spec/redis_objects_conn_spec.rb

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -96,14 +96,9 @@ def id
9696
end
9797

9898
it "should support local handles with a vanilla redis connection" do
99-
# Redis.current = nil # reset from other tests
10099
Redis::Objects.redis = nil
101100
@redis_handle = Redis.new(:host => REDIS_HOST, :port => REDIS_PORT)
102-
103-
# Redis.current is lazily auto-populated to touch 6379
104-
# This why we choose the weird 9212 port to avoid
105-
# Redis.current.inspect.should == Redis.new.inspect
106-
Redis::Objects.redis.inspect.should == Redis.new.inspect
101+
raises_exception{ Redis::Objects.redis.inspect } # NotConnected
107102

108103
v = Redis::Value.new('conn/value', @redis_handle)
109104
v.clear
@@ -141,14 +136,9 @@ def id
141136
end
142137

143138
it "should support local handles with a connection_pool" do
144-
# Redis.current = nil # reset from other tests
145139
Redis::Objects.redis = nil
146140
@redis_handle = ConnectionPool.new { Redis.new(:host => REDIS_HOST, :port => REDIS_PORT) }
147-
148-
# Redis.current is lazily auto-populated to touch 6379
149-
# This why we choose the weird 9212 port to avoid
150-
# Redis.current.inspect.should == Redis.new.inspect
151-
Redis::Objects.redis.inspect.should == Redis.new.inspect
141+
raises_exception{ Redis::Objects.redis.inspect } # NotConnected
152142

153143
v = Redis::Value.new('conn/value', @redis_handle)
154144
v.clear

spec/redis_objects_instance_spec.rb

Lines changed: 41 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@
148148
end
149149

150150
it "#{meth} should set expiration when expireat option assigned" do
151-
@value = Redis::Value.new('spec/value', :expireat => Time.now + 10.seconds)
151+
@value = Redis::Value.new('spec/value', :expireat => Time.now + 10)
152152
@value.send(meth, 'monkey')
153153
@value.ttl.should > 0
154154
end
@@ -286,18 +286,28 @@
286286
@list.get.should == ['a','c','f','j','h','i','a']
287287
end
288288

289-
it "should support popping & shifting multiple values" do
289+
it "should support popping and shifting multiple values" do
290290
@list.should.be.empty
291291

292-
@list << 'a' << 'b' << 'c'
293-
@list.shift(2).should == ['a', 'b']
294-
@list.shift(2).should == ['c']
295-
@list.shift(2).should == []
292+
@list << 'a' << 'b' << 'c' << 'd'
293+
@list.should == ['a', 'b', 'c', 'd']
294+
@list.shift
295+
@list.should == ['b', 'c', 'd']
296+
@list.shift(2).should == ['b', 'c']
297+
@list.should == ['d']
298+
@list.shift(2).should == ['d']
299+
@list.shift(2).should == nil
296300

297-
@list << 'a' << 'b' << 'c'
298-
@list.pop(2).should == ['b', 'c']
299-
@list.pop(2).should == ['a']
300-
@list.pop(2).should == []
301+
@list << 'e' << 'f' << 'g'
302+
303+
# Old behavior
304+
# @list.pop(2).should == ['f', 'g']
305+
306+
# New behavior
307+
@list.pop(2).should == ['g', 'f']
308+
309+
@list.pop(2).should == ['e']
310+
@list.pop(2).should == nil
301311
end
302312

303313
it "should handle rpoplpush" do
@@ -412,7 +422,7 @@
412422
end
413423

414424
it "#{meth} expireat: option" do
415-
@list = Redis::List.new('spec/list_exp', :expireat => Time.now + 10.seconds)
425+
@list = Redis::List.new('spec/list_exp', :expireat => Time.now + 10)
416426
@list.clear
417427
@list.send(meth, 'val')
418428
@list.ttl.should > 0
@@ -430,7 +440,7 @@
430440
end
431441

432442
it "[]= expireat: option" do
433-
@list = Redis::List.new('spec/list_exp', :expireat => Time.now + 10.seconds)
443+
@list = Redis::List.new('spec/list_exp', :expireat => Time.now + 10)
434444
@list.clear
435445
@list.redis.rpush(@list.key, 'hello')
436446
@list[0] = 'world'
@@ -448,7 +458,7 @@
448458
end
449459

450460
it "insert expireat: option" do
451-
@list = Redis::List.new('spec/list_exp', :expireat => Time.now + 10.seconds)
461+
@list = Redis::List.new('spec/list_exp', :expireat => Time.now + 10)
452462
@list.clear
453463
@list.redis.rpush(@list.key, 'hello')
454464
@list.insert 'BEFORE', 'hello', 'world'
@@ -586,7 +596,7 @@
586596
@counter.ttl.should <= 10
587597
end
588598
it "expireat: option" do
589-
@counter = Redis::Counter.new('spec/counter_exp', :expireat => Time.now + 10.seconds)
599+
@counter = Redis::Counter.new('spec/counter_exp', :expireat => Time.now + 10)
590600
@counter.send(meth)
591601
@counter.ttl.should > 0
592602
@counter.ttl.should <= 10
@@ -600,14 +610,14 @@
600610
[:set, :value=].each do |meth|
601611
describe meth do
602612
it "expiration: option" do
603-
@counter = Redis::Counter.new('spec/counter_exp', :expireat => Time.now + 10.seconds)
613+
@counter = Redis::Counter.new('spec/counter_exp', :expireat => Time.now + 10)
604614
@counter.send(meth, 99)
605615
@counter.should == 99
606616
@counter.ttl.should > 0
607617
@counter.ttl.should <= 10
608618
end
609619
it "expireat: option" do
610-
@counter = Redis::Counter.new('spec/counter_exp', :expireat => Time.now + 10.seconds)
620+
@counter = Redis::Counter.new('spec/counter_exp', :expireat => Time.now + 10)
611621
@counter.send(meth, 99)
612622
@counter.should == 99
613623
@counter.ttl.should > 0
@@ -805,22 +815,25 @@
805815
describe Redis::HashKey do
806816
describe "With Marshal" do
807817
before do
808-
@hash = Redis::HashKey.new('test_hash', {:marshal_keys=>{'created_at'=>true}})
818+
@hash = Redis::HashKey.new('test_hash', {:marshal_keys=>{'created_at' => true}})
809819
@hash.clear
810820
end
811821

812822
it "should marshal specified keys" do
813-
@hash['created_at'] = Time.now
823+
time = Time.now
824+
@hash['created_at'] = time
825+
@hash['created_at'].should == time
814826
@hash['created_at'].class.should == Time
815827
end
816828

817829
it "should not marshal unless required" do
818-
@hash['updated_at'] = Time.now
830+
@hash['updated_at'] = 10
831+
@hash['updated_at'].should == "10"
819832
@hash['updated_at'].class.should == String
820833
end
821834

822835
it "should marshall appropriate key with bulk set and get" do
823-
@hash.bulk_set({'created_at'=>Time.now, 'updated_at'=>Time.now})
836+
@hash.bulk_set({'created_at' => Time.now, 'updated_at' => 11})
824837

825838
@hash['created_at'].class.should == Time
826839
@hash['updated_at'].class.should == String
@@ -849,7 +862,7 @@
849862
# no marshaling
850863
@hash.options[:marshal] = false
851864
v = {:json => 'data'}
852-
@hash['abc'] = v
865+
@hash['abc'] = v.to_s
853866
@hash['abc'].should == v.to_s
854867

855868
@hash.options[:marshal] = true
@@ -1075,7 +1088,7 @@
10751088
end
10761089

10771090
it "#{meth} expireat: option" do
1078-
@hash = Redis::HashKey.new('spec/hash_expireat', :expireat => Time.now + 10.seconds)
1091+
@hash = Redis::HashKey.new('spec/hash_expireat', :expireat => Time.now + 10)
10791092
@hash.clear
10801093
@hash.send(meth, *args)
10811094
@hash.ttl.should > 0
@@ -1294,7 +1307,7 @@
12941307
end
12951308

12961309
it "should set expiration when expireat option assigned" do
1297-
@set = Redis::Set.new('spec/set', :expireat => Time.now + 10.seconds)
1310+
@set = Redis::Set.new('spec/set', :expireat => Time.now + 10)
12981311
@set.send(meth, 'val')
12991312
@set.ttl.should > 0
13001313
@set.ttl.should <= 10
@@ -1558,7 +1571,7 @@
15581571
end
15591572

15601573
it 'should set expiration when expireat option assigned' do
1561-
@set = Redis::SortedSet.new('spec/zset', :expireat => Time.now + 10.seconds)
1574+
@set = Redis::SortedSet.new('spec/zset', :expireat => Time.now + 10)
15621575
@set['val'] = 1
15631576
@set.ttl.should > 0
15641577
@set.ttl.should <= 10
@@ -1590,7 +1603,7 @@
15901603
@set.ttl.should <= 10
15911604
end
15921605
it "#{meth} expireat: option" do
1593-
@set = Redis::SortedSet.new('spec/zset_exp', :expireat => Time.now + 10.seconds)
1606+
@set = Redis::SortedSet.new('spec/zset_exp', :expireat => Time.now + 10)
15941607
@set.clear
15951608
@set.send(meth, 'somekey', 12)
15961609
@set.ttl.should > 0
@@ -1607,7 +1620,7 @@
16071620
@set.ttl.should <= 10
16081621
end
16091622
it "#{meth} expireat: option" do
1610-
@set = Redis::SortedSet.new('spec/zset_exp', :expireat => Time.now + 10.seconds)
1623+
@set = Redis::SortedSet.new('spec/zset_exp', :expireat => Time.now + 10)
16111624
@set.clear
16121625
@set.send(meth, 'somekey' => 12)
16131626
@set.ttl.should > 0
@@ -1626,7 +1639,7 @@
16261639
end
16271640

16281641
it "#{meth} expireat: option" do
1629-
@set = Redis::SortedSet.new('spec/zset_exp', :expireat => Time.now + 10.seconds)
1642+
@set = Redis::SortedSet.new('spec/zset_exp', :expireat => Time.now + 10)
16301643
@set.clear
16311644
@set.redis.zadd(@set.key, 1, "1")
16321645
@set.send(meth, 'sets', Redis::SortedSet.new('other'))
@@ -1646,7 +1659,7 @@
16461659
end
16471660

16481661
it "delete expireat: option" do
1649-
@set = Redis::SortedSet.new('spec/zset_exp', :expireat => Time.now + 10.seconds)
1662+
@set = Redis::SortedSet.new('spec/zset_exp', :expireat => Time.now + 10)
16501663
@set.clear
16511664
@set.redis.zadd(@set.key, 1, "1")
16521665
@set.redis.zadd(@set.key, 2, "2")

spec/spec_helper.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
end
1111

1212
# For the incompatible change from redis.rb
13-
Redis.exists_returns_integer = true
13+
# Redis.exists_returns_integer = true
1414

1515
# Avoid phantom remote test failures
1616
RUNNING_LOCALLY = !ENV['TRAVIS']
@@ -61,7 +61,7 @@ def kill_redis
6161
Process.kill "TERM", pid
6262
Process.kill "KILL", pid
6363
File.unlink pidfile
64-
File.unlink rdbfile if File.exists? rdbfile
64+
File.unlink rdbfile if File.exist? rdbfile
6565
end
6666

6767
# Start redis-server except under JRuby

0 commit comments

Comments
 (0)