redis-objects 2.0.0.alpha → 2.0.0.beta2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -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")
@@ -6,6 +6,7 @@ Redis::Objects.redis = REDIS_HANDLE
6
6
 
7
7
  class Roster
8
8
  include Redis::Objects
9
+
9
10
  counter :available_slots, :start => 10
10
11
  counter :pitchers, :limit => :max_pitchers
11
12
  counter :basic
@@ -35,7 +36,7 @@ class Roster
35
36
  def self.jimmyhat; 350; end
36
37
  value :weird_key, :key => 'players:weird_key:#{jimmyhat}', :global => true
37
38
 
38
- #callable as key
39
+ # callable as key
39
40
  counter :daily, :global => true, :key => Proc.new { |roster| "#{roster.name}:#{Time.now.strftime('%Y-%m-%dT%H')}:daily" }
40
41
 
41
42
  # set default expiration
@@ -61,16 +62,31 @@ class Roster
61
62
  end
62
63
 
63
64
  class VanillaRoster < Roster
64
- # No explicit Redis::Objects
65
+ # inherits Redis::Objects
66
+ # No explicit RedisAccessors (but they are inherited)
65
67
  end
66
68
 
67
69
  class CustomRoster < Roster
68
- include Redis::Objects
70
+ # inherits Redis::Objects
69
71
 
70
72
  counter :basic # Override
71
73
  counter :special # New
72
74
  end
73
75
 
76
+ class UidRoster < Roster
77
+ # inherits Redis::Objects
78
+
79
+ attr_accessor :uid
80
+ def initialize(uid=123) @uid = uid end
81
+ end
82
+
83
+ class CustomIdFieldRoster < UidRoster
84
+ # inherits Redis::Objects
85
+ redis_id_field :uid
86
+
87
+ counter :basic
88
+ end
89
+
74
90
  class MethodRoster
75
91
  def increment(attribute, by=1)
76
92
  42
@@ -87,18 +103,24 @@ class CustomMethodRoster < MethodRoster
87
103
  counter :basic
88
104
  end
89
105
 
90
- class UidRoster < Roster
91
- attr_accessor :uid
92
- def initialize(uid=123) @uid = uid end
93
- end
94
106
 
95
- class CustomIdFieldRoster < UidRoster
96
- redis_id_field :uid
97
- include Redis::Objects
98
- counter :basic
99
- end
107
+ # TODO: @redis_objects is un-initialized in subclasses. It only picks up accessors declared within the subclass itself.
108
+ # but all the accessors continue to work as expected.
109
+ =begin
110
+ puts "Roster.redis_objects.length: #{Roster.redis_objects.length} (expected: 35)" # got 35
111
+ VanillaRoster.total_players_online.increment(5)
112
+ VanillaRoster.global_player_leaderboard.add('nate', 22)
113
+ puts "VanillaRoster.redis_objects.length: #{VanillaRoster.redis_objects.length} (expected: 35)" # got 0
114
+ puts "VanillaRoster: total_players_online: #{VanillaRoster.total_players_online} global_player_leaderboard: #{VanillaRoster.global_player_leaderboard}" # got 5 & nate
115
+ puts "CustomRoster.redis_objects.length: #{CustomRoster.redis_objects.length} (expected: 36)" # got 2
116
+ puts "UidRoster.redis_objects.length: #{UidRoster.redis_objects.length} (expected: 35)" # got 0
117
+ puts "CustomIdFieldRoster.redis_objects.length: #{CustomIdFieldRoster.redis_objects.length} (expected: 35)" # got 1
118
+ #puts "MethodRoster.redis_objects.length: #{MethodRoster.redis_objects.length}"
119
+ puts "CustomMethodRoster.redis_objects.length: #{CustomMethodRoster.redis_objects.length} (expected: 1)" # got 1
120
+ =end
100
121
 
101
122
  describe Redis::Objects do
123
+ # Before each
102
124
  before do
103
125
  @roster = Roster.new
104
126
  @roster2 = Roster.new
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']
@@ -24,8 +24,9 @@ SimpleCov.formatter = SimpleCov::Formatter::CoberturaFormatter
24
24
 
25
25
  #require "active_support/xml_mini"
26
26
  require "active_support"
27
+ require "active_support/core_ext/integer/time" # needed for 1.second 1.minute etc durations to function
27
28
  require "active_support/testing/time_helpers"
28
- include ActiveSupport::Testing::TimeHelpers
29
+ include ActiveSupport::Testing::TimeHelpers # needed by one line in redis_objects_model_spec.rb
29
30
 
30
31
  REDIS_CLASS_NAMES = [:Counter, :HashKey, :List, :Lock, :Set, :SortedSet, :Value]
31
32
 
@@ -61,7 +62,7 @@ def kill_redis
61
62
  Process.kill "TERM", pid
62
63
  Process.kill "KILL", pid
63
64
  File.unlink pidfile
64
- File.unlink rdbfile if File.exists? rdbfile
65
+ File.unlink rdbfile if File.exist? rdbfile
65
66
  end
66
67
 
67
68
  # Start redis-server except under JRuby
metadata CHANGED
@@ -1,29 +1,28 @@
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.beta2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nate Wiger
8
- autorequire:
9
8
  bindir: bin
10
9
  cert_chain: []
11
- date: 2022-06-23 00:00:00.000000000 Z
10
+ date: 1980-01-02 00:00:00.000000000 Z
12
11
  dependencies:
13
12
  - !ruby/object:Gem::Dependency
14
13
  name: redis
15
14
  requirement: !ruby/object:Gem::Requirement
16
15
  requirements:
17
- - - ">="
16
+ - - "~>"
18
17
  - !ruby/object:Gem::Version
19
- version: '0'
18
+ version: '5.0'
20
19
  type: :runtime
21
20
  prerelease: false
22
21
  version_requirements: !ruby/object:Gem::Requirement
23
22
  requirements:
24
- - - ">="
23
+ - - "~>"
25
24
  - !ruby/object:Gem::Version
26
- version: '0'
25
+ version: '5.0'
27
26
  - !ruby/object:Gem::Dependency
28
27
  name: bundler
29
28
  requirement: !ruby/object:Gem::Requirement
@@ -188,7 +187,7 @@ files:
188
187
  - lib/redis/value.rb
189
188
  - redis-objects.gemspec
190
189
  - spec/redis_autoload_objects_spec.rb
191
- - spec/redis_legacy_key_naming_spec.rb
190
+ - spec/redis_key_naming_spec.rb
192
191
  - spec/redis_namespace_compat_spec.rb
193
192
  - spec/redis_objects_active_record_spec.rb
194
193
  - spec/redis_objects_conn_spec.rb
@@ -200,7 +199,6 @@ homepage: http://github.com/nateware/redis-objects
200
199
  licenses:
201
200
  - Artistic-2.0
202
201
  metadata: {}
203
- post_install_message:
204
202
  rdoc_options: []
205
203
  require_paths:
206
204
  - lib
@@ -211,17 +209,16 @@ required_ruby_version: !ruby/object:Gem::Requirement
211
209
  version: '0'
212
210
  required_rubygems_version: !ruby/object:Gem::Requirement
213
211
  requirements:
214
- - - ">"
212
+ - - ">="
215
213
  - !ruby/object:Gem::Version
216
- version: 1.3.1
214
+ version: '0'
217
215
  requirements: []
218
- rubygems_version: 3.3.7
219
- signing_key:
216
+ rubygems_version: 3.6.9
220
217
  specification_version: 4
221
218
  summary: Map Redis types directly to Ruby objects
222
219
  test_files:
223
220
  - spec/redis_autoload_objects_spec.rb
224
- - spec/redis_legacy_key_naming_spec.rb
221
+ - spec/redis_key_naming_spec.rb
225
222
  - spec/redis_namespace_compat_spec.rb
226
223
  - spec/redis_objects_active_record_spec.rb
227
224
  - spec/redis_objects_conn_spec.rb