redlics 0.1.9 → 0.2.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
- SHA1:
3
- metadata.gz: d0b6f9912012f2d12cbf81290ff72c26bdd49049
4
- data.tar.gz: d7a9c1c243581911669e4e972f7fc087ad6a240e
2
+ SHA256:
3
+ metadata.gz: 7516e95ed940d5b1ef0c3b5057877fee5513df08184748e5cbe89a6433b4cf81
4
+ data.tar.gz: 3f21b371b547d3b3b12ae69435793f3172d7e93e30cbcd862dd3443bee33b062
5
5
  SHA512:
6
- metadata.gz: bd4973305a3682c412d506f194c789e71d3b862e01f7223bd810dc5d12589ff4fc8ada741a3da3033916e6a5971216c9654c23d3e2e168841a0805ef87244283
7
- data.tar.gz: 309cb16e5f92297b665653cd3c80f7daa6e4124cbf381dd3fc1795fdcc43e7f62dff97fbb706192ab88b20ca973e396a71ada380e8234cc41de476f4f7ad8d9e
6
+ metadata.gz: f22958454df88403c508ebe652d885036b4db7044535fd4e44ec9c2970ead853969949fcbf6f3e196e6919c7903559fa9c8decc3067304e705f6dd0a77985d8b
7
+ data.tar.gz: 8c1485dd295b7fa33c397947390633b53f52ada35205b6ca2e30a352fe42c87950fc7c467ed605c10c243f2a9129f31d00d2b98b2c102c0e4b4bee16b650fcb4
data/.travis.yml CHANGED
@@ -5,10 +5,11 @@ cache: bundler
5
5
  before_install:
6
6
  - gem update --remote bundler
7
7
  rvm:
8
- - 2.0.0
9
- - 2.1
10
- - 2.2
11
- - 2.3.0
8
+ - 2.3
9
+ - 2.4
10
+ - 2.5
11
+ - 2.6
12
+ - 2.7
12
13
  - jruby-9.0.0.0
13
14
  - ruby-head
14
15
  - jruby-head
data/Gemfile CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  source 'https://rubygems.org'
2
4
 
3
5
  # Specify your gem's dependencies in redlics.gemspec
data/README.md CHANGED
@@ -3,10 +3,9 @@
3
3
  [![Gem Version](https://badge.fury.io/rb/redlics.svg)](https://rubygems.org/gems/redlics)
4
4
  [![Gem](https://img.shields.io/gem/dt/redlics.svg?maxAge=2592000)](https://rubygems.org/gems/redlics)
5
5
  [![Build Status](https://secure.travis-ci.org/phlegx/redlics.svg?branch=master)](https://travis-ci.org/phlegx/redlics)
6
- [![Code Climate](http://img.shields.io/codeclimate/github/phlegx/redlics.svg)](https://codeclimate.com/github/phlegx/redlics)
7
- [![Inline Docs](http://inch-ci.org/github/phlegx/redlics.svg?branch=master)](http://inch-ci.org/github/phlegx/redlics)
8
- [![Dependency Status](https://gemnasium.com/phlegx/redlics.svg)](https://gemnasium.com/phlegx/redlics)
9
- [![License](https://img.shields.io/github/license/phlegx/redlics.svg)](http://opensource.org/licenses/MIT)
6
+ [![Code Climate](https://codeclimate.com/github/phlegx/redlics.svg)](https://codeclimate.com/github/phlegx/redlics)
7
+ [![Inline Docs](https://inch-ci.org/github/phlegx/redlics.svg?branch=master)](https://inch-ci.org/github/phlegx/redlics)
8
+ [![License](https://img.shields.io/github/license/phlegx/redlics.svg)](https://opensource.org/licenses/MIT)
10
9
 
11
10
  Record millions of tracks and counts consuming low memory! Redlics is a gem for Redis analytics with tracks (using bitmaps) and counts (using buckets) encoding numbers in Redis keys and values.
12
11
 
@@ -403,5 +402,4 @@ Keys in Redis look like this:
403
402
 
404
403
  The MIT License
405
404
 
406
- Copyright (c) 2017 Phlegx Systems OG
407
-
405
+ Copyright (c) 2022 Phlegx Systems OG
data/Rakefile CHANGED
@@ -1,9 +1,9 @@
1
- require 'rake/testtask'
1
+ # frozen_string_literal: true
2
2
 
3
+ require 'rake/testtask'
3
4
 
4
5
  Rake::TestTask.new do |t|
5
6
  t.pattern = 'test/**/*_test.rb'
6
7
  end
7
8
 
8
-
9
9
  task default: :test
@@ -1,14 +1,13 @@
1
- module Redlics
1
+ # frozen_string_literal: true
2
2
 
3
+ module Redlics
3
4
  # Redlics constants.
4
5
  LUA_CACHE = Hash.new { |h, k| h[k] = Hash.new }
5
6
  LUA_SCRIPT = File.expand_path('../lua/script.lua', __FILE__).freeze
6
7
  CONTEXTS = { counter: { short: :c, long: :counter }, tracker: { short: :t, long: :tracker }, operation: { short: :o, long: :operation } }.freeze
7
8
 
8
-
9
9
  # Configuration class
10
10
  class Config
11
-
12
11
  # Initialization with default configuration.
13
12
  #
14
13
  # Configure Redis:
@@ -48,7 +47,6 @@ module Redlics
48
47
  )
49
48
  end
50
49
 
51
-
52
50
  # Send missing methods to the OpenStruct configuration.
53
51
  #
54
52
  # @param method [String] the missing method name
@@ -57,6 +55,5 @@ module Redlics
57
55
  def method_missing(method, *args, &block)
58
56
  @config.send(method, *args, &block)
59
57
  end
60
-
61
58
  end
62
59
  end
@@ -1,16 +1,14 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'connection_pool'
2
4
  require 'redis'
3
5
  require 'redis/namespace'
4
6
 
5
-
6
7
  module Redlics
7
-
8
8
  # Connection namespace
9
9
  module Connection
10
-
11
10
  extend self
12
11
 
13
-
14
12
  # Create a new connection pool for Redis connection.
15
13
  #
16
14
  # @param options [Hash] configuration options
@@ -21,7 +19,6 @@ module Redlics
21
19
  end
22
20
  end
23
21
 
24
-
25
22
  private
26
23
 
27
24
  # Set connection pool options.
@@ -33,7 +30,6 @@ module Redlics
33
30
  timeout: options[:pool_timeout] }
34
31
  end
35
32
 
36
-
37
33
  # Build Redis connection with options.
38
34
  #
39
35
  # @param options [Hash] configuration options
@@ -49,7 +45,6 @@ module Redlics
49
45
  end
50
46
  end
51
47
 
52
-
53
48
  # Client options provided by redis-rb
54
49
  # @see https://github.com/redis/redis-rb/blob/master/lib/redis.rb
55
50
  #
@@ -74,6 +69,5 @@ module Redlics
74
69
  opts[:driver] ||= 'ruby'
75
70
  opts
76
71
  end
77
-
78
72
  end
79
73
  end
@@ -1,14 +1,13 @@
1
- module Redlics
1
+ # frozen_string_literal: true
2
2
 
3
+ module Redlics
3
4
  # Counter class
4
5
  module Counter
5
-
6
6
  # Context constant for given class.
7
7
  CONTEXT = Redlics::CONTEXTS[:counter].freeze
8
8
 
9
9
  extend self
10
10
 
11
-
12
11
  # Count for a given event and object id with options.
13
12
  #
14
13
  # @param *args [Array] list of arguments for count
@@ -19,7 +18,6 @@ module Redlics
19
18
  count_with_args(*args)
20
19
  end
21
20
 
22
-
23
21
  private
24
22
 
25
23
  # Count with hash.
@@ -38,7 +36,6 @@ module Redlics
38
36
  end
39
37
  end
40
38
 
41
-
42
39
  # Count with hash.
43
40
  #
44
41
  # @param [&Block] a block with configuration options
@@ -48,7 +45,6 @@ module Redlics
48
45
  count_with_hash(options.to_h)
49
46
  end
50
47
 
51
-
52
48
  # Count with hash.
53
49
  #
54
50
  # @param *args [Array] list of arguments for count
@@ -59,7 +55,6 @@ module Redlics
59
55
  count_with_hash(options)
60
56
  end
61
57
 
62
-
63
58
  # Count by hash.
64
59
  #
65
60
  # @param options [Hash] configuration options
@@ -75,7 +70,6 @@ module Redlics
75
70
  end
76
71
  end
77
72
 
78
-
79
73
  # Count by key.
80
74
  #
81
75
  # @param options [Hash] configuration options
@@ -90,6 +84,5 @@ module Redlics
90
84
  end
91
85
  end
92
86
  end
93
-
94
87
  end
95
88
  end
@@ -1,21 +1,19 @@
1
- module Redlics
1
+ # frozen_string_literal: true
2
2
 
3
+ module Redlics
3
4
  # Exception namespace
4
5
  module Exception
5
-
6
6
  # Error Pattern namespace
7
7
  module ErrorPatterns
8
8
  NOSCRIPT = /^NOSCRIPT/.freeze
9
9
  end
10
10
 
11
-
12
11
  # Lua Range Error class
13
12
  #
14
13
  # Maximal Lua stack size for the method `unpack` is by default 8000.
15
14
  # To change this parameter in Redis an own make and build of Redis is needed.
16
15
  # @see https://github.com/antirez/redis/blob/3.2/deps/lua/src/luaconf.h
17
16
  class LuaRangeError < StandardError;
18
-
19
17
  # Initialization with default error message.
20
18
  #
21
19
  # @param msg [String] the error message
@@ -23,8 +21,6 @@ module Redlics
23
21
  def initialize(msg = 'Too many keys (max. 8000 keys defined by LUAI_MAXCSTACK)')
24
22
  super(msg)
25
23
  end
26
-
27
24
  end
28
-
29
25
  end
30
26
  end
@@ -1,11 +1,10 @@
1
- module Redlics
1
+ # frozen_string_literal: true
2
2
 
3
+ module Redlics
3
4
  # Granularity namespace
4
5
  module Granularity
5
-
6
6
  extend self
7
7
 
8
-
9
8
  # Validate granularities by given context.
10
9
  #
11
10
  # @param context [Hash] the hash of a context defined in Redlics::CONTEXTS
@@ -17,7 +16,6 @@ module Redlics
17
16
  check(granularities) || default(context)
18
17
  end
19
18
 
20
-
21
19
  # Get default granularities by given context.
22
20
  #
23
21
  # @param context [Hash] the hash of a context defined in Redlics::CONTEXTS
@@ -26,7 +24,6 @@ module Redlics
26
24
  check(Redlics.config["#{context[:long]}_granularity"]) || [Redlics.config.granularities.keys.first]
27
25
  end
28
26
 
29
-
30
27
  private
31
28
 
32
29
  # Check if granularities are defined in the configuration.
@@ -47,6 +44,5 @@ module Redlics
47
44
  end
48
45
  checked.any? ? checked : nil
49
46
  end
50
-
51
47
  end
52
48
  end
data/lib/redlics/key.rb CHANGED
@@ -1,11 +1,10 @@
1
- module Redlics
1
+ # frozen_string_literal: true
2
2
 
3
+ module Redlics
3
4
  # Key namespace
4
5
  module Key
5
-
6
6
  extend self
7
7
 
8
-
9
8
  # Construct the key name with given parameters.
10
9
  #
11
10
  # @param context [Hash] the hash of a context defined in Redlics::CONTEXTS
@@ -27,7 +26,6 @@ module Redlics
27
26
  key
28
27
  end
29
28
 
30
-
31
29
  # Construct an array with all keys of a time frame in a given granularity.
32
30
  #
33
31
  # @param context [Hash] the hash of a context defined in Redlics::CONTEXTS
@@ -46,7 +44,6 @@ module Redlics
46
44
  end
47
45
  end
48
46
 
49
-
50
47
  # Prepend namespace to a key.
51
48
  #
52
49
  # @param key [String] the key name
@@ -57,7 +54,6 @@ module Redlics
57
54
  "#{Redlics.config.namespace}#{Redlics.config.separator}#{key}"
58
55
  end
59
56
 
60
-
61
57
  # Encode a number with a mapping table.
62
58
  #
63
59
  # @param number [Integer] the number to encode
@@ -74,7 +70,6 @@ module Redlics
74
70
  encoded
75
71
  end
76
72
 
77
-
78
73
  # Decode a number with a mapping table.
79
74
  #
80
75
  # @param string [String] the string to encode
@@ -91,7 +86,6 @@ module Redlics
91
86
  decoded.to_i
92
87
  end
93
88
 
94
-
95
89
  # Check if a key exists in Redis.
96
90
  #
97
91
  # @param string [String] the key name to check
@@ -100,7 +94,6 @@ module Redlics
100
94
  Redlics.redis { |r| r.exists(key) }
101
95
  end
102
96
 
103
-
104
97
  # Check if Redlics can bucketize.
105
98
  #
106
99
  # @param context [Hash] the hash of a context defined in Redlics::CONTEXTS
@@ -110,7 +103,6 @@ module Redlics
110
103
  context[:long] == :counter && Redlics.config.bucket && !options[:id].nil?
111
104
  end
112
105
 
113
-
114
106
  # Create a unique operation key in Redis.
115
107
  # @return [String] the created unique operation key
116
108
  def unique_namespace
@@ -128,7 +120,6 @@ module Redlics
128
120
  end
129
121
  end
130
122
 
131
-
132
123
  private
133
124
 
134
125
  # Create a operation key.
@@ -137,7 +128,6 @@ module Redlics
137
128
  "#{Redlics::CONTEXTS[:operation][:short]}#{Redlics.config.separator}#{SecureRandom.uuid}"
138
129
  end
139
130
 
140
-
141
131
  # Get the time format pattern of a granularity.
142
132
  #
143
133
  # @param granularity [Symbol] existing granularity
@@ -147,7 +137,6 @@ module Redlics
147
137
  past.strftime(Redlics.config.granularities[granularity][:pattern])
148
138
  end
149
139
 
150
-
151
140
  # Encode ids in event names.
152
141
  #
153
142
  # @param event [String] event name with eventual Redis namespace separator
@@ -156,7 +145,6 @@ module Redlics
156
145
  event.to_s.split(Redlics.config.separator).map { |v| v.match(/\A\d+\z/) ? encode(v) : v }.join(Redlics.config.separator)
157
146
  end
158
147
 
159
-
160
148
  # Bucketize key name with id.
161
149
  #
162
150
  # @param key [String] key name
@@ -172,7 +160,6 @@ module Redlics
172
160
  ["#{key}#{Redlics.config.separator}#{bucket}", value]
173
161
  end
174
162
 
175
-
176
163
  # Unbucketize key name with id. Encode the id if configured to encode.
177
164
  #
178
165
  # @param key [String] key name
@@ -183,7 +170,6 @@ module Redlics
183
170
  "#{key}#{Redlics.config.separator}#{id}"
184
171
  end
185
172
 
186
-
187
173
  # Defined encode map.
188
174
  # @return [Hash] the encode map with numbers as keys
189
175
  def encode_map
@@ -200,7 +186,6 @@ module Redlics
200
186
  '90' => '`', '91' => '~', '92' => 'ä', '93' => 'Ä', '94' => 'ü', '95' => 'Ü', '96' => 'ö', '97' => 'Ö', '98' => 'é', '99' => 'É' }).freeze
201
187
  end
202
188
 
203
-
204
189
  # Defined decode map.
205
190
  # @return [Hash] the decode map with numbers as values
206
191
  def decode_map
@@ -217,7 +202,6 @@ module Redlics
217
202
  '`' => '90', '~' => '91', 'ä' => '92', 'Ä' => '93', 'ü' => '94', 'Ü' => '95', 'ö' => '96', 'Ö' => '97', 'é' => '98', 'É' => '99' }).freeze
218
203
  end
219
204
 
220
-
221
205
  # Replace defined separator in configuration from the encode map.
222
206
  #
223
207
  # @param map [Hash] encode map hash
@@ -230,7 +214,6 @@ module Redlics
230
214
  map
231
215
  end
232
216
 
233
-
234
217
  # Replace defined separator in configuration from the decode map.
235
218
  #
236
219
  # @param map [Hash] decode map hash
@@ -242,6 +225,5 @@ module Redlics
242
225
  end
243
226
  map
244
227
  end
245
-
246
228
  end
247
229
  end
@@ -1,8 +1,8 @@
1
- module Redlics
1
+ # frozen_string_literal: true
2
2
 
3
+ module Redlics
3
4
  # Operators namespace
4
5
  module Operators
5
-
6
6
  # AND (&) operator.
7
7
  #
8
8
  # @param query [Redlics::Query] Redlics query object
@@ -11,7 +11,6 @@ module Redlics
11
11
  Query::Operation.new('AND', [self, query])
12
12
  end
13
13
 
14
-
15
14
  # OR (|) operator.
16
15
  #
17
16
  # @param query [Redlics::Query] Redlics query object
@@ -21,7 +20,6 @@ module Redlics
21
20
  end
22
21
  alias_method :+, :|
23
22
 
24
-
25
23
  # XOR (^) operator.
26
24
  #
27
25
  # @param query [Redlics::Query] Redlics query object
@@ -30,7 +28,6 @@ module Redlics
30
28
  Query::Operation.new('XOR', [self, query])
31
29
  end
32
30
 
33
-
34
31
  # NOT (-, ~) operator.
35
32
  # @return [Redlics::Query::Operation] a Redlics query operation object
36
33
  def -@()
@@ -38,7 +35,6 @@ module Redlics
38
35
  end
39
36
  alias_method :~@, :-@
40
37
 
41
-
42
38
  # MINUS (-) operator.
43
39
  #
44
40
  # @param query [Redlics::Query] Redlics query object
@@ -46,6 +42,5 @@ module Redlics
46
42
  def -(query)
47
43
  Query::Operation.new('MINUS', [self, query])
48
44
  end
49
-
50
45
  end
51
46
  end
@@ -1,17 +1,15 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Redlics
2
4
  class Query
3
-
4
5
  # Operation class
5
6
  class Operation
6
-
7
7
  # Include Redlics operators.
8
8
  include Redlics::Operators
9
9
 
10
-
11
10
  # Gives read access to the listed instance variables.
12
11
  attr_reader :namespaces
13
12
 
14
-
15
13
  # Initialization of a query operation object.
16
14
  #
17
15
  # @param operator [String] operator to calculate
@@ -25,7 +23,6 @@ module Redlics
25
23
  ObjectSpace.define_finalizer(self, self.class.finalize(namespaces)) if Redlics.config.auto_clean
26
24
  end
27
25
 
28
-
29
26
  # Get or process tracks on Redis.
30
27
  # @return [Integer] tracks result of given query operation
31
28
  def tracks
@@ -34,7 +31,6 @@ module Redlics
34
31
  )
35
32
  end
36
33
 
37
-
38
34
  # Get or process track bits on Redis.
39
35
  # @return [String] key of track bits result
40
36
  def track_bits
@@ -53,7 +49,6 @@ module Redlics
53
49
  )
54
50
  end
55
51
 
56
-
57
52
  # Check if object id exists in track bits.
58
53
  #
59
54
  # @param [Integer] the object id to check
@@ -62,7 +57,6 @@ module Redlics
62
57
  Redlics.redis { |r| r.getbit(@track_bits || traverse, id.to_i) } == 1
63
58
  end
64
59
 
65
-
66
60
  # Reset processed data (also operation keys on Redis).
67
61
  #
68
62
  # @param space [Symbol] define space to reset
@@ -82,17 +76,14 @@ module Redlics
82
76
  return true
83
77
  end
84
78
 
85
-
86
79
  # Check if query operation is a leaf in the binary tree.
87
80
  # @return [Boolean] true if a leaf, false if not
88
81
  def is_leaf?
89
82
  is_a?(Redlics::Query::Operation) && @track_bits.nil?
90
83
  end
91
84
 
92
-
93
85
  # Singleton class
94
86
  class << self
95
-
96
87
  # Finalize query operation called from garbage collector.
97
88
  #
98
89
  # @param namespaces [Array] list of created operation keys in Redis
@@ -102,7 +93,6 @@ module Redlics
102
93
  proc { reset_redis_namespaces(namespaces) }
103
94
  end
104
95
 
105
-
106
96
  # Reset Redis created namespace keys.
107
97
  #
108
98
  # @param namespaces [Array] list of created operation keys in Redis
@@ -111,13 +101,10 @@ module Redlics
111
101
  def reset_redis_namespaces(namespaces)
112
102
  Redlics.redis { |r| r.del(namespaces) } if namespaces.any?
113
103
  end
114
-
115
104
  end
116
105
 
117
-
118
106
  private
119
107
 
120
-
121
108
  # Traverse query operation binary tree and calculate operation leafs.
122
109
  # @return [String] result operation key in Redis
123
110
  def traverse
@@ -129,7 +116,6 @@ module Redlics
129
116
  track_bits
130
117
  end
131
118
  end
132
-
133
119
  end
134
120
  end
135
121
  end
data/lib/redlics/query.rb CHANGED
@@ -1,17 +1,14 @@
1
- module Redlics
1
+ # frozen_string_literal: true
2
2
 
3
+ module Redlics
3
4
  # Query class
4
5
  class Query
5
-
6
-
7
6
  # Include Redlics operators.
8
7
  include Redlics::Operators
9
8
 
10
-
11
9
  # Gives read access to the listed instance variables.
12
10
  attr_reader :namespaces
13
11
 
14
-
15
12
  # Initialization of a query object
16
13
  #
17
14
  # @param event [String] event name with eventual Redis namespace separator
@@ -29,7 +26,6 @@ module Redlics
29
26
  ObjectSpace.define_finalizer(self, self.class.finalize(namespaces)) if Redlics.config.auto_clean
30
27
  end
31
28
 
32
-
33
29
  # Get or process counts on Redis.
34
30
  # @return [Integer] count result of given query
35
31
  def counts
@@ -40,14 +36,12 @@ module Redlics
40
36
  )
41
37
  end
42
38
 
43
-
44
39
  # Get or process tracks on Redis.
45
40
  # @return [Integer] tracks result of given query
46
41
  def tracks
47
42
  @tracks ||= Redlics.redis { |r| r.bitcount(track_bits) }
48
43
  end
49
44
 
50
-
51
45
  # Get or process track bits on Redis.
52
46
  # @return [String] key of track bits result
53
47
  def track_bits
@@ -60,7 +54,6 @@ module Redlics
60
54
  )
61
55
  end
62
56
 
63
-
64
57
  # Check if object id exists in track bits.
65
58
  # @return [Boolean] true if exists, false if not
66
59
  # @return [NilClass] nil if no object id is given
@@ -68,7 +61,6 @@ module Redlics
68
61
  @exists ||= @options[:id] ? Redlics.redis { |r| r.getbit(track_bits, @options[:id]) } == 1 : nil
69
62
  end
70
63
 
71
-
72
64
  # Get or process counts and plot.
73
65
  #
74
66
  # @return [Hash] with date times and counts
@@ -85,7 +77,6 @@ module Redlics
85
77
  nil
86
78
  end
87
79
 
88
-
89
80
  # Get or process tracks and plot.
90
81
  #
91
82
  # @return [Hash] with date times and counts
@@ -102,7 +93,6 @@ module Redlics
102
93
  nil
103
94
  end
104
95
 
105
-
106
96
  # Get or process counts and show keys to analyze.
107
97
  # @return [Array] list of keys to analyze
108
98
  def realize_counts!
@@ -113,7 +103,6 @@ module Redlics
113
103
  )
114
104
  end
115
105
 
116
-
117
106
  # Get or process tracks and show keys to analyze.
118
107
  # @return [Array] list of keys to analyze
119
108
  def realize_tracks!
@@ -124,7 +113,6 @@ module Redlics
124
113
  )
125
114
  end
126
115
 
127
-
128
116
  # Reset processed data (also operation keys on Redis).
129
117
  #
130
118
  # @param space [Symbol] define space to reset
@@ -152,7 +140,6 @@ module Redlics
152
140
  return true
153
141
  end
154
142
 
155
-
156
143
  # Check if query is a leaf. A query is always a leaf.
157
144
  # This method is required for query operations.
158
145
  # @return [Boolean] true
@@ -160,10 +147,8 @@ module Redlics
160
147
  true
161
148
  end
162
149
 
163
-
164
150
  # Singleton class
165
151
  class << self
166
-
167
152
  # Short query access to analyze data.
168
153
  #
169
154
  # @param *args [Array] list of arguments of the query
@@ -180,7 +165,6 @@ module Redlics
180
165
  query
181
166
  end
182
167
 
183
-
184
168
  # Finalize query called from garbage collector.
185
169
  #
186
170
  # @param namespaces [Array] list of created operation keys in Redis
@@ -190,7 +174,6 @@ module Redlics
190
174
  proc { reset_redis_namespaces(namespaces) }
191
175
  end
192
176
 
193
-
194
177
  # Reset Redis created namespace keys.
195
178
  #
196
179
  # @param namespaces [Array] list of created operation keys in Redis
@@ -199,10 +182,8 @@ module Redlics
199
182
  def reset_redis_namespaces(namespaces)
200
183
  Redlics.redis { |r| r.del(namespaces) } if namespaces.any?
201
184
  end
202
-
203
185
  end
204
186
 
205
-
206
187
  private
207
188
 
208
189
  # Format plot result with time objects as keys.
@@ -220,7 +201,6 @@ module Redlics
220
201
  result
221
202
  end
222
203
 
223
-
224
204
  # Reset track bits (also operation key on Redis).
225
205
  # @return [NilClass] nil
226
206
  def reset_track_bits
@@ -228,7 +208,5 @@ module Redlics
228
208
  @namespaces.delete(@track_bits_namespace)
229
209
  @track_bits, @track_bits_namespace = nil, nil
230
210
  end
231
-
232
211
  end
233
212
  end
234
-
@@ -1,12 +1,11 @@
1
- module Redlics
1
+ # frozen_string_literal: true
2
2
 
3
+ module Redlics
3
4
  # Time Frame class
4
5
  class TimeFrame
5
-
6
6
  # Gives read access to the listed instance variables.
7
7
  attr_reader :from, :to, :granularity
8
8
 
9
-
10
9
  # Initialization of a time frame object.
11
10
  #
12
11
  # @param context [Hash] the hash of a context defined in Redlics::CONTEXTS
@@ -22,7 +21,6 @@ module Redlics
22
21
  @granularity = Granularity.validate(context, options[:granularity]).first
23
22
  end
24
23
 
25
-
26
24
  # Construct keys by time frame steps.
27
25
  # @return [Array] keys
28
26
  def splat
@@ -33,7 +31,6 @@ module Redlics
33
31
  end
34
32
  end
35
33
 
36
-
37
34
  private
38
35
 
39
36
  # Initialize time frames `from` and `to` by time.
@@ -45,7 +42,6 @@ module Redlics
45
42
  [time.beginning_of_day, time.end_of_day]
46
43
  end
47
44
 
48
-
49
45
  # Initialize time frames `from` and `to` by symbol.
50
46
  #
51
47
  # @param symbol [Symbol] a time span
@@ -76,7 +72,6 @@ module Redlics
76
72
  end
77
73
  end
78
74
 
79
-
80
75
  # Initialize time frames `from` and `to` by hash.
81
76
  #
82
77
  # @param hash [Hash] a time hash with keys `from` and `to`
@@ -87,7 +82,6 @@ module Redlics
87
82
  hash[:to] && hash[:to].is_a?(String) && Time.parse(hash[:to]) || hash[:to] || Time.now ]
88
83
  end
89
84
 
90
-
91
85
  # Initialize time frames `from` and `to` by hash.
92
86
  #
93
87
  # @param range [Range] a time range
@@ -97,7 +91,6 @@ module Redlics
97
91
  init_with_hash({ from: range.first, to: range.last }, context)
98
92
  end
99
93
 
100
-
101
94
  # Get default granularity by given context.
102
95
  #
103
96
  # @param context [Hash] the hash of a context defined in Redlics::CONTEXTS
@@ -105,6 +98,5 @@ module Redlics
105
98
  def default(context)
106
99
  Redlics.config.granularities[Granularity.default(context).first][:step].ago
107
100
  end
108
-
109
101
  end
110
102
  end
@@ -1,14 +1,13 @@
1
- module Redlics
1
+ # frozen_string_literal: true
2
2
 
3
+ module Redlics
3
4
  # Tracker class
4
5
  module Tracker
5
-
6
6
  # Context constant for given class.
7
7
  CONTEXT = Redlics::CONTEXTS[:tracker].freeze
8
8
 
9
9
  extend self
10
10
 
11
-
12
11
  # Track for a given event and object id with options.
13
12
  #
14
13
  # @param *args [Array] list of arguments for track
@@ -19,7 +18,6 @@ module Redlics
19
18
  track_with_args(*args)
20
19
  end
21
20
 
22
-
23
21
  private
24
22
 
25
23
  # Track with hash.
@@ -38,7 +36,6 @@ module Redlics
38
36
  end
39
37
  end
40
38
 
41
-
42
39
  # Track with hash.
43
40
  #
44
41
  # @param [&Block] a block with configuration options
@@ -48,7 +45,6 @@ module Redlics
48
45
  track_with_hash(options.to_h)
49
46
  end
50
47
 
51
-
52
48
  # Track with hash.
53
49
  #
54
50
  # @param *args [Array] list of arguments for track
@@ -61,6 +57,5 @@ module Redlics
61
57
  })
62
58
  track_with_hash(options)
63
59
  end
64
-
65
60
  end
66
61
  end
@@ -1,4 +1,6 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # Redlics version.
2
4
  module Redlics
3
- VERSION = '0.1.9'
5
+ VERSION = '0.2.0'
4
6
  end
data/lib/redlics.rb CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'active_support/core_ext/module/delegation'
2
4
  require 'active_support/time'
3
5
  require 'msgpack'
@@ -15,10 +17,8 @@ require 'redlics/operators'
15
17
  require 'redlics/query'
16
18
  require 'redlics/query/operation'
17
19
 
18
-
19
20
  # Redlics namespace
20
21
  module Redlics
21
-
22
22
  extend self
23
23
 
24
24
  # Delegate methods to right objects.
@@ -26,7 +26,6 @@ module Redlics
26
26
  delegate :track, to: Tracker
27
27
  delegate :analyze, to: Query
28
28
 
29
-
30
29
  # Get or initialize the Redis connection.
31
30
  # @return [Object] redis connection
32
31
  def redis
@@ -44,7 +43,6 @@ module Redlics
44
43
  end
45
44
  end
46
45
 
47
-
48
46
  # Load Lua script file and arguments in Redis.
49
47
  #
50
48
  # @param file [String] absolute path to the Lua script file
@@ -72,21 +70,18 @@ module Redlics
72
70
  end
73
71
  end
74
72
 
75
-
76
73
  # Get or initialize Redlics config.
77
74
  # @return [OpenStruct] Redlics configuration
78
75
  def config
79
76
  @config ||= Redlics::Config.new
80
77
  end
81
78
 
82
-
83
79
  # Set configuration of Redlics in a block.
84
80
  # @return [OpenStruct] Redlics configuration
85
81
  def configure
86
82
  yield config if block_given?
87
83
  end
88
84
 
89
-
90
85
  private
91
86
 
92
87
  # Get or initialize the Redis connection pool.
@@ -94,6 +89,4 @@ module Redlics
94
89
  def redis_pool
95
90
  @redis ||= Redlics::Connection.create(config.to_h)
96
91
  end
97
-
98
92
  end
99
-
data/redlics.gemspec CHANGED
@@ -1,9 +1,9 @@
1
- # coding: utf-8
2
- lib = File.expand_path('../lib', __FILE__)
1
+ # frozen_string_literal: true
2
+
3
+ lib = File.expand_path('lib', __dir__)
3
4
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
5
  require 'redlics/version'
5
6
 
6
-
7
7
  Gem::Specification.new do |spec|
8
8
  spec.name = 'redlics'
9
9
  spec.version = Redlics::VERSION
@@ -21,13 +21,13 @@ Gem::Specification.new do |spec|
21
21
  spec.test_files = Dir.glob('test/*_test.rb')
22
22
  spec.require_paths = ['lib']
23
23
 
24
- spec.required_ruby_version = '>= 2.0.0'
24
+ spec.required_ruby_version = '>= 2.3'
25
+ spec.add_dependency 'activesupport', '>= 5.2.8'
25
26
  spec.add_dependency 'connection_pool', '~> 2.2'
26
- spec.add_dependency 'redis', '~> 3.2'
27
+ spec.add_dependency 'msgpack', '>= 0.7.2'
28
+ spec.add_dependency 'redis', '~> 4.2'
27
29
  spec.add_dependency 'redis-namespace', '~> 1.5'
28
- spec.add_dependency 'activesupport', '>= 4.2', '< 5.2'
29
- spec.add_dependency 'msgpack', '>= 0.7.2', '< 2.0'
30
30
 
31
- spec.add_development_dependency 'rake', '~> 12.0'
32
31
  spec.add_development_dependency 'minitest', '~> 5.8'
32
+ spec.add_development_dependency 'rake', '~> 12.0'
33
33
  end
data/test/redlics_test.rb CHANGED
@@ -1,13 +1,11 @@
1
- # encoding: UTF-8
2
- require File.expand_path(File.join(File.dirname(__FILE__), 'test_helper'))
1
+ # frozen_string_literal: true
3
2
 
3
+ require File.expand_path(File.join(File.dirname(__FILE__), 'test_helper'))
4
4
 
5
5
  describe Redlics do
6
6
  subject { Redlics }
7
7
 
8
-
9
8
  it 'must respond positively' do
10
9
  subject.redis { |r| r.namespace }.must_equal Redlics.config.namespace
11
10
  end
12
-
13
11
  end
metadata CHANGED
@@ -1,125 +1,113 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: redlics
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.9
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Egon Zemmer
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-07-14 00:00:00.000000000 Z
11
+ date: 2022-06-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: connection_pool
14
+ name: activesupport
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - "~>"
17
+ - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: '2.2'
19
+ version: 5.2.8
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
- version: '2.2'
26
+ version: 5.2.8
27
27
  - !ruby/object:Gem::Dependency
28
- name: redis
28
+ name: connection_pool
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: '3.2'
33
+ version: '2.2'
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: '3.2'
40
+ version: '2.2'
41
41
  - !ruby/object:Gem::Dependency
42
- name: redis-namespace
42
+ name: msgpack
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - "~>"
45
+ - - ">="
46
46
  - !ruby/object:Gem::Version
47
- version: '1.5'
47
+ version: 0.7.2
48
48
  type: :runtime
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - "~>"
52
+ - - ">="
53
53
  - !ruby/object:Gem::Version
54
- version: '1.5'
54
+ version: 0.7.2
55
55
  - !ruby/object:Gem::Dependency
56
- name: activesupport
56
+ name: redis
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
- - - ">="
59
+ - - "~>"
60
60
  - !ruby/object:Gem::Version
61
61
  version: '4.2'
62
- - - "<"
63
- - !ruby/object:Gem::Version
64
- version: '5.2'
65
62
  type: :runtime
66
63
  prerelease: false
67
64
  version_requirements: !ruby/object:Gem::Requirement
68
65
  requirements:
69
- - - ">="
66
+ - - "~>"
70
67
  - !ruby/object:Gem::Version
71
68
  version: '4.2'
72
- - - "<"
73
- - !ruby/object:Gem::Version
74
- version: '5.2'
75
69
  - !ruby/object:Gem::Dependency
76
- name: msgpack
70
+ name: redis-namespace
77
71
  requirement: !ruby/object:Gem::Requirement
78
72
  requirements:
79
- - - ">="
80
- - !ruby/object:Gem::Version
81
- version: 0.7.2
82
- - - "<"
73
+ - - "~>"
83
74
  - !ruby/object:Gem::Version
84
- version: '2.0'
75
+ version: '1.5'
85
76
  type: :runtime
86
77
  prerelease: false
87
78
  version_requirements: !ruby/object:Gem::Requirement
88
79
  requirements:
89
- - - ">="
90
- - !ruby/object:Gem::Version
91
- version: 0.7.2
92
- - - "<"
80
+ - - "~>"
93
81
  - !ruby/object:Gem::Version
94
- version: '2.0'
82
+ version: '1.5'
95
83
  - !ruby/object:Gem::Dependency
96
- name: rake
84
+ name: minitest
97
85
  requirement: !ruby/object:Gem::Requirement
98
86
  requirements:
99
87
  - - "~>"
100
88
  - !ruby/object:Gem::Version
101
- version: '12.0'
89
+ version: '5.8'
102
90
  type: :development
103
91
  prerelease: false
104
92
  version_requirements: !ruby/object:Gem::Requirement
105
93
  requirements:
106
94
  - - "~>"
107
95
  - !ruby/object:Gem::Version
108
- version: '12.0'
96
+ version: '5.8'
109
97
  - !ruby/object:Gem::Dependency
110
- name: minitest
98
+ name: rake
111
99
  requirement: !ruby/object:Gem::Requirement
112
100
  requirements:
113
101
  - - "~>"
114
102
  - !ruby/object:Gem::Version
115
- version: '5.8'
103
+ version: '12.0'
116
104
  type: :development
117
105
  prerelease: false
118
106
  version_requirements: !ruby/object:Gem::Requirement
119
107
  requirements:
120
108
  - - "~>"
121
109
  - !ruby/object:Gem::Version
122
- version: '5.8'
110
+ version: '12.0'
123
111
  description: Redis analytics with tracks (using bitmaps) and counts (using buckets)encoding
124
112
  numbers in Redis keys and values.
125
113
  email:
@@ -162,15 +150,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
162
150
  requirements:
163
151
  - - ">="
164
152
  - !ruby/object:Gem::Version
165
- version: 2.0.0
153
+ version: '2.3'
166
154
  required_rubygems_version: !ruby/object:Gem::Requirement
167
155
  requirements:
168
156
  - - ">="
169
157
  - !ruby/object:Gem::Version
170
158
  version: '0'
171
159
  requirements: []
172
- rubyforge_project:
173
- rubygems_version: 2.5.2
160
+ rubygems_version: 3.2.24
174
161
  signing_key:
175
162
  specification_version: 4
176
163
  summary: Redis analytics with tracks and counts.