redis-objects 1.4.3 → 1.6.0

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.
@@ -2,6 +2,7 @@
2
2
  require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
3
3
 
4
4
  require 'redis/objects'
5
+ Redis::Objects.redis = REDIS_HANDLE
5
6
 
6
7
  class Roster
7
8
  include Redis::Objects
@@ -14,11 +15,15 @@ class Roster
14
15
  list :player_stats, :marshal => true
15
16
  set :outfielders, :marshal => true
16
17
  sorted_set :rank
18
+ lock :per_field
17
19
 
18
20
  # global class counters
19
21
  counter :total_players_online, :global => true
20
22
  set :all_players_online, :global => true
21
23
  value :last_player, :global => true
24
+ lock :nasty_global_mutex, :global => true # remember it appends "_lock"
25
+ sorted_set :global_player_leaderboard, :global => true
26
+ hash_key :global_player_online_status, :global => true
22
27
 
23
28
  # custom keys
24
29
  counter :player_totals, :key => 'players/#{username}/total'
@@ -162,6 +167,14 @@ describe Redis::Objects do
162
167
  @roster.redis.get(k).should == '1'
163
168
  end
164
169
 
170
+ it "should be able to directly assign value of hash" do
171
+ @roster.contact_information['John_Name'] = 'John Doe'
172
+ @roster.contact_information = { 'John_Phone' => '12345678', 'John_Address' => '321 LANE' }
173
+ @roster.contact_information['John_Phone'].should == '12345678'
174
+ @roster.contact_information['John_Address'].should == '321 LANE'
175
+ @roster.contact_information['John_Name'].should.be.nil
176
+ end
177
+
165
178
  it "should be able to get/set contact info" do
166
179
  @roster.contact_information['John_Phone'] = '123415352'
167
180
  @roster.contact_information['John_Address'] = '123 LANE'
@@ -202,6 +215,21 @@ describe Redis::Objects do
202
215
  end
203
216
  end
204
217
 
218
+ it "should handle obtaining / clearing locks" do
219
+ # class-level calls for Admin reasons
220
+ # this is a really weird API and I wonder if anyone actually uses it
221
+ id = 88
222
+ roster = Roster.new(id)
223
+ roster.per_field_lock.exists?.should == false
224
+ Roster.obtain_lock(:per_field, id) do
225
+ roster.per_field_lock.exists?.should == true
226
+ end
227
+ roster.per_field_lock.exists?.should == false
228
+
229
+ Roster.clear_lock(:per_field, id)
230
+ roster.per_field_lock.exists?.should == false
231
+ end
232
+
205
233
  it "should support increment/decrement of counters" do
206
234
  @roster.available_slots.key.should == 'roster:1:available_slots'
207
235
  @roster.available_slots.should == 10
@@ -265,6 +293,26 @@ describe Redis::Objects do
265
293
  Roster.get_counter(:total_players_online).should == 111
266
294
  end
267
295
 
296
+ it "should support class-level manipulation of global objects" do
297
+ Roster.nasty_global_mutex_lock.exists?.should == false
298
+ Roster.nasty_global_mutex_lock do
299
+ Roster.nasty_global_mutex_lock.exists?.should == true
300
+ end
301
+ Roster.nasty_global_mutex_lock.exists?.should == false
302
+
303
+ Roster.global_player_leaderboard.exists?.should == false
304
+ Roster.global_player_leaderboard.add('nate', 22)
305
+ Roster.global_player_leaderboard.add('jim', 11)
306
+ Roster.global_player_leaderboard.rank('nate').should == 1 # 0-based
307
+
308
+ Roster.global_player_online_status.exists?.should == false
309
+ Roster.global_player_online_status['nate'] = 'online'
310
+ Roster.global_player_online_status['jeff'] = 'offline'
311
+ Roster.global_player_online_status['nate'].should == 'online'
312
+ Roster.global_player_online_status['jeff'].should == 'offline'
313
+ Roster.global_player_online_status['bobby'].should.be.nil
314
+ end
315
+
268
316
  it "should take an atomic block for increment/decrement" do
269
317
  a = false
270
318
  @roster.available_slots.should == 10
@@ -423,6 +471,13 @@ describe Redis::Objects do
423
471
  end
424
472
  error.should.be.kind_of(NoMethodError)
425
473
 
474
+ error = nil
475
+ begin
476
+ Roster.increment_counter(:available_slots, nil)
477
+ rescue => error
478
+ end
479
+ error.should.be.kind_of(Redis::Objects::MissingID)
480
+
426
481
  error = nil
427
482
  begin
428
483
  Roster.obtain_lock(:badness, 2){}
@@ -485,6 +540,12 @@ describe Redis::Objects do
485
540
  @roster.starting_pitcher.should.be.nil
486
541
  end
487
542
 
543
+ it "should be able to directly assign value of list" do
544
+ @roster.player_stats << 'c'
545
+ @roster.player_stats = ['a', 'b']
546
+ @roster.player_stats.get.should == ['a', 'b']
547
+ end
548
+
488
549
  it "should handle lists of simple values" do
489
550
  @roster.player_stats.should.be.empty
490
551
  @roster.player_stats << 'a'
@@ -559,6 +620,14 @@ describe Redis::Objects do
559
620
  @roster.player_stats.get.should == ['a','c','f','j','h','i','a']
560
621
  end
561
622
 
623
+ it "should be able to directly assign values of set" do
624
+ @roster.outfielders << 'c'
625
+ @roster.outfielders = ['a', 'b']
626
+ @roster.outfielders.member?('a').should.be.true
627
+ @roster.outfielders.member?('b').should.be.true
628
+ @roster.outfielders.member?('c').should.be.false
629
+ end
630
+
562
631
  it "should handle sets of simple values" do
563
632
  @roster.outfielders.should.be.empty
564
633
  @roster.outfielders << 'a' << 'a' << 'a'
@@ -1009,8 +1078,21 @@ describe Redis::Objects do
1009
1078
  end
1010
1079
 
1011
1080
  it "should allow deleting the entire object" do
1012
- @roster.redis.keys.select { |key| key.match(/^roster:/)}.count.should > 0
1013
- @roster.delete!.should > 0
1014
- @roster.redis.keys.select { |key| key.match(/^roster:/)}.count.should == 0
1081
+ (@roster.redis.keys & @roster.redis_instance_keys).count.should > 0
1082
+ @roster.redis_delete_objects.should > 0
1083
+ (@roster.redis.keys & @roster.redis_instance_keys).count.should == 0
1084
+ end
1085
+
1086
+ it "should be able to return all instance keys" do
1087
+ @roster.redis_instance_keys.include?('roster:1:player_stats').should == true
1088
+ @roster.redis_instance_keys.include?('players:my_rank:user1').should == true
1089
+ @roster.redis_instance_keys.include?('roster:1:player_stats').should == true
1090
+ @roster.redis_instance_keys.include?('players:all_stats').should == false
1091
+ end
1092
+
1093
+ it "should handle per-class connection handles" do
1094
+ redis = Roster.redis
1095
+ Roster.redis = redis
1096
+ Roster.redis.should == redis
1015
1097
  end
1016
1098
  end
data/spec/spec_helper.rb CHANGED
@@ -9,6 +9,21 @@ if $0 =~ /\brspec$/
9
9
  raise "\n===\nThese tests are in bacon, not rspec. Try: bacon #{ARGV * ' '}\n===\n"
10
10
  end
11
11
 
12
+ # For the incompatible change from redis.rb
13
+ Redis.exists_returns_integer = true
14
+
15
+ # Avoid phantom remote test failures
16
+ RUNNING_LOCALLY = !ENV['TRAVIS']
17
+
18
+ # Code coverage reports
19
+ require 'simplecov'
20
+ SimpleCov.start
21
+
22
+ require 'simplecov-cobertura'
23
+ SimpleCov.formatter = SimpleCov::Formatter::CoberturaFormatter
24
+
25
+ #require "active_support/xml_mini"
26
+ require "active_support"
12
27
  require "active_support/testing/time_helpers"
13
28
  include ActiveSupport::Testing::TimeHelpers
14
29
 
@@ -69,8 +84,6 @@ end
69
84
 
70
85
  # Grab a global handle
71
86
  REDIS_HANDLE = Redis.new(:host => REDIS_HOST, :port => REDIS_PORT)
72
- #$redis = REDIS_HANDLE
73
- Redis.current = REDIS_HANDLE
74
87
 
75
88
  SORT_ORDER = {:order => 'desc alpha'}
76
89
  SORT_LIMIT = {:limit => [2, 2]}
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: 1.4.3
4
+ version: 1.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nate Wiger
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-10-07 00:00:00.000000000 Z
11
+ date: 2022-04-29 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: '4.0'
19
+ version: '4.6'
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: '4.0'
26
+ version: '4.6'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: bundler
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -94,6 +94,20 @@ dependencies:
94
94
  - - ">="
95
95
  - !ruby/object:Gem::Version
96
96
  version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: activesupport
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
97
111
  - !ruby/object:Gem::Dependency
98
112
  name: activerecord
99
113
  requirement: !ruby/object:Gem::Requirement
@@ -122,6 +136,20 @@ dependencies:
122
136
  - - ">="
123
137
  - !ruby/object:Gem::Version
124
138
  version: '0'
139
+ - !ruby/object:Gem::Dependency
140
+ name: simplecov-cobertura
141
+ requirement: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - ">="
144
+ - !ruby/object:Gem::Version
145
+ version: '0'
146
+ type: :development
147
+ prerelease: false
148
+ version_requirements: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - ">="
151
+ - !ruby/object:Gem::Version
152
+ version: '0'
125
153
  description: Map Redis types directly to Ruby objects. Works with any class or ORM.
126
154
  email:
127
155
  - nwiger@gmail.com
@@ -140,6 +168,7 @@ files:
140
168
  - lib/redis-objects.rb
141
169
  - lib/redis/base_object.rb
142
170
  - lib/redis/counter.rb
171
+ - lib/redis/enumerable_object.rb
143
172
  - lib/redis/hash_key.rb
144
173
  - lib/redis/helpers/core_commands.rb
145
174
  - lib/redis/list.rb
@@ -162,6 +191,7 @@ files:
162
191
  - spec/redis_namespace_compat_spec.rb
163
192
  - spec/redis_objects_active_record_spec.rb
164
193
  - spec/redis_objects_conn_spec.rb
194
+ - spec/redis_objects_custom_serializer.rb
165
195
  - spec/redis_objects_instance_spec.rb
166
196
  - spec/redis_objects_model_spec.rb
167
197
  - spec/spec_helper.rb
@@ -184,8 +214,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
184
214
  - !ruby/object:Gem::Version
185
215
  version: '0'
186
216
  requirements: []
187
- rubyforge_project:
188
- rubygems_version: 2.7.3
217
+ rubygems_version: 3.0.3.1
189
218
  signing_key:
190
219
  specification_version: 4
191
220
  summary: Map Redis types directly to Ruby objects
@@ -194,6 +223,7 @@ test_files:
194
223
  - spec/redis_namespace_compat_spec.rb
195
224
  - spec/redis_objects_active_record_spec.rb
196
225
  - spec/redis_objects_conn_spec.rb
226
+ - spec/redis_objects_custom_serializer.rb
197
227
  - spec/redis_objects_instance_spec.rb
198
228
  - spec/redis_objects_model_spec.rb
199
229
  - spec/spec_helper.rb