redis-objects 2.0.0.alpha → 2.0.0.beta

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 22b6b39234249ccd4c9485061bb918a211c539b3612d1a916a56eab0e13e031f
4
- data.tar.gz: 9465be0b72fb8d160421eae75cf5cc5996a2aaa6b507bac6492f6a0b66fad788
3
+ metadata.gz: 3962b1b4d04b8b94a6d130f2323fe1f93a74cce5546285b011ccbb85293afa5d
4
+ data.tar.gz: cfba25072de6ac2801100f2a11aa0588dc872e0826d88c070327c3be688a9260
5
5
  SHA512:
6
- metadata.gz: ff4f516b5618e2a010c32ee0360dbfdbc172d400d3570cae3e5078aff845188171f3900849bdbb9c9c8cc869cc419d1995c9162b79e09a2a7d750d05b0591987
7
- data.tar.gz: 75677a0da407ad97925c69ea51a55d51d4fc3b7a036768e4c5cb2457adbeefdeb924160d3ec8656949b4d2369785c8de4a272a4284ccc12f379eb89b3a7496b3
6
+ metadata.gz: 64a0743cbe2f89145510e00877f2954f6734bdd472c0b272ac165912dffb4ef9d03b395ee7c63bf6a5c06504f6340cf761e69cca0f9fdf5285895b3a544e38b3
7
+ data.tar.gz: eb7cc427ed879586363b84ed1b509052a23e5bf56d7ef8621d5b9fc6d8c4fea3ec20672a1569d018f45530ac131f9e68772213192c6c42baf50beaa7cec977a5
data/CHANGELOG.rdoc CHANGED
@@ -1,5 +1,13 @@
1
1
  = Changelog for Redis::Objects
2
2
 
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
+
3
11
  == 1.7.0 (29 Apr 2022)
4
12
 
5
13
  * Bumped version to 1.7.0 to revert redis-rb version lock [Nate Wiger]
data/README.md CHANGED
@@ -6,19 +6,19 @@ Redis::Objects - Map Redis types directly to Ruby objects
6
6
  [![Donate](https://www.paypalobjects.com/en_US/i/btn/btn_donate_SM.gif)](https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=MJF7JU5M7F8VL)
7
7
 
8
8
  Important 2.0 changes
9
- ---------------------
9
+ =====================
10
10
  Redis::Objects 2.0 introduces several important backwards incompatible changes.
11
11
  Currently 2.0 can be installed with `gem install redis-objects --pre` or by listing it
12
12
  explicitly in your Gemfile:
13
13
  ~~~ruby
14
14
  # Gemfile
15
- gem 'redis-objects', '>= 2.0.0.alpha'
15
+ gem 'redis-objects', '>= 2.0.0.beta'
16
16
  ~~~
17
17
  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.
19
19
 
20
20
  Key Naming Changes
21
- ==================
21
+ ------------------
22
22
  The internal key naming scheme has changed for `Nested::Class::Namespaces` to fix a longstanding bug.
23
23
  **This means your existing data in Redis will not be accessible until you call `migrate_redis_legacy_keys`.**
24
24
 
@@ -39,8 +39,8 @@ handle a high number of keys. For large data sets, it could take a while.
39
39
 
40
40
  For more details on the issue and fix refer to [#213](https://github.com/nateware/redis-objects/issues/231).
41
41
 
42
- Rename of `lock` Method
43
- =======================
42
+ Renaming of `lock` Method
43
+ -------------------------
44
44
  The `lock` method that collided with `ActiveRecord::Base` has been renamed `redis_lock`.
45
45
  This means your classes need to be updated to call `redis_lock` instead:
46
46
 
@@ -51,7 +51,7 @@ class YouClassNameHere < ActiveRecord::Base
51
51
  end
52
52
  ~~~
53
53
 
54
- For more details on the issue and fix refer to [#213](https://github.com/nateware/redis-objects/issues/231).
54
+ For more details on the issue and fix refer to [#196](https://github.com/nateware/redis-objects/issues/196).
55
55
 
56
56
  Overview
57
57
  --------
data/lib/redis/list.rb CHANGED
@@ -31,11 +31,7 @@ class Redis
31
31
  # Remove a member from the end of the list. Redis: RPOP
32
32
  def pop(n=nil)
33
33
  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)
39
35
  else
40
36
  unmarshal redis.rpop(key)
41
37
  end
@@ -65,11 +61,7 @@ class Redis
65
61
  # Remove a member from the start of the list. Redis: LPOP
66
62
  def shift(n=nil)
67
63
  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)
73
65
  else
74
66
  unmarshal redis.lpop(key)
75
67
  end
@@ -1,5 +1,5 @@
1
1
  class Redis
2
2
  module Objects
3
- VERSION = "2.0.0.alpha"
3
+ VERSION = "2.0.0.beta"
4
4
  end
5
5
  end
data/lib/redis/objects.rb CHANGED
@@ -62,7 +62,7 @@ class Redis
62
62
  @redis = Objects::ConnectionPoolProxy.proxy_if_needed(conn)
63
63
  end
64
64
  def redis
65
- @redis || $redis || Redis.current ||
65
+ @redis || $redis ||
66
66
  raise(NotConnected, "Redis::Objects.redis not set to a Redis.new connection")
67
67
  end
68
68
 
@@ -148,11 +148,11 @@ class Redis
148
148
  legacy = redis_legacy_prefix(klass)
149
149
  if modern != legacy
150
150
  warn <<EOW
151
- WARNING: In redis-objects 2.0.0, key naming will change to fix longstanding bugs.
152
- Your class #{klass.name.to_s} will be affected by this change!
153
- Current key prefix: #{legacy.inspect}
154
- Future key prefix: #{modern.inspect}
155
- Read more at https://github.com/nateware/redis-objects/issues/231
151
+ [redis-objects] WARNING: In redis-objects 2.0.0, key naming will change to fix longstanding bugs.
152
+ [redis-objects] Your class #{klass.name.to_s} will be affected by this change!
153
+ [redis-objects] Current key prefix: #{legacy.inspect}
154
+ [redis-objects] Future key prefix: #{modern.inspect}
155
+ [redis-objects] Read more at https://github.com/nateware/redis-objects/issues/231
156
156
  EOW
157
157
  end
158
158
  end
@@ -165,7 +165,7 @@ EOW
165
165
  if legacy == redis_prefix
166
166
  raise "Failed to migrate keys for #{self.name.to_s} as legacy and new redis_prefix are the same (#{redis_prefix})"
167
167
  end
168
- warn "Migrating keys from #{legacy} prefix to #{redis_prefix}"
168
+ warn "[redis-objects] Migrating keys from #{legacy} prefix to #{redis_prefix}"
169
169
 
170
170
  loop do
171
171
  cursor, keys = redis.scan(cursor, :match => "#{legacy}:*")
@@ -178,14 +178,14 @@ EOW
178
178
  new_key = redis_field_key(name, id=id, context=self)
179
179
 
180
180
  # Rename the key
181
- warn "Rename '#{key}', '#{new_key}'"
181
+ warn "[redis-objects] Rename '#{key}', '#{new_key}'"
182
182
  ok = redis.rename(key, new_key)
183
- warn "Warning: Rename '#{key}', '#{new_key}' failed: #{ok}" if ok != 'OK'
183
+ warn "[redis-objects] Warning: Rename '#{key}', '#{new_key}' failed: #{ok}" if ok != 'OK'
184
184
  end
185
185
  break if cursor == "0"
186
186
  end
187
187
 
188
- warn "Migrated #{total_keys} total number of redis keys"
188
+ warn "[redis-objects] Migrated #{total_keys} total number of redis keys"
189
189
  end
190
190
 
191
191
  def redis_options(name)
data/lib/redis/set.rb CHANGED
@@ -15,7 +15,8 @@ class Redis
15
15
  # Redis: SADD
16
16
  def add(value)
17
17
  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
19
20
  end
20
21
  end
21
22
 
@@ -211,7 +211,7 @@ class Redis
211
211
  result = redis.zrange(temp_key, 0, -1)
212
212
  end
213
213
 
214
- result.value
214
+ result
215
215
  end
216
216
  alias_method :intersect, :intersection
217
217
  alias_method :inter, :intersection
@@ -248,7 +248,7 @@ class Redis
248
248
  result = redis.zrange(temp_key, 0, -1)
249
249
  end
250
250
 
251
- result.value
251
+ result
252
252
  end
253
253
  alias_method :|, :union
254
254
  alias_method :+, :union
@@ -19,7 +19,7 @@ Gem::Specification.new do |spec|
19
19
  spec.require_paths = ["lib"]
20
20
 
21
21
  # Only fix this one version or else tests break
22
- spec.add_dependency "redis"
22
+ spec.add_dependency "redis", '~> 5.0'
23
23
 
24
24
  # Ignore gemspec warnings on these. Trying to fix them to versions breaks TravisCI
25
25
  spec.add_development_dependency "bundler"
@@ -96,14 +96,9 @@ describe 'Connection tests' do
96
96
  end
97
97
 
98
98
  it "should support local handles with a vanilla redis connection" do
99
- # Redis.current = nil # reset from other tests
100
99
  Redis::Objects.redis = nil
101
100
  @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
107
102
 
108
103
  v = Redis::Value.new('conn/value', @redis_handle)
109
104
  v.clear
@@ -141,14 +136,9 @@ describe 'Connection tests' do
141
136
  end
142
137
 
143
138
  it "should support local handles with a connection_pool" do
144
- # Redis.current = nil # reset from other tests
145
139
  Redis::Objects.redis = nil
146
140
  @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
152
142
 
153
143
  v = Redis::Value.new('conn/value', @redis_handle)
154
144
  v.clear
@@ -148,7 +148,7 @@ describe Redis::Value do
148
148
  end
149
149
 
150
150
  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)
152
152
  @value.send(meth, 'monkey')
153
153
  @value.ttl.should > 0
154
154
  end
@@ -286,18 +286,28 @@ describe Redis::List do
286
286
  @list.get.should == ['a','c','f','j','h','i','a']
287
287
  end
288
288
 
289
- it "should support popping & shifting multiple values" do
289
+ it "should support popping and shifting multiple values" do
290
290
  @list.should.be.empty
291
291
 
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
296
300
 
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
301
311
  end
302
312
 
303
313
  it "should handle rpoplpush" do
@@ -412,7 +422,7 @@ describe Redis::List do
412
422
  end
413
423
 
414
424
  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)
416
426
  @list.clear
417
427
  @list.send(meth, 'val')
418
428
  @list.ttl.should > 0
@@ -430,7 +440,7 @@ describe Redis::List do
430
440
  end
431
441
 
432
442
  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)
434
444
  @list.clear
435
445
  @list.redis.rpush(@list.key, 'hello')
436
446
  @list[0] = 'world'
@@ -448,7 +458,7 @@ describe Redis::List do
448
458
  end
449
459
 
450
460
  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)
452
462
  @list.clear
453
463
  @list.redis.rpush(@list.key, 'hello')
454
464
  @list.insert 'BEFORE', 'hello', 'world'
@@ -586,7 +596,7 @@ describe Redis::Counter do
586
596
  @counter.ttl.should <= 10
587
597
  end
588
598
  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)
590
600
  @counter.send(meth)
591
601
  @counter.ttl.should > 0
592
602
  @counter.ttl.should <= 10
@@ -600,14 +610,14 @@ describe Redis::Counter do
600
610
  [:set, :value=].each do |meth|
601
611
  describe meth do
602
612
  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)
604
614
  @counter.send(meth, 99)
605
615
  @counter.should == 99
606
616
  @counter.ttl.should > 0
607
617
  @counter.ttl.should <= 10
608
618
  end
609
619
  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)
611
621
  @counter.send(meth, 99)
612
622
  @counter.should == 99
613
623
  @counter.ttl.should > 0
@@ -805,22 +815,25 @@ end
805
815
  describe Redis::HashKey do
806
816
  describe "With Marshal" do
807
817
  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}})
809
819
  @hash.clear
810
820
  end
811
821
 
812
822
  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
814
826
  @hash['created_at'].class.should == Time
815
827
  end
816
828
 
817
829
  it "should not marshal unless required" do
818
- @hash['updated_at'] = Time.now
830
+ @hash['updated_at'] = 10
831
+ @hash['updated_at'].should == "10"
819
832
  @hash['updated_at'].class.should == String
820
833
  end
821
834
 
822
835
  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})
824
837
 
825
838
  @hash['created_at'].class.should == Time
826
839
  @hash['updated_at'].class.should == String
@@ -849,7 +862,7 @@ describe Redis::HashKey do
849
862
  # no marshaling
850
863
  @hash.options[:marshal] = false
851
864
  v = {:json => 'data'}
852
- @hash['abc'] = v
865
+ @hash['abc'] = v.to_s
853
866
  @hash['abc'].should == v.to_s
854
867
 
855
868
  @hash.options[:marshal] = true
@@ -1075,7 +1088,7 @@ describe Redis::HashKey do
1075
1088
  end
1076
1089
 
1077
1090
  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)
1079
1092
  @hash.clear
1080
1093
  @hash.send(meth, *args)
1081
1094
  @hash.ttl.should > 0
@@ -1294,7 +1307,7 @@ describe Redis::Set do
1294
1307
  end
1295
1308
 
1296
1309
  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)
1298
1311
  @set.send(meth, 'val')
1299
1312
  @set.ttl.should > 0
1300
1313
  @set.ttl.should <= 10
@@ -1558,7 +1571,7 @@ describe Redis::SortedSet do
1558
1571
  end
1559
1572
 
1560
1573
  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)
1562
1575
  @set['val'] = 1
1563
1576
  @set.ttl.should > 0
1564
1577
  @set.ttl.should <= 10
@@ -1590,7 +1603,7 @@ describe Redis::SortedSet do
1590
1603
  @set.ttl.should <= 10
1591
1604
  end
1592
1605
  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)
1594
1607
  @set.clear
1595
1608
  @set.send(meth, 'somekey', 12)
1596
1609
  @set.ttl.should > 0
@@ -1607,7 +1620,7 @@ describe Redis::SortedSet do
1607
1620
  @set.ttl.should <= 10
1608
1621
  end
1609
1622
  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)
1611
1624
  @set.clear
1612
1625
  @set.send(meth, 'somekey' => 12)
1613
1626
  @set.ttl.should > 0
@@ -1626,7 +1639,7 @@ describe Redis::SortedSet do
1626
1639
  end
1627
1640
 
1628
1641
  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)
1630
1643
  @set.clear
1631
1644
  @set.redis.zadd(@set.key, 1, "1")
1632
1645
  @set.send(meth, 'sets', Redis::SortedSet.new('other'))
@@ -1646,7 +1659,7 @@ describe Redis::SortedSet do
1646
1659
  end
1647
1660
 
1648
1661
  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)
1650
1663
  @set.clear
1651
1664
  @set.redis.zadd(@set.key, 1, "1")
1652
1665
  @set.redis.zadd(@set.key, 2, "2")
data/spec/spec_helper.rb CHANGED
@@ -10,7 +10,7 @@ if $0 =~ /\brspec$/
10
10
  end
11
11
 
12
12
  # For the incompatible change from redis.rb
13
- Redis.exists_returns_integer = true
13
+ # Redis.exists_returns_integer = true
14
14
 
15
15
  # Avoid phantom remote test failures
16
16
  RUNNING_LOCALLY = !ENV['TRAVIS']
@@ -61,7 +61,7 @@ def kill_redis
61
61
  Process.kill "TERM", pid
62
62
  Process.kill "KILL", pid
63
63
  File.unlink pidfile
64
- File.unlink rdbfile if File.exists? rdbfile
64
+ File.unlink rdbfile if File.exist? rdbfile
65
65
  end
66
66
 
67
67
  # Start redis-server except under JRuby
metadata CHANGED
@@ -1,29 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: redis-objects
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.0.alpha
4
+ version: 2.0.0.beta
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nate Wiger
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-06-23 00:00:00.000000000 Z
11
+ date: 2023-03-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: redis
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ">="
17
+ - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '0'
19
+ version: '5.0'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - ">="
24
+ - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: '0'
26
+ version: '5.0'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: bundler
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -215,7 +215,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
215
215
  - !ruby/object:Gem::Version
216
216
  version: 1.3.1
217
217
  requirements: []
218
- rubygems_version: 3.3.7
218
+ rubygems_version: 3.4.10
219
219
  signing_key:
220
220
  specification_version: 4
221
221
  summary: Map Redis types directly to Ruby objects