redis-objects 1.4.3 → 1.5.0

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: 6a9f86f294c2283b6ceae1730dfe6f1d1c3665ac9733cd107a4aa522d8a66bda
4
- data.tar.gz: 50d631298aff5bcd5b15179c1a700a56a512c4a096cedad4c3f716999dcfebea
3
+ metadata.gz: 1645ef709707def1356b48d10f02ed09c7cffc5e83568dc3b2d14c030fdff3d7
4
+ data.tar.gz: f1ef896dfaa12b573631417eaae3039bf16fd0d07ea4019956aa002c24a057f5
5
5
  SHA512:
6
- metadata.gz: 48b37a11d5a2a5844863f2a7c559b5e38a6a96eab5d8f5393d0b688f8ffada7f8e480bb12d93869ca7a82d1fbb0fd311fc85a5f72635a4749ee771fefe834abc
7
- data.tar.gz: b09b794badff0249c468b0cc33b2daa24e87ab084cc5a778eb3415894bdad6e90070f7e3da4d417c16ec867017d4c15e5d06c0ca163560e5c4513297e3698241
6
+ metadata.gz: a9d492b56d5c712d5c33d19ac682fd45eb937ead9dba84d7123346a40aaf88020dd6be82c8697342a130470f8a23bf0d3cc701e6691cf15e685efc1aec64737a
7
+ data.tar.gz: c5033f81a4d8c9aba6798aca9bf49cf5613217b6ef388252df92fe099111b4a85c0709e96fc64fcfe2bb0cc54720a536f2b08ea6c49976d44604347d7049b978
@@ -5,7 +5,7 @@ before_install:
5
5
  - gem install bundler
6
6
 
7
7
  rvm:
8
- - 2.2
9
8
  - 2.3.3
10
9
  - 2.4.0
11
10
  - 2.5.1
11
+ - 2.6.4
@@ -1,5 +1,25 @@
1
1
  = Changelog for Redis::Objects
2
2
 
3
+ == 1.5.0 (18 Sep 2019)
4
+
5
+ * updated README on expireat [Nate Wiger]
6
+
7
+ * Add option for using a custom serializer [Tomás Rojas]
8
+
9
+ * DRY up objects to enable custom prefixing when desired [Tomás Rojas]
10
+
11
+ * Allow spop to return multiple members [Evan Paul]
12
+
13
+ * Rename #delete! to #redis_delete_objects [Mattias Pfeiffer]
14
+
15
+ * Make deletion simpler with just 1 call to Redis [Mattias Pfeiffer]
16
+
17
+ * Move `CoreCommands` inclusion to `BaseObject` [Tomás Rojas]
18
+
19
+ * Move `Enumerable` functionality to `EnumerableObject` [Tomás Rojas]
20
+
21
+ * Move `attr_reader`s to `Redis::BaseObject` [Tomás Rojas]
22
+
3
23
  == 1.4.3 (7 Oct 2018)
4
24
 
5
25
  * Merge pull request #235 from johnc219/fix/end-time-expiration Add expiration in seconds to obtain end_time [Nate Wiger]
data/README.md CHANGED
@@ -9,7 +9,7 @@ This is **not** an ORM. People that are wrapping ORM’s around Redis are missin
9
9
  The killer feature of Redis is that it allows you to perform _atomic_ operations
10
10
  on _individual_ data structures, like counters, lists, and sets. The **atomic** part is HUGE.
11
11
  Using an ORM wrapper that retrieves a "record", updates values, then sends those values back,
12
- _removes_ the atomicity, cutting the nuts off the major advantage of Redis. Just use MySQL, k?
12
+ _removes_ the atomicity, and thus the major advantage of Redis. Just use MySQL, k?
13
13
 
14
14
  This gem provides a Rubyish interface to Redis, by mapping [Redis data types](http://redis.io/commands)
15
15
  to Ruby objects, via a thin layer over the `redis` gem. It offers several advantages
@@ -550,20 +550,40 @@ Use :expiration and :expireat options to set default expiration.
550
550
 
551
551
  ~~~ruby
552
552
  value :value_with_expiration, :expiration => 1.hour
553
- value :value_with_expireat, :expireat => Time.now + 1.hour
553
+ value :value_with_expireat, :expireat => lambda { Time.now + 1.hour }
554
554
  ~~~
555
555
 
556
- :warning: `expireat` is evaluated at class load time.
557
- In this example, it will be one hour after evaluating class, not after one hour after setting value.
556
+ :warning: In the above example, `expiration` is evaluated at class load time.
557
+ In this example, it will be one hour after loading the class, not after one hour
558
+ after setting a value. If you want to expire one hour after setting the value,
559
+ please use `:expireat` with `lambda`.
560
+
561
+ Custom serialization
562
+ --------------------
563
+ You can customize how values are serialized by setting `serializer: CustomSerializer`.
564
+ The default is `Marshal` from the standard lib, but it can be anything that responds to `dump` and
565
+ `load`. `JSON` and `YAML` are popular options.
558
566
 
559
- If you want to expire one hour after setting the value. please use `lambda`.
567
+ If you need to pass extra arguments to `dump` or `load`, you can set
568
+ `marshal_dump_args: { foo: 'bar' }` and `marshal_load_args: { foo: 'bar' }` respectively.
560
569
 
561
570
  ~~~ruby
562
- value :value_with_expireat, :expireat => lambda { Time.now + 1.hour }
571
+ class CustomSerializer
572
+ def self.dump(value)
573
+ # custom code for serializing
574
+ end
575
+
576
+ def self.load(value)
577
+ # custom code for deserializing
578
+ end
579
+ end
580
+
581
+ @account = Account.create!(params[:account])
582
+ @newest = Redis::Value.new('custom_serializer', marshal: true, serializer: CustomSerializer)
583
+ @newest.value = @account.attributes
563
584
  ~~~
564
585
 
565
586
  Author
566
587
  =======
567
- Copyright (c) 2009-2013 [Nate Wiger](http://nateware.com). All Rights Reserved.
588
+ Copyright (c) 2009-2019 [Nate Wiger](http://nateware.com). All Rights Reserved.
568
589
  Released under the [Artistic License](http://www.opensource.org/licenses/artistic-license-2.0.php).
569
-
@@ -1,6 +1,12 @@
1
+ require 'redis/helpers/core_commands'
2
+
1
3
  class Redis
2
4
  # Defines base functionality for all redis-objects.
3
5
  class BaseObject
6
+ include Redis::Helpers::CoreCommands
7
+
8
+ attr_reader :key, :options
9
+
4
10
  def initialize(key, *args)
5
11
  @key = key.is_a?(Array) ? key.flatten.join(':') : key
6
12
  @options = args.last.is_a?(Hash) ? args.pop : {}
@@ -9,10 +9,6 @@ class Redis
9
9
  # class to define a counter.
10
10
  #
11
11
  class Counter < BaseObject
12
- require 'redis/helpers/core_commands'
13
- include Redis::Helpers::CoreCommands
14
-
15
- attr_reader :key, :options
16
12
  def initialize(key, *args)
17
13
  super(key, *args)
18
14
  @options[:start] ||= @options[:default] || 0
@@ -0,0 +1,28 @@
1
+ require File.dirname(__FILE__) + '/base_object'
2
+
3
+ class Redis
4
+ #
5
+ # Class representing a Redis enumerable type (list, set, sorted set, or hash).
6
+ #
7
+ class EnumerableObject < BaseObject
8
+ include Enumerable
9
+
10
+ # Iterate through each member. Redis::Objects mixes in Enumerable,
11
+ # so you can also use familiar methods like +collect+, +detect+, and so forth.
12
+ def each(&block)
13
+ value.each(&block)
14
+ end
15
+
16
+ def sort(options={})
17
+ return super() if block_given?
18
+ options[:order] = "asc alpha" if options.keys.count == 0 # compat with Ruby
19
+ val = redis.sort(key, options)
20
+ val.is_a?(Array) ? val.map{|v| unmarshal(v)} : val
21
+ end
22
+
23
+ # ActiveSupport's core extension `Enumerable#as_json` implementation is incompatible with ours.
24
+ def as_json(*)
25
+ to_hash
26
+ end
27
+ end
28
+ end
@@ -1,16 +1,10 @@
1
- require File.dirname(__FILE__) + '/base_object'
1
+ require File.dirname(__FILE__) + '/enumerable_object'
2
2
 
3
3
  class Redis
4
4
  #
5
5
  # Class representing a Redis hash.
6
6
  #
7
- class HashKey < BaseObject
8
- require 'enumerator'
9
- include Enumerable
10
- require 'redis/helpers/core_commands'
11
- include Redis::Helpers::CoreCommands
12
-
13
- attr_reader :key, :options
7
+ class HashKey < EnumerableObject
14
8
  def initialize(key, *args)
15
9
  super
16
10
  @options[:marshal_keys] ||= {}
@@ -74,11 +68,6 @@ class Redis
74
68
  alias_method :clone, :all
75
69
  alias_method :value, :all
76
70
 
77
- # Enumerate through all fields. Redis: HGETALL
78
- def each(&block)
79
- all.each(&block)
80
- end
81
-
82
71
  # Enumerate through each keys. Redis: HKEYS
83
72
  def each_key(&block)
84
73
  keys.each(&block)
@@ -101,11 +90,6 @@ class Redis
101
90
  true if size == 0
102
91
  end
103
92
 
104
- # Clears the dict of all keys/values. Redis: DEL
105
- def clear
106
- redis.del(key)
107
- end
108
-
109
93
  # Set keys in bulk, takes a hash of field/values {'field1' => 'val1'}. Redis: HMSET
110
94
  def bulk_set(*args)
111
95
  raise ArgumentError, "Argument to bulk_set must be hash of key/value pairs" unless args.last.is_a?(::Hash)
@@ -183,9 +167,5 @@ class Redis
183
167
  def decrbyfloat(field, by=1.0)
184
168
  incrbyfloat(field, -by)
185
169
  end
186
-
187
- def as_json(*)
188
- to_hash
189
- end
190
170
  end
191
171
  end
@@ -5,13 +5,14 @@ class Redis
5
5
  def exists?
6
6
  redis.exists key
7
7
  end
8
-
8
+
9
+ # Delete key. Redis: DEL
9
10
  def delete
10
11
  redis.del key
11
12
  end
12
13
  alias_method :del, :delete
13
14
  alias_method :clear, :delete
14
-
15
+
15
16
  def type
16
17
  redis.type key
17
18
  end
@@ -29,7 +30,7 @@ class Redis
29
30
  @key = dest if ret && setkey
30
31
  ret
31
32
  end
32
-
33
+
33
34
  def expire(seconds)
34
35
  redis.expire key, seconds
35
36
  end
@@ -50,20 +51,19 @@ class Redis
50
51
  redis.move key, dbindex
51
52
  end
52
53
 
53
- def sort(options={})
54
- options[:order] = "asc alpha" if options.keys.count == 0 # compat with Ruby
55
- val = redis.sort(key, options)
56
- val.is_a?(Array) ? val.map{|v| unmarshal(v)} : val
54
+ def serializer
55
+ options[:serializer] || Marshal
57
56
  end
58
57
 
59
58
  def marshal(value, domarshal=false)
60
59
  if options[:marshal] || domarshal
61
- Marshal.dump(value)
60
+ dump_args = options[:marshal_dump_args] || []
61
+ serializer.dump(value, *(dump_args.is_a?(Array) ? dump_args : [dump_args]))
62
62
  else
63
63
  value
64
64
  end
65
65
  end
66
-
66
+
67
67
  def unmarshal(value, domarshal=false)
68
68
  if value.nil?
69
69
  nil
@@ -73,7 +73,8 @@ class Redis
73
73
  elsif !value.is_a?(String)
74
74
  value
75
75
  else
76
- Marshal.load(value)
76
+ load_args = options[:marshal_load_args] || []
77
+ serializer.load(value, *(load_args.is_a?(Array) ? load_args : [load_args]))
77
78
  end
78
79
  else
79
80
  value
@@ -1,18 +1,11 @@
1
- require File.dirname(__FILE__) + '/base_object'
1
+ require File.dirname(__FILE__) + '/enumerable_object'
2
2
 
3
3
  class Redis
4
4
  #
5
5
  # Class representing a Redis list. Instances of Redis::List are designed to
6
6
  # behave as much like Ruby arrays as possible.
7
7
  #
8
- class List < BaseObject
9
- require 'enumerator'
10
- include Enumerable
11
- require 'redis/helpers/core_commands'
12
- include Redis::Helpers::CoreCommands
13
-
14
- attr_reader :key, :options
15
-
8
+ class List < EnumerableObject
16
9
  # Works like push. Can chain together: list << 'a' << 'b'
17
10
  def <<(value)
18
11
  push(value) # marshal in push()
@@ -123,12 +116,6 @@ class Redis
123
116
  redis.lrem(key, count, marshal(name)) # weird api
124
117
  end
125
118
 
126
- # Iterate through each member of the set. Redis::Objects mixes in Enumerable,
127
- # so you can also use familiar methods like +collect+, +detect+, and so forth.
128
- def each(&block)
129
- values.each(&block)
130
- end
131
-
132
119
  # Return a range of values from +start_index+ to +end_index+. Can also use
133
120
  # the familiar list[start,end] Ruby syntax. Redis: LRANGE
134
121
  def range(start_index, end_index)
@@ -169,9 +156,5 @@ class Redis
169
156
  def to_s
170
157
  values.join(', ')
171
158
  end
172
-
173
- def as_json(*)
174
- to_hash
175
- end
176
159
  end
177
160
  end
@@ -11,7 +11,6 @@ class Redis
11
11
  class Lock < BaseObject
12
12
  class LockTimeout < StandardError; end #:nodoc:
13
13
 
14
- attr_reader :key, :options
15
14
  def initialize(key, *args)
16
15
  super(key, *args)
17
16
  @options[:timeout] ||= 5
@@ -19,13 +18,6 @@ class Redis
19
18
  redis.setnx(key, @options[:start]) unless @options[:start] == 0 || @options[:init] === false
20
19
  end
21
20
 
22
- # Clear the lock. Should only be needed if there's a server crash
23
- # or some other event that gets locks in a stuck state.
24
- def clear
25
- redis.del(key)
26
- end
27
- alias_method :delete, :clear
28
-
29
21
  def value
30
22
  nil
31
23
  end
@@ -173,8 +173,15 @@ class Redis
173
173
  def redis() self.class.redis end
174
174
  def redis_objects() self.class.redis_objects end
175
175
 
176
- def delete!
177
- redis.del(redis_objects.keys.map { |k| send(k) }.reject(&:nil?).map { |obj| obj.key })
176
+ def redis_delete_objects
177
+ redis.del(redis_instance_keys)
178
+ end
179
+
180
+ def redis_instance_keys
181
+ redis_objects
182
+ .reject { |_, value| value[:global] }
183
+ .keys
184
+ .collect { |name| redis_field_key(name) }
178
185
  end
179
186
 
180
187
  def redis_options(name) #:nodoc:
@@ -1,5 +1,5 @@
1
1
  class Redis
2
2
  module Objects
3
- VERSION = "1.4.3"
3
+ VERSION = "1.5.0"
4
4
  end
5
5
  end
@@ -1,17 +1,10 @@
1
- require File.dirname(__FILE__) + '/base_object'
1
+ require File.dirname(__FILE__) + '/enumerable_object'
2
2
 
3
3
  class Redis
4
4
  #
5
5
  # Class representing a set.
6
6
  #
7
- class Set < BaseObject
8
- require 'enumerator'
9
- include Enumerable
10
- require 'redis/helpers/core_commands'
11
- include Redis::Helpers::CoreCommands
12
-
13
- attr_reader :key, :options
14
-
7
+ class Set < EnumerableObject
15
8
  # Works like add. Can chain together: list << 'a' << 'b'
16
9
  def <<(value)
17
10
  add(value)
@@ -27,8 +20,8 @@ class Redis
27
20
  end
28
21
 
29
22
  # Remove and return a random member. Redis: SPOP
30
- def pop
31
- unmarshal redis.spop(key)
23
+ def pop(count = nil)
24
+ unmarshal redis.spop(key, count)
32
25
  end
33
26
 
34
27
  # return a random member. Redis: SRANDMEMBER
@@ -74,12 +67,6 @@ class Redis
74
67
  res
75
68
  end
76
69
 
77
- # Iterate through each member of the set. Redis::Objects mixes in Enumerable,
78
- # so you can also use familiar methods like +collect+, +detect+, and so forth.
79
- def each(&block)
80
- members.each(&block)
81
- end
82
-
83
70
  # Return the intersection with another set. Can pass it either another set
84
71
  # object or set name. Also available as & which is a bit cleaner:
85
72
  #
@@ -185,10 +172,6 @@ class Redis
185
172
  members.join(', ')
186
173
  end
187
174
 
188
- def as_json(*)
189
- to_hash
190
- end
191
-
192
175
  private
193
176
 
194
177
  def keys_from_objects(sets)
@@ -1,17 +1,10 @@
1
- require File.dirname(__FILE__) + '/base_object'
1
+ require File.dirname(__FILE__) + '/enumerable_object'
2
2
 
3
3
  class Redis
4
4
  #
5
5
  # Class representing a sorted set.
6
6
  #
7
- class SortedSet < BaseObject
8
- # require 'enumerator'
9
- # include Enumerable
10
- require 'redis/helpers/core_commands'
11
- include Redis::Helpers::CoreCommands
12
-
13
- attr_reader :key, :options
14
-
7
+ class SortedSet < EnumerableObject
15
8
  # How to add values using a sorted set. The key is the member, eg,
16
9
  # "Peter", and the value is the score, eg, 163. So:
17
10
  # num_posts['Peter'] = 163
@@ -6,11 +6,6 @@ class Redis
6
6
  # Class representing a simple value. You can use standard Ruby operations on it.
7
7
  #
8
8
  class Value < BaseObject
9
- require 'redis/helpers/core_commands'
10
- include Redis::Helpers::CoreCommands
11
-
12
- attr_reader :key, :options
13
-
14
9
  def value=(val)
15
10
  allow_expiration do
16
11
  if val.nil?
@@ -0,0 +1,198 @@
1
+
2
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
3
+
4
+ require 'redis/objects'
5
+
6
+ class CustomSerializer
7
+ class << self
8
+ attr_accessor :dump_called, :load_called, :dump_args, :load_args
9
+ end
10
+
11
+ def self.dump(value, *args, **kargs)
12
+ @dump_called = true
13
+ @dump_args = [args, kargs]
14
+ Marshal.dump(value)
15
+ end
16
+
17
+ def self.load(value, *args, **kargs)
18
+ @load_called = true
19
+ @load_args = [args, kargs]
20
+ Marshal.load(value)
21
+ end
22
+
23
+ def self.reset!
24
+ @dump_called = nil
25
+ @load_called = nil
26
+ end
27
+ end
28
+
29
+ describe 'with custom serialization' do
30
+ before do
31
+ CustomSerializer.reset!
32
+ end
33
+
34
+ describe Redis::Value do
35
+ before do
36
+ @value = Redis::Value.new(
37
+ 'spec/value_custom_serializer',
38
+ marshal: true,
39
+ serializer: CustomSerializer
40
+ )
41
+ @value.clear
42
+ end
43
+
44
+ it 'uses custom serializer' do
45
+ @value.value = { json: 'data' }
46
+ CustomSerializer.dump_called.should == true
47
+ CustomSerializer.load_called.should == nil
48
+ @value.value.should == { json: 'data' }
49
+ CustomSerializer.dump_called.should == true
50
+ CustomSerializer.load_called.should == true
51
+ end
52
+
53
+ it 'passes extra arguments to dump' do
54
+ @value.options[:marshal_dump_args] = ['some', { extra: 'arguments' }]
55
+ @value.value = 1
56
+ CustomSerializer.dump_args.should == [['some'], { extra: 'arguments' }]
57
+ end
58
+
59
+ it 'passes extra arguments to load' do
60
+ @value.options[:marshal_load_args] = ['some', { extra: 'arguments' }]
61
+ @value.value = 1
62
+ @value.value.should == 1
63
+ CustomSerializer.load_args.should == [['some'], { extra: 'arguments' }]
64
+ end
65
+ end
66
+
67
+ describe Redis::List do
68
+ before do
69
+ @list = Redis::List.new(
70
+ 'spec/list_custom_serializer',
71
+ marshal: true,
72
+ serializer: CustomSerializer
73
+ )
74
+ @list.clear
75
+ end
76
+
77
+ it 'uses custom serializer' do
78
+ @list << { json: 'data' }
79
+ CustomSerializer.dump_called.should == true
80
+ CustomSerializer.load_called.should == nil
81
+ @list.should == [{ json: 'data' }]
82
+ CustomSerializer.dump_called.should == true
83
+ CustomSerializer.load_called.should == true
84
+ end
85
+
86
+ it 'passes extra arguments to dump' do
87
+ @list.options[:marshal_dump_args] = ['some', { extra: 'arguments' }]
88
+ @list << 1
89
+ CustomSerializer.dump_args.should == [['some'], { extra: 'arguments' }]
90
+ end
91
+
92
+ it 'passes extra arguments to load' do
93
+ @list.options[:marshal_load_args] = ['some', { extra: 'arguments' }]
94
+ @list << 1
95
+ @list.values.should == [1]
96
+ CustomSerializer.load_args.should == [['some'], { extra: 'arguments' }]
97
+ end
98
+ end
99
+
100
+ describe Redis::HashKey do
101
+ before do
102
+ @hash = Redis::HashKey.new(
103
+ 'spec/hash_custom_serializer',
104
+ marshal: true,
105
+ serializer: CustomSerializer
106
+ )
107
+ @hash.clear
108
+ end
109
+
110
+ it 'uses custom serializer' do
111
+ @hash['a'] = 1
112
+ CustomSerializer.dump_called.should == true
113
+ CustomSerializer.load_called.should == nil
114
+ @hash.value.should == { 'a' => 1 }
115
+ CustomSerializer.dump_called.should == true
116
+ CustomSerializer.load_called.should == true
117
+ end
118
+
119
+ it 'passes extra arguments to dump' do
120
+ @hash.options[:marshal_dump_args] = ['some', { extra: 'arguments' }]
121
+ @hash['a'] = 1
122
+ CustomSerializer.dump_args.should == [['some'], { extra: 'arguments' }]
123
+ end
124
+
125
+ it 'passes extra arguments to load' do
126
+ @hash.options[:marshal_load_args] = ['some', { extra: 'arguments' }]
127
+ @hash['a'] = 1
128
+ @hash.value.should == { 'a' => 1 }
129
+ CustomSerializer.load_args.should == [['some'], { extra: 'arguments' }]
130
+ end
131
+ end
132
+
133
+ describe Redis::Set do
134
+ before do
135
+ @set = Redis::Set.new(
136
+ 'spec/set_custom_serializer',
137
+ marshal: true,
138
+ serializer: CustomSerializer
139
+ )
140
+ @set.clear
141
+ end
142
+
143
+ it 'uses custom serializer' do
144
+ @set << 'a'
145
+ CustomSerializer.dump_called.should == true
146
+ CustomSerializer.load_called.should == nil
147
+ @set.members.should == ['a']
148
+ CustomSerializer.dump_called.should == true
149
+ CustomSerializer.load_called.should == true
150
+ end
151
+
152
+ it 'passes extra arguments to dump' do
153
+ @set.options[:marshal_dump_args] = ['some', { extra: 'arguments' }]
154
+ @set << 'a'
155
+ CustomSerializer.dump_args.should == [['some'], { extra: 'arguments' }]
156
+ end
157
+
158
+ it 'passes extra arguments to load' do
159
+ @set.options[:marshal_load_args] = ['some', { extra: 'arguments' }]
160
+ @set << 'a'
161
+ @set.members.should == ['a']
162
+ CustomSerializer.load_args.should == [['some'], { extra: 'arguments' }]
163
+ end
164
+ end
165
+
166
+ describe Redis::SortedSet do
167
+ before do
168
+ @set = Redis::SortedSet.new(
169
+ 'spec/zset_custom_serializer',
170
+ marshal: true,
171
+ serializer: CustomSerializer
172
+ )
173
+ @set.clear
174
+ end
175
+
176
+ it 'uses custom serializer' do
177
+ @set['a'] = 1
178
+ CustomSerializer.dump_called.should == true
179
+ CustomSerializer.load_called.should == nil
180
+ @set.members.should == ['a']
181
+ CustomSerializer.dump_called.should == true
182
+ CustomSerializer.load_called.should == true
183
+ end
184
+
185
+ it 'passes extra arguments to dump' do
186
+ @set.options[:marshal_dump_args] = ['some', { extra: 'arguments' }]
187
+ @set['a'] = 1
188
+ CustomSerializer.dump_args.should == [['some'], { extra: 'arguments' }]
189
+ end
190
+
191
+ it 'passes extra arguments to load' do
192
+ @set.options[:marshal_load_args] = ['some', { extra: 'arguments' }]
193
+ @set['a'] = 1
194
+ @set.members.should == ['a']
195
+ CustomSerializer.load_args.should == [['some'], { extra: 'arguments' }]
196
+ end
197
+ end
198
+ end
@@ -1009,8 +1009,15 @@ describe Redis::Objects do
1009
1009
  end
1010
1010
 
1011
1011
  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
1012
+ (@roster.redis.keys & @roster.redis_instance_keys).count.should > 0
1013
+ @roster.redis_delete_objects.should > 0
1014
+ (@roster.redis.keys & @roster.redis_instance_keys).count.should == 0
1015
+ end
1016
+
1017
+ it "should be able to return all instance keys" do
1018
+ @roster.redis_instance_keys.include?('roster:1:player_stats').should == true
1019
+ @roster.redis_instance_keys.include?('players:my_rank:user1').should == true
1020
+ @roster.redis_instance_keys.include?('roster:1:player_stats').should == true
1021
+ @roster.redis_instance_keys.include?('players:all_stats').should == false
1015
1022
  end
1016
1023
  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.3
4
+ version: 1.5.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: 2019-09-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: redis
@@ -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
@@ -184,8 +186,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
184
186
  - !ruby/object:Gem::Version
185
187
  version: '0'
186
188
  requirements: []
187
- rubyforge_project:
188
- rubygems_version: 2.7.3
189
+ rubygems_version: 3.0.3
189
190
  signing_key:
190
191
  specification_version: 4
191
192
  summary: Map Redis types directly to Ruby objects
@@ -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