redis-objects 0.8.0 → 0.9.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.
@@ -33,6 +33,20 @@ class Roster
33
33
  #callable as key
34
34
  counter :daily, :global => true, :key => Proc.new { |roster| "#{roster.name}:#{Time.now.strftime('%Y-%m-%dT%H')}:daily" }
35
35
 
36
+ # set default expiration
37
+ value :value_with_expiration, :expiration => 10
38
+ value :value_with_expireat, :expireat => Time.now + 10.seconds
39
+ set :set_with_expiration, :expiration => 10
40
+ set :set_with_expireat, :expireat => Time.now + 10.seconds
41
+ list :list_with_expiration, :expiration => 10
42
+ list :list_with_expireat, :expireat => Time.now + 10.seconds
43
+ hash_key :hash_with_expiration, :expiration => 10
44
+ hash_key :hash_with_expireat, :expireat => Time.now + 10.seconds
45
+ counter :counter_with_expiration, :expiration => 10
46
+ counter :counter_with_expireat, :expireat => Time.now + 10.seconds
47
+ sorted_set :sorted_set_with_expiration,:expiration => 10
48
+ sorted_set :sorted_set_with_expireat, :expireat => Time.now + 10.seconds
49
+
36
50
  def initialize(id=1) @id = id end
37
51
  def id; @id; end
38
52
  def username; "user#{id}"; end
@@ -594,19 +608,23 @@ describe Redis::Objects do
594
608
  @roster_1.outfielders.intersection(@roster_2.outfielders, @roster_3.outfielders).sort.should == ['d']
595
609
  @roster_1.outfielders.intersect(@roster_2.outfielders).sort.should == ['c','d','e']
596
610
  @roster_1.outfielders.inter(@roster_2.outfielders, @roster_3.outfielders).sort.should == ['d']
611
+
597
612
  @roster_1.outfielders.interstore(INTERSTORE_KEY, @roster_2.outfielders).should == 3
598
- @roster_1.redis.smembers(INTERSTORE_KEY).sort.should == ['c','d','e']
613
+ @roster_1.redis.smembers(INTERSTORE_KEY).sort.map{|v| Marshal.restore(v)}.should == ['c','d','e']
614
+
599
615
  @roster_1.outfielders.interstore(INTERSTORE_KEY, @roster_2.outfielders, @roster_3.outfielders).should == 1
600
- @roster_1.redis.smembers(INTERSTORE_KEY).sort.should == ['d']
616
+ @roster_1.redis.smembers(INTERSTORE_KEY).sort.map{|v| Marshal.restore(v)}.should == ['d']
601
617
 
602
618
  (@roster_1.outfielders | @roster_2.outfielders).sort.should == ['a','b','c','d','e','f','g']
603
619
  (@roster_1.outfielders + @roster_2.outfielders).sort.should == ['a','b','c','d','e','f','g']
604
620
  @roster_1.outfielders.union(@roster_2.outfielders).sort.should == ['a','b','c','d','e','f','g']
605
621
  @roster_1.outfielders.union(@roster_2.outfielders, @roster_3.outfielders).sort.should == ['a','b','c','d','e','f','g','l','m']
622
+
606
623
  @roster_1.outfielders.unionstore(UNIONSTORE_KEY, @roster_2.outfielders).should == 7
607
- @roster_1.redis.smembers(UNIONSTORE_KEY).sort.should == ['a','b','c','d','e','f','g']
624
+ @roster_1.redis.smembers(UNIONSTORE_KEY).map{|v| Marshal.restore(v)}.sort.should == ['a','b','c','d','e','f','g']
625
+
608
626
  @roster_1.outfielders.unionstore(UNIONSTORE_KEY, @roster_2.outfielders, @roster_3.outfielders).should == 9
609
- @roster_1.redis.smembers(UNIONSTORE_KEY).sort.should == ['a','b','c','d','e','f','g','l','m']
627
+ @roster_1.redis.smembers(UNIONSTORE_KEY).map{|v| Marshal.restore(v)}.sort.should == ['a','b','c','d','e','f','g','l','m']
610
628
  end
611
629
 
612
630
  it "should handle class-level global lists of simple values" do
@@ -920,4 +938,52 @@ describe Redis::Objects do
920
938
  extended_roster.extended_sorted_set.should.be.kind_of(Redis::SortedSet)
921
939
  @roster.respond_to?(:extended_sorted_set).should == false
922
940
  end
941
+
942
+ it "should set time to live in seconds when expiration option assigned" do
943
+ @roster.value_with_expiration.value = 'val'
944
+ @roster.value_with_expiration.ttl.should > 0
945
+ @roster.value_with_expiration.ttl.should <= 10
946
+
947
+ @roster.set_with_expiration << 'val'
948
+ @roster.set_with_expiration.ttl.should > 0
949
+ @roster.set_with_expiration.ttl.should <= 10
950
+
951
+ @roster.list_with_expiration << 'val'
952
+ @roster.list_with_expiration.ttl.should > 0
953
+ @roster.list_with_expiration.ttl.should <= 10
954
+
955
+ @roster.hash_with_expiration[:foo] = :bar
956
+ @roster.hash_with_expiration.ttl.should > 0
957
+ @roster.hash_with_expiration.ttl.should <= 10
958
+
959
+ @roster.counter_with_expiration.increment
960
+ @roster.counter_with_expiration.ttl.should > 0
961
+ @roster.counter_with_expiration.ttl.should <= 10
962
+
963
+ @roster.sorted_set_with_expiration[:foo] = 1
964
+ @roster.sorted_set_with_expiration.ttl.should > 0
965
+ @roster.sorted_set_with_expiration.ttl.should <= 10
966
+ end
967
+
968
+ it "should set expiration when expireat option assigned" do
969
+ @roster.value_with_expireat.value = 'val'
970
+ @roster.value_with_expireat.ttl.should > 0
971
+ @roster.value_with_expireat.ttl.should <= 10
972
+
973
+ @roster.set_with_expireat << 'val'
974
+ @roster.set_with_expireat.ttl.should > 0
975
+ @roster.set_with_expireat.ttl.should <= 10
976
+
977
+ @roster.list_with_expireat << 'val'
978
+ @roster.list_with_expireat.ttl.should > 0
979
+ @roster.list_with_expireat.ttl.should <= 10
980
+
981
+ @roster.hash_with_expireat[:foo] = :bar
982
+ @roster.hash_with_expireat.ttl.should > 0
983
+ @roster.hash_with_expireat.ttl.should <= 10
984
+
985
+ @roster.sorted_set_with_expireat[:foo] = 1
986
+ @roster.sorted_set_with_expireat.ttl.should > 0
987
+ @roster.sorted_set_with_expireat.ttl.should <= 10
988
+ end
923
989
  end
data/spec/spec_helper.rb CHANGED
@@ -19,26 +19,31 @@ DIFFSTORE_KEY = 'test:diffstore'
19
19
  REDIS_BIN = 'redis-server'
20
20
  REDIS_PORT = ENV['REDIS_PORT'] || 9212
21
21
  REDIS_HOST = ENV['REDIS_HOST'] || 'localhost'
22
- REDIS_PID = File.expand_path 'redis.pid', File.dirname(__FILE__)
23
- REDIS_DUMP = File.expand_path 'redis.rdb', File.dirname(__FILE__)
22
+ REDIS_PID = 'redis.pid' # can't be absolute
23
+ REDIS_DUMP = 'redis.rdb' # can't be absolute
24
+ REDIS_RUNDIR = File.dirname(__FILE__)
24
25
 
25
- describe 'redis-server' do
26
- it "starting redis-server on #{REDIS_HOST}:#{REDIS_PORT}" do
27
- fork_pid = fork do
28
- system "(echo port #{REDIS_PORT}; echo logfile /dev/null; echo daemonize yes; echo pidfile #{REDIS_PID}; echo dbfilename #{REDIS_DUMP}) | #{REDIS_BIN} -"
26
+ if !(defined?(RUBY_ENGINE) && RUBY_ENGINE == "jruby")
27
+ describe 'redis-server' do
28
+ it "starting redis-server on #{REDIS_HOST}:#{REDIS_PORT}" do
29
+ fork_pid = fork do
30
+ system "cd #{REDIS_RUNDIR} && (echo port #{REDIS_PORT}; echo logfile /dev/null; echo daemonize yes; echo pidfile #{REDIS_PID}; echo dbfilename #{REDIS_DUMP}; echo databases 32) | #{REDIS_BIN} -"
31
+ end
32
+ fork_pid.should > 0
33
+ sleep 2
29
34
  end
30
- fork_pid.should > 0
31
- sleep 2
32
35
  end
33
- end
34
36
 
35
- at_exit do
36
- pid = File.read(REDIS_PID).to_i
37
- puts "=> Killing #{REDIS_BIN} with pid #{pid}"
38
- Process.kill "TERM", pid
39
- Process.kill "KILL", pid
40
- File.unlink REDIS_PID
41
- File.unlink REDIS_DUMP if File.exists? REDIS_DUMP
37
+ at_exit do
38
+ pidfile = File.expand_path REDIS_PID, REDIS_RUNDIR
39
+ rdbfile = File.expand_path REDIS_DUMP, REDIS_RUNDIR
40
+ pid = File.read(pidfile).to_i
41
+ puts "=> Killing #{REDIS_BIN} with pid #{pid}"
42
+ Process.kill "TERM", pid
43
+ Process.kill "KILL", pid
44
+ File.unlink pidfile
45
+ File.unlink rdbfile if File.exists? rdbfile
46
+ end
42
47
  end
43
48
 
44
49
  def raises_exception(&block)
metadata CHANGED
@@ -1,97 +1,97 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: redis-objects
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.0
4
+ version: 0.9.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nate Wiger
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-11-09 00:00:00.000000000 Z
11
+ date: 2014-03-26 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
19
  version: 3.0.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
26
  version: 3.0.2
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: bundler
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - ~>
31
+ - - "~>"
32
32
  - !ruby/object:Gem::Version
33
33
  version: '1.3'
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - ~>
38
+ - - "~>"
39
39
  - !ruby/object:Gem::Version
40
40
  version: '1.3'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: rake
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - '>='
45
+ - - ">="
46
46
  - !ruby/object:Gem::Version
47
47
  version: '0'
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - '>='
52
+ - - ">="
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: bacon
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
- - - '>='
59
+ - - ">="
60
60
  - !ruby/object:Gem::Version
61
61
  version: '0'
62
62
  type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
- - - '>='
66
+ - - ">="
67
67
  - !ruby/object:Gem::Version
68
68
  version: '0'
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: redis-namespace
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
- - - '>='
73
+ - - ">="
74
74
  - !ruby/object:Gem::Version
75
75
  version: '0'
76
76
  type: :development
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
- - - '>='
80
+ - - ">="
81
81
  - !ruby/object:Gem::Version
82
82
  version: '0'
83
83
  - !ruby/object:Gem::Dependency
84
84
  name: activerecord
85
85
  requirement: !ruby/object:Gem::Requirement
86
86
  requirements:
87
- - - ~>
87
+ - - "~>"
88
88
  - !ruby/object:Gem::Version
89
89
  version: '3.2'
90
90
  type: :development
91
91
  prerelease: false
92
92
  version_requirements: !ruby/object:Gem::Requirement
93
93
  requirements:
94
- - - ~>
94
+ - - "~>"
95
95
  - !ruby/object:Gem::Version
96
96
  version: '3.2'
97
97
  description: Map Redis types directly to Ruby objects. Works with any class or ORM.
@@ -101,8 +101,8 @@ executables: []
101
101
  extensions: []
102
102
  extra_rdoc_files: []
103
103
  files:
104
- - .gitignore
105
- - .travis.yml
104
+ - ".gitignore"
105
+ - ".travis.yml"
106
106
  - ATOMICITY.rdoc
107
107
  - CHANGELOG.rdoc
108
108
  - Gemfile
@@ -115,7 +115,6 @@ files:
115
115
  - lib/redis/counter.rb
116
116
  - lib/redis/hash_key.rb
117
117
  - lib/redis/helpers/core_commands.rb
118
- - lib/redis/helpers/serialize.rb
119
118
  - lib/redis/list.rb
120
119
  - lib/redis/lock.rb
121
120
  - lib/redis/objects.rb
@@ -148,17 +147,17 @@ require_paths:
148
147
  - lib
149
148
  required_ruby_version: !ruby/object:Gem::Requirement
150
149
  requirements:
151
- - - '>='
150
+ - - ">="
152
151
  - !ruby/object:Gem::Version
153
152
  version: '0'
154
153
  required_rubygems_version: !ruby/object:Gem::Requirement
155
154
  requirements:
156
- - - '>='
155
+ - - ">="
157
156
  - !ruby/object:Gem::Version
158
157
  version: '0'
159
158
  requirements: []
160
159
  rubyforge_project:
161
- rubygems_version: 2.0.3
160
+ rubygems_version: 2.2.0
162
161
  signing_key:
163
162
  specification_version: 4
164
163
  summary: Map Redis types directly to Ruby objects
@@ -1,41 +0,0 @@
1
- class Redis
2
- module Helpers
3
- module Serialize
4
- include Marshal
5
-
6
- def to_redis(value, marshal=false)
7
- return value unless options[:marshal] || marshal
8
- case value
9
- when String, Fixnum, Bignum, Float
10
- value
11
- else
12
- dump(value)
13
- end
14
- end
15
-
16
- def from_redis(value, marshal=false)
17
- # This was removed because we can't reliably determine
18
- # if a person said @value = "123.4" maybe for space/etc.
19
- #begin
20
- # case value
21
- # when /^\d+$/
22
- # return Integer(value)
23
- # when /^(?:\d+\d.\d*|\d*\.\d+)$/
24
- # return Float(value)
25
- # end
26
- #rescue
27
- # # continue below
28
- #end
29
- return value unless options[:marshal] || marshal
30
- case value
31
- when Array
32
- value.collect{|v| from_redis(v)}
33
- when Hash
34
- value.inject({}) { |h, (k, v)| h[k] = from_redis(v); h }
35
- else
36
- restore(value) rescue value
37
- end
38
- end
39
- end
40
- end
41
- end