redstruct 0.1.5 → 0.1.6
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 +4 -4
- data/lib/redstruct/factory.rb +40 -0
- data/lib/redstruct/types/struct.rb +2 -2
- data/lib/redstruct/version.rb +1 -1
- data/test/test_helper.rb +2 -2
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b037a49dda3d7e960996e6fbc0c9bbc5ffe6445c
|
4
|
+
data.tar.gz: 221f64d42c69a93802971c6e8ecf425dd598ac22
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 94c3c5363a1f04b83cb6438fb07b22df54528fbc51d2f2820a8ffc46c59684bde7fd19ddd1aa83045fa109a7c7e7f94a6d3ce89339b535d751216142873b0987
|
7
|
+
data.tar.gz: 1754834360f2ae46fc748ba2b74bbafd322765424ac93f0b58594dadd52974661810771ad22b2d5ceb1c59ea687ecc7fc8641e09212937ccfeca5f6c4ce5635e
|
data/lib/redstruct/factory.rb
CHANGED
@@ -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.
|
35
|
+
self.connection.pexpireat(@key, time.to_i)
|
36
36
|
else
|
37
|
-
self.connection.
|
37
|
+
self.connection.expireat(@key, time.to_i)
|
38
38
|
end
|
39
39
|
end
|
40
40
|
|
data/lib/redstruct/version.rb
CHANGED
data/test/test_helper.rb
CHANGED
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.
|
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-
|
11
|
+
date: 2016-12-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: redis
|