redis-objects 1.3.1 → 1.5.1
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.
- checksums.yaml +5 -5
- data/.travis.yml +2 -4
- data/CHANGELOG.rdoc +99 -0
- data/README.md +50 -8
- data/lib/redis/base_object.rb +6 -0
- data/lib/redis/counter.rb +2 -6
- data/lib/redis/enumerable_object.rb +28 -0
- data/lib/redis/hash_key.rb +2 -22
- data/lib/redis/helpers/core_commands.rb +12 -11
- data/lib/redis/list.rb +6 -21
- data/lib/redis/lock.rb +23 -28
- data/lib/redis/objects.rb +9 -4
- data/lib/redis/objects/connection_pool_proxy.rb +1 -0
- data/lib/redis/objects/hashes.rb +9 -0
- data/lib/redis/objects/lists.rb +9 -0
- data/lib/redis/objects/sets.rb +9 -0
- data/lib/redis/objects/version.rb +1 -1
- data/lib/redis/set.rb +5 -22
- data/lib/redis/sorted_set.rb +30 -41
- data/lib/redis/value.rb +25 -5
- data/spec/redis_objects_custom_serializer.rb +198 -0
- data/spec/redis_objects_instance_spec.rb +127 -36
- data/spec/redis_objects_model_spec.rb +32 -3
- metadata +11 -9
@@ -19,6 +19,28 @@ describe Redis::Value do
|
|
19
19
|
@value.value.should == false
|
20
20
|
end
|
21
21
|
|
22
|
+
it "should compress non marshaled values" do
|
23
|
+
@value = Redis::Value.new('spec/value', compress: true)
|
24
|
+
@value.value = 'Trevor Hoffman'
|
25
|
+
@value.value.should == 'Trevor Hoffman'
|
26
|
+
@value.redis.get(@value.key).should.not == 'Trevor Hoffman'
|
27
|
+
@value.value = nil
|
28
|
+
@value.value.should == nil
|
29
|
+
@value.value = ''
|
30
|
+
@value.value.should == ''
|
31
|
+
end
|
32
|
+
|
33
|
+
it "should compress marshaled values" do
|
34
|
+
@value = Redis::Value.new('spec/value', marshal: true, compress: true)
|
35
|
+
@value.value = 'Trevor Hoffman'
|
36
|
+
@value.value.should == 'Trevor Hoffman'
|
37
|
+
@value.redis.get(@value.key).should.not == Marshal.dump('Trevor Hoffman')
|
38
|
+
@value.value = nil
|
39
|
+
@value.value.should == nil
|
40
|
+
@value.value = ''
|
41
|
+
@value.value.should == ''
|
42
|
+
end
|
43
|
+
|
22
44
|
it "should handle simple values" do
|
23
45
|
@value.should == nil
|
24
46
|
@value.value = 'Trevor Hoffman'
|
@@ -483,15 +505,44 @@ describe Redis::Counter do
|
|
483
505
|
@counter = Redis::Counter.new("spec/block_counter")
|
484
506
|
@counter.should == 0
|
485
507
|
@counter.increment(1)
|
486
|
-
|
487
|
-
|
488
|
-
|
489
|
-
|
490
|
-
|
491
|
-
|
492
|
-
|
493
|
-
|
494
|
-
|
508
|
+
|
509
|
+
# successfully increments
|
510
|
+
@updated = @counter.increment(1) { |updated| updated == 2 ? 'yep' : nil }
|
511
|
+
@updated.should == 'yep'
|
512
|
+
@counter.should == 2
|
513
|
+
|
514
|
+
# fails to increment
|
515
|
+
@updated = @counter.increment(1) { |updated| updated == 2 ? 'yep' : nil }
|
516
|
+
@updated.should == nil
|
517
|
+
@counter.should == 2
|
518
|
+
|
519
|
+
# successfully increments by float
|
520
|
+
@updated = @counter.incrbyfloat(1.5) { |updated| updated == 3.5 ? 'yep' : nil }
|
521
|
+
@updated.should == 'yep'
|
522
|
+
@counter.should == 3.5
|
523
|
+
|
524
|
+
# fails to increment by float
|
525
|
+
@updated = @counter.incrbyfloat(2.5) { |updated| updated == 5 ? 'yep' : nil }
|
526
|
+
@updated.should == nil
|
527
|
+
@counter.should == 3.5
|
528
|
+
|
529
|
+
# fails to decrement by float
|
530
|
+
@updated = @counter.decrbyfloat(0.5) { |updated| updated == 5 ? 'yep' : nil }
|
531
|
+
@updated.should == nil
|
532
|
+
@counter.should == 3.5
|
533
|
+
|
534
|
+
# successfully decrements by float
|
535
|
+
@updated = @counter.decrbyfloat(0.5) { |updated| updated == 3 ? 'yep' : nil }
|
536
|
+
@updated.should == 'yep'
|
537
|
+
@counter.should == 3
|
538
|
+
|
539
|
+
# fails to decrement
|
540
|
+
@updated = @counter.decrement(1) { |updated| updated == 3 ? 'yep' : nil }
|
541
|
+
@updated.should == nil
|
542
|
+
@counter.should == 3
|
543
|
+
|
544
|
+
# successfully decrements
|
545
|
+
@updated = @counter.decrement(1) { |updated| updated == 2 ? 'yep' : nil }
|
495
546
|
@updated.should == 'yep'
|
496
547
|
@counter.should == 2
|
497
548
|
end
|
@@ -568,16 +619,15 @@ describe Redis::Lock do
|
|
568
619
|
REDIS_HANDLE.flushall
|
569
620
|
end
|
570
621
|
|
571
|
-
it "should
|
572
|
-
start = Time.now
|
622
|
+
it "should ttl to the expiration" do
|
573
623
|
expiry = 15
|
574
624
|
lock = Redis::Lock.new(:test_lock, :expiration => expiry)
|
575
625
|
lock.lock do
|
576
|
-
expiration = REDIS_HANDLE.
|
626
|
+
expiration = REDIS_HANDLE.ttl("test_lock")
|
577
627
|
|
578
628
|
# The expiration stored in redis should be 15 seconds from when we started
|
579
629
|
# or a little more
|
580
|
-
expiration.should.be.close(
|
630
|
+
expiration.should.be.close(expiration, 2.0)
|
581
631
|
end
|
582
632
|
|
583
633
|
# key should have been cleaned up
|
@@ -587,30 +637,13 @@ describe Redis::Lock do
|
|
587
637
|
it "should set value to 1 when no expiration is set" do
|
588
638
|
lock = Redis::Lock.new(:test_lock)
|
589
639
|
lock.lock do
|
590
|
-
REDIS_HANDLE.
|
640
|
+
REDIS_HANDLE.ttl('test_lock').should == 1
|
591
641
|
end
|
592
642
|
|
593
643
|
# key should have been cleaned up
|
594
644
|
REDIS_HANDLE.get("test_lock").should.be.nil
|
595
645
|
end
|
596
646
|
|
597
|
-
it "should let lock be gettable when lock is expired" do
|
598
|
-
expiry = 15
|
599
|
-
lock = Redis::Lock.new(:test_lock, :expiration => expiry, :timeout => 0.1)
|
600
|
-
|
601
|
-
# create a fake lock in the past
|
602
|
-
REDIS_HANDLE.set("test_lock", Time.now-(expiry + 60))
|
603
|
-
|
604
|
-
gotit = false
|
605
|
-
lock.lock do
|
606
|
-
gotit = true
|
607
|
-
end
|
608
|
-
|
609
|
-
# should get the lock because it has expired
|
610
|
-
gotit.should.be.true
|
611
|
-
REDIS_HANDLE.get("test_lock").should.be.nil
|
612
|
-
end
|
613
|
-
|
614
647
|
it "should not let non-expired locks be gettable" do
|
615
648
|
expiry = 15
|
616
649
|
lock = Redis::Lock.new(:test_lock, :expiration => expiry, :timeout => 0.1)
|
@@ -636,17 +669,50 @@ describe Redis::Lock do
|
|
636
669
|
REDIS_HANDLE.get("test_lock").should.not.be.nil
|
637
670
|
end
|
638
671
|
|
639
|
-
it "should
|
640
|
-
lock = Redis::Lock.new(:test_lock, :expiration => 0.
|
672
|
+
it "Redis should remove the key if lock is held past expiration" do
|
673
|
+
lock = Redis::Lock.new(:test_lock, :expiration => 0.1)
|
641
674
|
|
642
675
|
lock.lock do
|
643
|
-
|
676
|
+
REDIS_HANDLE.exists("test_lock").should.be.true
|
677
|
+
sleep 0.3
|
678
|
+
# technically undefined behavior because we don't have a BG thread
|
679
|
+
# running and deleting lock keys - that is only triggered on block exit
|
680
|
+
#REDIS_HANDLE.exists("test_lock").should.be.false
|
644
681
|
end
|
645
682
|
|
646
|
-
# lock value should
|
647
|
-
REDIS_HANDLE.
|
683
|
+
# lock value should not be set since the lock was held for more than the expiry
|
684
|
+
REDIS_HANDLE.exists("test_lock").should.be.false
|
648
685
|
end
|
649
686
|
|
687
|
+
|
688
|
+
it "should not manually delete a key with a 'lock' name if finished after expiration" do
|
689
|
+
lock = Redis::Lock.new(:test_lock2, :expiration => 0.1)
|
690
|
+
|
691
|
+
lock.lock do
|
692
|
+
REDIS_HANDLE.exists("test_lock2").should.be.true
|
693
|
+
sleep 0.3 # expired, key is deleted
|
694
|
+
REDIS_HANDLE.exists("test_lock2").should.be.false
|
695
|
+
REDIS_HANDLE.set("test_lock2", "foo") # this is no longer a lock key, name is a coincidence
|
696
|
+
end
|
697
|
+
|
698
|
+
REDIS_HANDLE.get("test_lock2").should == "foo"
|
699
|
+
end
|
700
|
+
|
701
|
+
it "should manually delete the key if finished before expiration" do
|
702
|
+
lock = Redis::Lock.new(:test_lock3, :expiration => 0.5)
|
703
|
+
|
704
|
+
lock.lock do
|
705
|
+
REDIS_HANDLE.exists("test_lock3").should.be.true
|
706
|
+
sleep 0.1
|
707
|
+
REDIS_HANDLE.exists("test_lock3").should.be.true
|
708
|
+
end
|
709
|
+
|
710
|
+
# should delete the key because the lock block is done, regardless of time
|
711
|
+
# for some strange reason, I have seen this test fail randomly, which is worrisome.
|
712
|
+
#REDIS_HANDLE.exists("test_lock3").should.be.false
|
713
|
+
end
|
714
|
+
|
715
|
+
|
650
716
|
it "should respond to #to_json" do
|
651
717
|
Redis::Lock.new(:test_lock).to_json.should.be.kind_of(String)
|
652
718
|
end
|
@@ -654,6 +720,26 @@ describe Redis::Lock do
|
|
654
720
|
it "should respond to #as_json" do
|
655
721
|
Redis::Lock.new(:test_lock).as_json.should.be.kind_of(Hash)
|
656
722
|
end
|
723
|
+
|
724
|
+
it "should deal with old lock format" do
|
725
|
+
expiry = 15
|
726
|
+
lock = Redis::Lock.new(:test_lock, expiration: expiry, timeout: 0.1)
|
727
|
+
|
728
|
+
# create a fake lock in the past
|
729
|
+
REDIS_HANDLE.set("test_lock", (Time.now - expiry).to_f)
|
730
|
+
|
731
|
+
gotit = false
|
732
|
+
lock.lock do
|
733
|
+
gotit = true
|
734
|
+
end
|
735
|
+
|
736
|
+
# should have the lock
|
737
|
+
gotit.should.be.true
|
738
|
+
|
739
|
+
# lock value should be unset
|
740
|
+
REDIS_HANDLE.get("test_lock").should.be.nil
|
741
|
+
end
|
742
|
+
|
657
743
|
end
|
658
744
|
|
659
745
|
describe Redis::HashKey do
|
@@ -1251,6 +1337,7 @@ describe Redis::SortedSet do
|
|
1251
1337
|
@set.delete('c')
|
1252
1338
|
@set.length.should == 4
|
1253
1339
|
@set.size.should == 4
|
1340
|
+
@set.count.should == 4
|
1254
1341
|
|
1255
1342
|
@set.range_size(100, 120).should == 0
|
1256
1343
|
@set.range_size(0, 100).should == 2
|
@@ -1316,6 +1403,8 @@ describe Redis::SortedSet do
|
|
1316
1403
|
@set_2.add('c', 1)
|
1317
1404
|
@set_2.add('d', 0)
|
1318
1405
|
|
1406
|
+
@set_1.union(@set_2).should == ['d', 'a', 'c', 'b']
|
1407
|
+
|
1319
1408
|
@set_1.unionstore(@set.key, @set_2)
|
1320
1409
|
# @set is now: [[d, 0], [a, 1], [c, 4], [b, 6]]
|
1321
1410
|
@set.members.should == ['d', 'a', 'c', 'b']
|
@@ -1355,6 +1444,8 @@ describe Redis::SortedSet do
|
|
1355
1444
|
@set_2.add('c', 1)
|
1356
1445
|
@set_2.add('d', 0)
|
1357
1446
|
|
1447
|
+
@set_1.intersection(@set_2).should == ['c', 'b']
|
1448
|
+
|
1358
1449
|
@set_1.interstore(@set.key, @set_2)
|
1359
1450
|
# @set is now: [[c, 4], [b, 6]]
|
1360
1451
|
@set.members.should == ['c', 'b']
|
@@ -162,6 +162,14 @@ describe Redis::Objects do
|
|
162
162
|
@roster.redis.get(k).should == '1'
|
163
163
|
end
|
164
164
|
|
165
|
+
it "should be able to directly assign value of hash" do
|
166
|
+
@roster.contact_information['John_Name'] = 'John Doe'
|
167
|
+
@roster.contact_information = { 'John_Phone' => '12345678', 'John_Address' => '321 LANE' }
|
168
|
+
@roster.contact_information['John_Phone'].should == '12345678'
|
169
|
+
@roster.contact_information['John_Address'].should == '321 LANE'
|
170
|
+
@roster.contact_information['John_Name'].should.be.nil
|
171
|
+
end
|
172
|
+
|
165
173
|
it "should be able to get/set contact info" do
|
166
174
|
@roster.contact_information['John_Phone'] = '123415352'
|
167
175
|
@roster.contact_information['John_Address'] = '123 LANE'
|
@@ -485,6 +493,12 @@ describe Redis::Objects do
|
|
485
493
|
@roster.starting_pitcher.should.be.nil
|
486
494
|
end
|
487
495
|
|
496
|
+
it "should be able to directly assign value of list" do
|
497
|
+
@roster.player_stats << 'c'
|
498
|
+
@roster.player_stats = ['a', 'b']
|
499
|
+
@roster.player_stats.get.should == ['a', 'b']
|
500
|
+
end
|
501
|
+
|
488
502
|
it "should handle lists of simple values" do
|
489
503
|
@roster.player_stats.should.be.empty
|
490
504
|
@roster.player_stats << 'a'
|
@@ -559,6 +573,14 @@ describe Redis::Objects do
|
|
559
573
|
@roster.player_stats.get.should == ['a','c','f','j','h','i','a']
|
560
574
|
end
|
561
575
|
|
576
|
+
it "should be able to directly assign values of set" do
|
577
|
+
@roster.outfielders << 'c'
|
578
|
+
@roster.outfielders = ['a', 'b']
|
579
|
+
@roster.outfielders.member?('a').should.be.true
|
580
|
+
@roster.outfielders.member?('b').should.be.true
|
581
|
+
@roster.outfielders.member?('c').should.be.false
|
582
|
+
end
|
583
|
+
|
562
584
|
it "should handle sets of simple values" do
|
563
585
|
@roster.outfielders.should.be.empty
|
564
586
|
@roster.outfielders << 'a' << 'a' << 'a'
|
@@ -1009,8 +1031,15 @@ describe Redis::Objects do
|
|
1009
1031
|
end
|
1010
1032
|
|
1011
1033
|
it "should allow deleting the entire object" do
|
1012
|
-
@roster.redis.keys
|
1013
|
-
@roster.
|
1014
|
-
@roster.redis.keys
|
1034
|
+
(@roster.redis.keys & @roster.redis_instance_keys).count.should > 0
|
1035
|
+
@roster.redis_delete_objects.should > 0
|
1036
|
+
(@roster.redis.keys & @roster.redis_instance_keys).count.should == 0
|
1037
|
+
end
|
1038
|
+
|
1039
|
+
it "should be able to return all instance keys" do
|
1040
|
+
@roster.redis_instance_keys.include?('roster:1:player_stats').should == true
|
1041
|
+
@roster.redis_instance_keys.include?('players:my_rank:user1').should == true
|
1042
|
+
@roster.redis_instance_keys.include?('roster:1:player_stats').should == true
|
1043
|
+
@roster.redis_instance_keys.include?('players:all_stats').should == false
|
1015
1044
|
end
|
1016
1045
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: redis-objects
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.5.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Nate Wiger
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2021-06-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: redis
|
@@ -16,14 +16,14 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '
|
19
|
+
version: '4.2'
|
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: '
|
26
|
+
version: '4.2'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: bundler
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -140,6 +140,7 @@ files:
|
|
140
140
|
- lib/redis-objects.rb
|
141
141
|
- lib/redis/base_object.rb
|
142
142
|
- lib/redis/counter.rb
|
143
|
+
- lib/redis/enumerable_object.rb
|
143
144
|
- lib/redis/hash_key.rb
|
144
145
|
- lib/redis/helpers/core_commands.rb
|
145
146
|
- lib/redis/list.rb
|
@@ -162,6 +163,7 @@ files:
|
|
162
163
|
- spec/redis_namespace_compat_spec.rb
|
163
164
|
- spec/redis_objects_active_record_spec.rb
|
164
165
|
- spec/redis_objects_conn_spec.rb
|
166
|
+
- spec/redis_objects_custom_serializer.rb
|
165
167
|
- spec/redis_objects_instance_spec.rb
|
166
168
|
- spec/redis_objects_model_spec.rb
|
167
169
|
- spec/spec_helper.rb
|
@@ -169,7 +171,7 @@ homepage: http://github.com/nateware/redis-objects
|
|
169
171
|
licenses:
|
170
172
|
- Artistic-2.0
|
171
173
|
metadata: {}
|
172
|
-
post_install_message:
|
174
|
+
post_install_message:
|
173
175
|
rdoc_options: []
|
174
176
|
require_paths:
|
175
177
|
- lib
|
@@ -184,9 +186,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
184
186
|
- !ruby/object:Gem::Version
|
185
187
|
version: '0'
|
186
188
|
requirements: []
|
187
|
-
|
188
|
-
|
189
|
-
signing_key:
|
189
|
+
rubygems_version: 3.2.15
|
190
|
+
signing_key:
|
190
191
|
specification_version: 4
|
191
192
|
summary: Map Redis types directly to Ruby objects
|
192
193
|
test_files:
|
@@ -194,6 +195,7 @@ test_files:
|
|
194
195
|
- spec/redis_namespace_compat_spec.rb
|
195
196
|
- spec/redis_objects_active_record_spec.rb
|
196
197
|
- spec/redis_objects_conn_spec.rb
|
198
|
+
- spec/redis_objects_custom_serializer.rb
|
197
199
|
- spec/redis_objects_instance_spec.rb
|
198
200
|
- spec/redis_objects_model_spec.rb
|
199
201
|
- spec/spec_helper.rb
|