redstruct 0.1.5 → 0.1.6

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
  SHA1:
3
- metadata.gz: 470e39dc31ddff31e91a990af14296a18dd15b07
4
- data.tar.gz: 65bf67b6726bb0b0ba89f72f37e122a33f67e358
3
+ metadata.gz: b037a49dda3d7e960996e6fbc0c9bbc5ffe6445c
4
+ data.tar.gz: 221f64d42c69a93802971c6e8ecf425dd598ac22
5
5
  SHA512:
6
- metadata.gz: 386d4fc527e3d02ac6d1dd69ab764cfe70727124544accdceba3ef0aad5d7c10e21b5ef50be33b2820d39ec288b522e170ce34fb192d9db83070fd41b681b286
7
- data.tar.gz: 5925383ed20bff46031493315e36a3af5622fc6aefe3bb91dfeb1726848fa7461d13a646d481f744e74cbb1460fad7bb6d4adc1a2602deda83b2feaf269ba0ae
6
+ metadata.gz: 94c3c5363a1f04b83cb6438fb07b22df54528fbc51d2f2820a8ffc46c59684bde7fd19ddd1aa83045fa109a7c7e7f94a6d3ce89339b535d751216142873b0987
7
+ data.tar.gz: 1754834360f2ae46fc748ba2b74bbafd322765424ac93f0b58594dadd52974661810771ad22b2d5ceb1c59ea687ecc7fc8641e09212937ccfeca5f6c4ce5635e
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  module Redstruct
2
3
  # Main interface of the gem; this class should be used to build all Redstruct
3
4
  # objects, even when deserializing them.
@@ -33,6 +34,45 @@ module Redstruct
33
34
  return @namespace.nil? || key.start_with?(@namespace) ? key : "#{@namespace}:#{key}"
34
35
  end
35
36
 
37
+ # Iterates over the keys of this factory using the Redis scan command
38
+ # For more about the scan command, see https://redis.io/commands/scan
39
+ # @param [String] match will prepend the factory namespace to the match string; see the redis documentation for the syntax
40
+ # @param [Integer] count maximum number of items returned per iteration
41
+ # @param [Integer] max maximum number of iterations; if none given, could potentially never terminate
42
+ # @return [Enumerator::Lazy] if no block given, returns an enumerator that you can chain with others
43
+ def each(match: '*', count: nil, max: 10_000, &block)
44
+ options = { match: isolate(match) }
45
+ options[:count] = count.to_i unless count.nil?
46
+
47
+ enumerator = @connection.scan_each(options)
48
+ enumerator = enumerator.each_slice(count) unless count.nil?
49
+
50
+ # creates a temporary enumerator which limits the number of possible iterations, ensuring this eventually finishes
51
+ unless max.nil?
52
+ unbounded_enumerator = enumerator
53
+ enumerator = Enumerator.new do |yielder|
54
+ iterations = 0
55
+ loop do
56
+ yielder << unbounded_enumerator.next
57
+ iterations += 1
58
+ raise StopIteration if iterations == max
59
+ end
60
+ end
61
+ end
62
+
63
+ return enumerator unless block_given?
64
+ return enumerator.each(&block)
65
+ end
66
+
67
+ # Deletes all keys created by the factory. By defaults will iterate at most of 500 million keys
68
+ # @param [Hash] options accepts the options as given in each
69
+ # @see Redstruct::Factory#each
70
+ def delete_all(options = {})
71
+ return each({ match: '*', count: 500, max: 1_000_000 }.merge(options)) do |keys|
72
+ @connection.del(*keys)
73
+ end
74
+ end
75
+
36
76
  # :nocov:
37
77
 
38
78
  # Helper method for serialization
@@ -32,9 +32,9 @@ module Redstruct
32
32
  def expire_at(time, ms: false)
33
33
  if ms
34
34
  time = (time.to_f * 1000) if time.is_a?(Time)
35
- self.connection.pexpire_at(@key, time.to_i)
35
+ self.connection.pexpireat(@key, time.to_i)
36
36
  else
37
- self.connection.expire_at(@key, time.to_i)
37
+ self.connection.expireat(@key, time.to_i)
38
38
  end
39
39
  end
40
40
 
@@ -1,3 +1,3 @@
1
1
  module Redstruct
2
- VERSION = '0.1.5'.freeze
2
+ VERSION = '0.1.6'.freeze
3
3
  end
data/test/test_helper.rb CHANGED
@@ -1,4 +1,4 @@
1
1
  $LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
2
- require 'redis/data'
3
-
2
+ require 'bundler/setup'
3
+ require 'redstruct'
4
4
  require 'minitest/autorun'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: redstruct
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.5
4
+ version: 0.1.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nicolas Pepin-Perreault
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-12-09 00:00:00.000000000 Z
11
+ date: 2016-12-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: redis