oxblood 0.1.0 → 0.2.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 27d328641bcf1ed89164aeb5288e6f9280ca6127
4
- data.tar.gz: fbf311595af5e1bb6fc0a582f7d1a799168399f0
3
+ metadata.gz: 914d269f92807d5e874e813be77ad7a325fa6b86
4
+ data.tar.gz: e8ec8e0a92d5ccc93a48271b0b44545cdc38a365
5
5
  SHA512:
6
- metadata.gz: 9876df90dcd7a807fe2bbcf9b7ef9a8068a08dd80943d7c0fd8808883ab99986d954d078215c7794a52dfeeb707b97f56e4b1f8976ee3ede87e5d5bf7b064e84
7
- data.tar.gz: 82efd7dd0895e1275afdecdb6c47a46d95bf8b3550bbcb45e2f18a313c575a04097ad0f17f4ed284f88002ab1c2124310ce227290f22095d076d8e594218c657
6
+ metadata.gz: 6a5584d343e12974e664c75b094662c72b0cc63c6c660c1c6f305d8a8d2cd7de2fe6c7361acf648fa1db7da158e532967be0fee053454e9a6ad785eaa63ecc52
7
+ data.tar.gz: 2d7ca78e83a921687b56de218a0b57a1bac2a262a66fb8c33c1fb630b623691e610e53ecd01063342e363927d02fb4e77d5d084f675faf7746ba49263ee09424
@@ -3,8 +3,8 @@ sudo: false
3
3
  language: ruby
4
4
 
5
5
  rvm:
6
- - 2.2.5
7
- - 2.3.1
6
+ - 2.2.6
7
+ - 2.3.3
8
8
  - 2.4.0
9
9
  - jruby-9.0.5.0
10
10
  - jruby-9.1.5.0
@@ -1,2 +1,15 @@
1
+ ## 0.2.0 (2017-01-18)
2
+ * [#13](https://github.com/etehtsea/oxblood/issues/13):
3
+ Added support for ZRANGEBYLEX/ZREMRANGEBYLEX/ZREVRANGEBYLEX - [@etehtsea](https://github.com/etehtsea)
4
+ * [#14](https://github.com/etehtsea/oxblood/issues/14):
5
+ Added support for ZINTERSTORE/ZUNIONSTORE - [@etehtsea](https://github.com/etehtsea)
6
+ * [#12](https://github.com/etehtsea/oxblood/issues/12):
7
+ Added support for ZADD options - [@etehtsea](https://github.com/etehtsea)
8
+ * [#3](https://github.com/etehtsea/oxblood/issues/3),
9
+ [#8](https://github.com/etehtsea/oxblood/issues/8),
10
+ [#10](https://github.com/etehtsea/oxblood/issues/10),
11
+ [#15](https://github.com/etehtsea/oxblood/issues/15):
12
+ Implemented SCAN, HSCAN, SSCAN, ZSCAN commands - [@etehtsea](https://github.com/etehtsea)
13
+
1
14
  ## 0.1.0 (2017-01-18)
2
15
  * Initial public release - [@etehtsea](https://github.com/etehtsea)
data/README.md CHANGED
@@ -18,15 +18,15 @@ A straightforward Redis Ruby client.
18
18
  - Cluster (0/20)
19
19
  - [Connection](http://www.rubydoc.info/github/etehtsea/oxblood/master/Oxblood/Commands/Connection)
20
20
  - Geo (0/6)
21
- - [Hashes](http://www.rubydoc.info/github/etehtsea/oxblood/master/Oxblood/Commands/Hashes) (14/15) (See [#3])
21
+ - [Hashes](http://www.rubydoc.info/github/etehtsea/oxblood/master/Oxblood/Commands/Hashes)
22
22
  - [HyperLogLog](http://www.rubydoc.info/github/etehtsea/oxblood/master/Oxblood/Commands/HyperLogLog)
23
- - [Keys](http://www.rubydoc.info/github/etehtsea/oxblood/master/Oxblood/Commands/Keys) (18/22) (See [#4], [#6], [#7], [#8])
23
+ - [Keys](http://www.rubydoc.info/github/etehtsea/oxblood/master/Oxblood/Commands/Keys) (19/22) (See [#4], [#6], [#7])
24
24
  - [Lists](http://www.rubydoc.info/github/etehtsea/oxblood/master/Oxblood/Commands/Lists)
25
25
  - Pub/Sub (0/6)
26
26
  - Scripting (0/7)
27
27
  - [Server](http://www.rubydoc.info/github/etehtsea/oxblood/master/Oxblood/Commands/Server) (2/31)
28
- - [Sets](http://www.rubydoc.info/github/etehtsea/oxblood/master/Oxblood/Commands/Sets) (14/15) (See [#10])
29
- - [Sorted Sets](http://www.rubydoc.info/github/etehtsea/oxblood/master/Oxblood/Commands/SortedSets) (15/21) (See [#12], [#13], [#14], [#15])
28
+ - [Sets](http://www.rubydoc.info/github/etehtsea/oxblood/master/Oxblood/Commands/Sets)
29
+ - [Sorted Sets](http://www.rubydoc.info/github/etehtsea/oxblood/master/Oxblood/Commands/SortedSets)
30
30
  - [Strings](http://www.rubydoc.info/github/etehtsea/oxblood/master/Oxblood/Commands/Strings) (23/24) (See [#16])
31
31
  - [Transactions](http://www.rubydoc.info/github/etehtsea/oxblood/master/Oxblood/Commands/Transactions)
32
32
  - [Pipeling](http://www.rubydoc.info/github/etehtsea/oxblood/master/Oxblood/Pipeline)
@@ -48,15 +48,8 @@ Bug reports and pull requests are welcome on [GitHub](https://github.com/etehtse
48
48
  ## License
49
49
  The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
50
50
 
51
- [#3]: https://github.com/etehtsea/oxblood/issues/3
52
51
  [#4]: https://github.com/etehtsea/oxblood/issues/4
53
52
  [#6]: https://github.com/etehtsea/oxblood/issues/6
54
53
  [#7]: https://github.com/etehtsea/oxblood/issues/7
55
- [#8]: https://github.com/etehtsea/oxblood/issues/8
56
- [#10]: https://github.com/etehtsea/oxblood/issues/10
57
- [#12]: https://github.com/etehtsea/oxblood/issues/12
58
- [#13]: https://github.com/etehtsea/oxblood/issues/13
59
- [#14]: https://github.com/etehtsea/oxblood/issues/14
60
- [#15]: https://github.com/etehtsea/oxblood/issues/15
61
54
  [#16]: https://github.com/etehtsea/oxblood/issues/16
62
55
  [#19]: https://github.com/etehtsea/oxblood/issues/19
@@ -1,3 +1,5 @@
1
+ require 'oxblood/commands/scan'
2
+
1
3
  module Oxblood
2
4
  module Commands
3
5
  module Hashes
@@ -166,6 +168,25 @@ module Oxblood
166
168
  def hvals(key)
167
169
  run(:HVALS, key)
168
170
  end
171
+
172
+ # Incrementally iterate hash fields and associated values
173
+ # @see https://redis.io/commands/hscan
174
+ #
175
+ # @param [Integer] cursor
176
+ # @param [Hash] opts
177
+ #
178
+ # @option opts [Integer] :count Amount of work that should be done at
179
+ # every call in order to retrieve elements from the collection.
180
+ # @option opts [String] :match
181
+ #
182
+ # @return [Array] two elements array, where the first element is String
183
+ # representing an unsigned 64 bit number (the cursor), and the second
184
+ # element is an Array of elements.
185
+ def hscan(key, cursor, opts = {})
186
+ args = [:HSCAN, key, cursor]
187
+ Scan.merge_opts!(args, opts)
188
+ run(*args)
189
+ end
169
190
  end
170
191
  end
171
192
  end
@@ -20,7 +20,7 @@ module Oxblood
20
20
  # @param [String, Array<String>] keys
21
21
  #
22
22
  # @return [Integer] the approximated number of unique elements observed
23
- # via {pfadd}.
23
+ # via {#pfadd}.
24
24
  def pfcount(*keys)
25
25
  run(*keys.unshift(:PFCOUNT))
26
26
  end
@@ -1,3 +1,5 @@
1
+ require 'oxblood/commands/scan'
2
+
1
3
  module Oxblood
2
4
  module Commands
3
5
  module Keys
@@ -208,6 +210,25 @@ module Oxblood
208
210
  def type(key)
209
211
  run(:TYPE, key)
210
212
  end
213
+
214
+ # Incrementally iterate the keys space
215
+ # @see https://redis.io/commands/scan
216
+ #
217
+ # @param [Integer] cursor
218
+ # @param [Hash] opts
219
+ #
220
+ # @option opts [Integer] :count Amount of work that should be done at
221
+ # every call in order to retrieve elements from the collection.
222
+ # @option opts [String] :match
223
+ #
224
+ # @return [Array] two elements array, where the first element is String
225
+ # representing an unsigned 64 bit number (the cursor), and the second
226
+ # element is an Array of elements.
227
+ def scan(cursor, opts = {})
228
+ args = [:SCAN, cursor]
229
+ Scan.merge_opts!(args, opts)
230
+ run(*args)
231
+ end
211
232
  end
212
233
  end
213
234
  end
@@ -0,0 +1,17 @@
1
+ module Oxblood
2
+ module Commands
3
+ # @api private
4
+ module Scan
5
+ # @note Mutates args argument!
6
+ def self.merge_opts!(args, opts)
7
+ if v = opts[:count]
8
+ args.push(:COUNT, v)
9
+ end
10
+
11
+ if v = opts[:match]
12
+ args.push(:MATCH, v)
13
+ end
14
+ end
15
+ end
16
+ end
17
+ end
@@ -1,3 +1,5 @@
1
+ require 'oxblood/commands/scan'
2
+
1
3
  module Oxblood
2
4
  module Commands
3
5
  module Sets
@@ -167,6 +169,25 @@ module Oxblood
167
169
  def sunionstore(destination, *keys)
168
170
  run(*keys.unshift(:SUNIONSTORE, destination))
169
171
  end
172
+
173
+ # Incrementally iterate Set elements
174
+ # @see https://redis.io/commands/sscan
175
+ #
176
+ # @param [Integer] cursor
177
+ # @param [Hash] opts
178
+ #
179
+ # @option opts [Integer] :count Amount of work that should be done at
180
+ # every call in order to retrieve elements from the collection.
181
+ # @option opts [String] :match
182
+ #
183
+ # @return [Array] two elements array, where the first element is String
184
+ # representing an unsigned 64 bit number (the cursor), and the second
185
+ # element is an Array of elements.
186
+ def sscan(key, cursor, opts = {})
187
+ args = [:SSCAN, key, cursor]
188
+ Scan.merge_opts!(args, opts)
189
+ run(*args)
190
+ end
170
191
  end
171
192
  end
172
193
  end
@@ -1,3 +1,5 @@
1
+ require 'oxblood/commands/scan'
2
+
1
3
  module Oxblood
2
4
  module Commands
3
5
  module SortedSets
@@ -10,10 +12,25 @@ module Oxblood
10
12
  #
11
13
  # @param [String] key under which store set
12
14
  # @param [[Float, String], Array<[Float, String]>] args scores and members
15
+ # @param [Hash] opts
16
+ #
17
+ # @option opts [Boolean] :xx Only update elements that already exist.
18
+ # Never add elements.
19
+ # @option opts [Boolean] :nx Don't update already existing elements.
20
+ # Always add new elements.
21
+ # @option opts [Boolean] :ch Modify the return value from the number of
22
+ # new elements added, to the total number of elements changed.
23
+ # @option opts [Boolean] :incr When this option is specified ZADD acts
24
+ # like ZINCRBY. Only one score-element pair can be specified in this mode.
13
25
  #
14
26
  # @return [Integer] The number of elements added to the sorted sets, not
15
27
  # including elements already existing for which the score was updated
16
- def zadd(key, *args)
28
+ def zadd(key, *args, **opts)
29
+ args.unshift(:XX) if opts[:xx]
30
+ args.unshift(:NX) if opts[:nx]
31
+ args.unshift(:CH) if opts[:ch]
32
+ args.unshift(:INCR) if opts[:incr]
33
+
17
34
  run(*args.unshift(:ZADD, key))
18
35
  end
19
36
 
@@ -53,6 +70,51 @@ module Oxblood
53
70
  run(:ZINCRBY, key, increment, member)
54
71
  end
55
72
 
73
+ # Return a range of members in a sorted set, by lexicographical range.
74
+ # @see https://redis.io/commands/zrangebylex
75
+ #
76
+ # @param [String] key
77
+ # @param [String] min
78
+ # @param [String] max
79
+ # @param [Hash] opts
80
+ #
81
+ # @option opts [Array<Integer, Integer>] :limit Get a range of the matching
82
+ # elements (similar to SELECT LIMIT offset, count in SQL)
83
+ #
84
+ # @return [Array<String>] list of elements in the specified score range.
85
+ def zrangebylex(key, min, max, opts = {})
86
+ common_rangebylex(:ZRANGEBYLEX, key, min, max, opts)
87
+ end
88
+
89
+ # Remove all members in a sorted set between the given lexicographical range.
90
+ # @see https://redis.io/commands/zremrangebylex
91
+ #
92
+ # @param [String] key
93
+ # @param [String] min
94
+ # @param [String] max
95
+ #
96
+ # @return [Integer] the number of elements removed.
97
+ def zremrangebylex(key, min, max)
98
+ run(:ZREMRANGEBYLEX, key, min, max)
99
+ end
100
+
101
+ # Return a range of members in a sorted set, by lexicographical range, ordered
102
+ # from higher to lower strings.
103
+ # @see https://redis.io/commands/zrevrangebylex
104
+ #
105
+ # @param [String] key
106
+ # @param [String] min
107
+ # @param [String] max
108
+ # @param [Hash] opts
109
+ #
110
+ # @option opts [Array<Integer, Integer>] :limit Get a range of the matching
111
+ # elements (similar to SELECT LIMIT offset, count in SQL)
112
+ #
113
+ # @return [Array<String>] list of elements in the specified score range.
114
+ def zrevrangebylex(key, min, max, opts = {})
115
+ common_rangebylex(:ZREVRANGEBYLEX, key, min, max, opts)
116
+ end
117
+
56
118
  # Count the number of members in a sorted set between a given
57
119
  # lexicographical range
58
120
  # @see http://redis.io/commands/zlexcount
@@ -256,6 +318,64 @@ module Oxblood
256
318
  run(:ZSCORE, key, member)
257
319
  end
258
320
 
321
+ # Incrementally iterate sorted sets elements and associated scores
322
+ # @see https://redis.io/commands/zscan
323
+ #
324
+ # @param [Integer] cursor
325
+ # @param [Hash] opts
326
+ #
327
+ # @option opts [Integer] :count Amount of work that should be done at
328
+ # every call in order to retrieve elements from the collection.
329
+ # @option opts [String] :match
330
+ #
331
+ # @return [Array] two elements array, where the first element is String
332
+ # representing an unsigned 64 bit number (the cursor), and the second
333
+ # element is an Array of elements.
334
+ def zscan(key, cursor, opts = {})
335
+ args = [:ZSCAN, key, cursor]
336
+ Scan.merge_opts!(args, opts)
337
+ run(*args)
338
+ end
339
+
340
+ # Add multiple sorted sets and store the resulting sorted set in a new key
341
+ # @see https://redis.io/commands/zunionstore
342
+ #
343
+ # @param [String] destination key
344
+ # @param [Integer] numkeys number of sorted sets
345
+ # @param [String, Array<String>] keys
346
+ # @param [Hash] opts
347
+ #
348
+ # @option opts [Array<Float>] :weights multiplication factor for each
349
+ # input sorted set.
350
+ # @option opts [Symbol] :aggregate how the results of the union
351
+ # are aggregated.
352
+ #
353
+ # @return [Integer] the number of elements in the resulting sorted set
354
+ # at destination.
355
+ def zunionstore(destination, numkeys, *keys, **opts)
356
+ common_store(:ZUNIONSTORE, destination, numkeys, keys, opts)
357
+ end
358
+
359
+ # Intersect multiple sorted sets and store the resulting sorted set in
360
+ # a new key.
361
+ # @see https://redis.io/commands/zinterstore
362
+ #
363
+ # @param [String] destination key
364
+ # @param [Integer] numkeys number of sorted sets
365
+ # @param [String, Array<String>] keys
366
+ # @param [Hash] opts
367
+ #
368
+ # @option opts [Array<Float>] :weights multiplication factor for each
369
+ # input sorted set.
370
+ # @option opts [Symbol] :aggregate how the results of the union
371
+ # are aggregated.
372
+ #
373
+ # @return [Integer] the number of elements in the resulting sorted set
374
+ # at destination.
375
+ def zinterstore(destination, numkeys, *keys, **opts)
376
+ common_store(:ZINTERSTORE, destination, numkeys, keys, opts)
377
+ end
378
+
259
379
  private
260
380
 
261
381
  def common_rangebyscore(command_name, key, min, max, opts)
@@ -271,6 +391,27 @@ module Oxblood
271
391
  args << :WITHSCORES if opts[:withscores]
272
392
  run(*args)
273
393
  end
394
+
395
+ def common_store(command_name, destination, numkeys, *keys, **opts)
396
+ args = keys.unshift(command_name, destination, numkeys)
397
+
398
+ if v = opts[:weights]
399
+ args.push(:WEIGHTS).concat(v)
400
+ end
401
+
402
+ if v = opts[:aggregate]
403
+ args.push(:AGGREGATE, v)
404
+ end
405
+
406
+ run(*args)
407
+ end
408
+
409
+ def common_rangebylex(command_name, key, min, max, opts)
410
+ args = [command_name, key, min, max]
411
+ args.push(:LIMIT).concat(opts[:limit]) if opts[:limit].is_a?(Array)
412
+
413
+ run(*args)
414
+ end
274
415
  end
275
416
  end
276
417
  end
@@ -1,3 +1,3 @@
1
1
  module Oxblood
2
- VERSION = '0.1.0'
2
+ VERSION = '0.2.0'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: oxblood
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Konstantin Shabanov
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-01-17 00:00:00.000000000 Z
11
+ date: 2017-01-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: connection_pool
@@ -122,6 +122,7 @@ files:
122
122
  - lib/oxblood/commands/hyper_log_log.rb
123
123
  - lib/oxblood/commands/keys.rb
124
124
  - lib/oxblood/commands/lists.rb
125
+ - lib/oxblood/commands/scan.rb
125
126
  - lib/oxblood/commands/server.rb
126
127
  - lib/oxblood/commands/sets.rb
127
128
  - lib/oxblood/commands/sorted_sets.rb