esse-redis_storage 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 1c05d60be8578e56e72f8eaa1ed86bd0e2ddc4155aa4e401b46f1baea2644887
4
+ data.tar.gz: fcf6aebf13c1dda145e8be6f1eab49a8f7fe70a4d5dd5e48be9d07c77e8ae712
5
+ SHA512:
6
+ metadata.gz: 153cb2cfa231b6f4657e779923db891e164a99f6c6401afaa5cae1b9c2e8893e2675cf26dc7cfc22f3d950ba04995b443c7a729a153ea2b457ef92c45edd5dcf
7
+ data.tar.gz: ff228cfae97984539f88920de7888df7809517d9c4a25aa2b842b530f06bb0a6864ecaf2c4db29cd0fff54060eac494c0c169f43fd0239d9a8a10c261d5f5dd6
data/.rubocop.yml ADDED
@@ -0,0 +1,26 @@
1
+ inherit_mode:
2
+ merge:
3
+ - Exclude
4
+
5
+ require:
6
+ - rubocop-performance
7
+ - rubocop-rspec
8
+ - standard/cop/block_single_line_braces
9
+
10
+ inherit_gem:
11
+ standard: config/base.yml
12
+
13
+ AllCops:
14
+ TargetRubyVersion: 2.5
15
+ SuggestExtensions: false
16
+ Exclude:
17
+ - "db/**/*"
18
+ - "tmp/**/*"
19
+ - "vendor/**/*"
20
+ NewCops: enable
21
+
22
+ RSpec/MultipleExpectations:
23
+ Enabled: false
24
+
25
+ RSpec/ExampleLength:
26
+ Enabled: false
data/CHANGELOG.md ADDED
@@ -0,0 +1,13 @@
1
+ # Changelog
2
+
3
+ All notable changes to this project will be documented in this file.
4
+
5
+ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
6
+
7
+ ## 0.0.2 - 2024-07-18
8
+ * The `Esse::RedisStorage::Queue.for` method now support both `repo:` and `attribute_name:` options.
9
+
10
+ ## 0.0.1 - 2024-07-03
11
+ The first release of the esse-redis_storage plugin
12
+ * Add `redis` and `redis_pool` configuration option to the `Esse::Config` class.
13
+ * `Esse::RedisStorage::Pool` class to handle the redis connection pool.
data/Gemfile ADDED
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "esse", git: "https://github.com/marcosgz/esse.git", branch: "main"
6
+ gem "esse-rspec"
7
+
8
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,112 @@
1
+ GIT
2
+ remote: https://github.com/marcosgz/esse.git
3
+ revision: ebbe8016650c2d090873a8799e8b127a39a592bf
4
+ branch: main
5
+ specs:
6
+ esse (0.2.6)
7
+ multi_json
8
+ thor (>= 0.19)
9
+
10
+ PATH
11
+ remote: .
12
+ specs:
13
+ esse-redis_storage (0.0.2)
14
+ esse (>= 0.2.4)
15
+ redis (>= 4.0.0)
16
+
17
+ GEM
18
+ remote: https://rubygems.org/
19
+ specs:
20
+ ast (2.4.2)
21
+ coderay (1.1.3)
22
+ connection_pool (2.4.1)
23
+ diff-lcs (1.5.1)
24
+ esse-rspec (0.0.6)
25
+ esse (>= 0.2.4)
26
+ rspec (>= 3)
27
+ json (2.7.2)
28
+ language_server-protocol (3.17.0.3)
29
+ lint_roller (1.1.0)
30
+ method_source (1.1.0)
31
+ multi_json (1.15.0)
32
+ parallel (1.25.1)
33
+ parser (3.3.3.0)
34
+ ast (~> 2.4.1)
35
+ racc
36
+ pry (0.14.2)
37
+ coderay (~> 1.1)
38
+ method_source (~> 1.0)
39
+ racc (1.8.0)
40
+ rainbow (3.1.1)
41
+ redis (5.2.0)
42
+ redis-client (>= 0.22.0)
43
+ redis-client (0.22.2)
44
+ connection_pool
45
+ regexp_parser (2.9.2)
46
+ rexml (3.3.1)
47
+ strscan
48
+ rspec (3.13.0)
49
+ rspec-core (~> 3.13.0)
50
+ rspec-expectations (~> 3.13.0)
51
+ rspec-mocks (~> 3.13.0)
52
+ rspec-core (3.13.0)
53
+ rspec-support (~> 3.13.0)
54
+ rspec-expectations (3.13.1)
55
+ diff-lcs (>= 1.2.0, < 2.0)
56
+ rspec-support (~> 3.13.0)
57
+ rspec-mocks (3.13.1)
58
+ diff-lcs (>= 1.2.0, < 2.0)
59
+ rspec-support (~> 3.13.0)
60
+ rspec-support (3.13.1)
61
+ rubocop (1.64.1)
62
+ json (~> 2.3)
63
+ language_server-protocol (>= 3.17.0)
64
+ parallel (~> 1.10)
65
+ parser (>= 3.3.0.2)
66
+ rainbow (>= 2.2.2, < 4.0)
67
+ regexp_parser (>= 1.8, < 3.0)
68
+ rexml (>= 3.2.5, < 4.0)
69
+ rubocop-ast (>= 1.31.1, < 2.0)
70
+ ruby-progressbar (~> 1.7)
71
+ unicode-display_width (>= 2.4.0, < 3.0)
72
+ rubocop-ast (1.31.3)
73
+ parser (>= 3.3.1.0)
74
+ rubocop-performance (1.21.1)
75
+ rubocop (>= 1.48.1, < 2.0)
76
+ rubocop-ast (>= 1.31.1, < 2.0)
77
+ rubocop-rspec (3.0.2)
78
+ rubocop (~> 1.61)
79
+ ruby-progressbar (1.13.0)
80
+ standard (1.37.0)
81
+ language_server-protocol (~> 3.17.0.2)
82
+ lint_roller (~> 1.0)
83
+ rubocop (~> 1.64.0)
84
+ standard-custom (~> 1.0.0)
85
+ standard-performance (~> 1.4)
86
+ standard-custom (1.0.2)
87
+ lint_roller (~> 1.0)
88
+ rubocop (~> 1.50)
89
+ standard-performance (1.4.0)
90
+ lint_roller (~> 1.1)
91
+ rubocop-performance (~> 1.21.0)
92
+ strscan (3.1.0)
93
+ thor (1.3.1)
94
+ unicode-display_width (2.5.0)
95
+
96
+ PLATFORMS
97
+ x86_64-linux
98
+
99
+ DEPENDENCIES
100
+ connection_pool
101
+ esse!
102
+ esse-redis_storage!
103
+ esse-rspec
104
+ pry
105
+ rspec
106
+ rubocop
107
+ rubocop-performance
108
+ rubocop-rspec
109
+ standard
110
+
111
+ BUNDLED WITH
112
+ 2.3.22
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024 Marcos G. Zimmermann
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,45 @@
1
+ # Esse redis-storage Plugin
2
+
3
+ <!-- Extends the [esse](https://github.com/marcosgz/esse) search to use [redis-storage](https://github.com/rails/redis-storage) as the default template engine. -->
4
+
5
+ This gems is a add-on for the [Esse](https://github.com/marcosgz/esse) search library that allows to use [redis-rb](https://github.com/redis/redis-rb) as the default storage engine for operations like async indexing using [esse-faktory](https://github.com/marcosgz/esse-faktory) or [esse-sidekiq](https://github.com/marcosgz/esse-sidekiq).
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'esse-redis_storage'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ ```bash
18
+ $ bundle install
19
+ ```
20
+
21
+ ## Configuration
22
+
23
+ This gem adds the `redis` configuration option to the `Esse::Config` class.
24
+
25
+ ```ruby
26
+ Esse.configure do |config|
27
+ config.redis = ConnectionPool.new(size: 10, timeout: 1) do
28
+ Redis.new(url: ENV.fetch('REDIS_URL', 'redis://0.0.0.0:6379'))
29
+ end
30
+ end
31
+ ```
32
+
33
+ ## Development
34
+
35
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake none` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
36
+
37
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
38
+
39
+ ## Contributing
40
+
41
+ Bug reports and pull requests are welcome on GitHub at https://github.com/marcosgz/esse-redis_storage.
42
+
43
+ ## License
44
+
45
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,4 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ task default: %i[]
@@ -0,0 +1,6 @@
1
+ services:
2
+ redis:
3
+ image: redis
4
+ command: redis-server
5
+ ports:
6
+ - 6379:6379
@@ -0,0 +1,19 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Esse
4
+ module RedisStorage
5
+ module Config
6
+ def self.included(base)
7
+ base.__send__(:include, InstanceMethods)
8
+ end
9
+
10
+ module InstanceMethods
11
+ attr_accessor :redis
12
+
13
+ def redis_pool
14
+ @redis_pool ||= Esse::RedisStorage::Pool.new(redis)
15
+ end
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,25 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Esse
4
+ module RedisStorage
5
+ class Pool
6
+ extend Forwardable
7
+ def_delegator :@connection, :with
8
+
9
+ module ConnectionPoolLike
10
+ def with
11
+ yield self
12
+ end
13
+ end
14
+
15
+ def initialize(connection)
16
+ if connection.respond_to?(:with)
17
+ @connection = connection
18
+ else
19
+ @connection = connection ? ::Redis.new(connection) : ::Redis.new
20
+ @connection.extend(ConnectionPoolLike)
21
+ end
22
+ end
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,90 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Esse
4
+ module RedisStorage
5
+ class Queue
6
+ include Enumerable
7
+ extend Forwardable
8
+ def_delegator :redis_connection, :with
9
+
10
+ GROUP = "queue"
11
+ SEPARATOR = ":"
12
+
13
+ attr_reader :name
14
+
15
+ def self.batch_id
16
+ SecureRandom.uuid
17
+ end
18
+
19
+ def self.for(repo:, attribute_name: nil)
20
+ name = [repo.index.index_name, repo.repo_name, attribute_name].compact.join(SEPARATOR)
21
+ new(name: name)
22
+ end
23
+
24
+ def initialize(name:)
25
+ @name = [Esse::RedisStorage::NAMESPACE, GROUP, name].compact.join(SEPARATOR)
26
+ end
27
+
28
+ # Enqueue a batch of ids to process
29
+ # @param id [String] The batch id
30
+ # @param values [Array<String>] The values of the batch
31
+ def enqueue(id: nil, values: [])
32
+ return if values.nil? || values.empty?
33
+
34
+ batch_id = id || self.class.batch_id
35
+ with do |conn|
36
+ conn.hset(name, batch_id, values.join(","))
37
+ end
38
+ batch_id
39
+ end
40
+
41
+ # Fetch and remove a batch of ids to process from the queue using batch_id
42
+ # @param batch_id [String] The batch id to fetch
43
+ # @yield [Array<String>] The values of the batch
44
+ def fetch(batch_id)
45
+ with do |conn|
46
+ values = conn.hget(name, batch_id)
47
+ return unless values
48
+
49
+ yield values.split(",")
50
+ conn.hdel(name, batch_id)
51
+ end
52
+ end
53
+
54
+ def delete(batch_id)
55
+ with do |conn|
56
+ conn.hdel(name, batch_id)
57
+ end
58
+ end
59
+
60
+ # Clear the queue
61
+ def clear
62
+ with do |conn|
63
+ conn.del(name)
64
+ end
65
+ end
66
+
67
+ # Get the size of the queue
68
+ # @return [Integer] The size of the queue
69
+ def size
70
+ with do |conn|
71
+ conn.hlen(name)
72
+ end
73
+ end
74
+
75
+ def each
76
+ with do |conn|
77
+ conn.hscan_each(name, count: 1000) do |batch_id, values|
78
+ yield batch_id, values.split(",")
79
+ end
80
+ end
81
+ end
82
+
83
+ private
84
+
85
+ def redis_connection
86
+ Esse.config.redis_pool
87
+ end
88
+ end
89
+ end
90
+ end
@@ -0,0 +1,36 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Esse
4
+ module RedisStorage
5
+ module QueueStats
6
+ KEY = "#{Esse::RedisStorage::NAMESPACE}:queues"
7
+
8
+ class << self
9
+ extend Forwardable
10
+ def_delegator :redis_connection, :with
11
+
12
+ def all
13
+ with { |conn| conn.smembers(KEY) }
14
+ end
15
+
16
+ def push(value)
17
+ with { |conn| conn.sadd(KEY, value) }
18
+ end
19
+
20
+ def delete(value)
21
+ with { |conn| conn.srem(KEY, value) }
22
+ end
23
+
24
+ def clear
25
+ with { |conn| conn.del(KEY) }
26
+ end
27
+
28
+ private
29
+
30
+ def redis_connection
31
+ Esse.config.redis_pool
32
+ end
33
+ end
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Esse
4
+ module RedisStorage
5
+ VERSION = "0.0.2"
6
+ end
7
+ end
@@ -0,0 +1,20 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "esse"
4
+ require "redis"
5
+ require "forwardable"
6
+ require "securerandom"
7
+
8
+ module Esse
9
+ module RedisStorage
10
+ NAMESPACE = "esse"
11
+ end
12
+ end
13
+
14
+ require_relative "redis_storage/version"
15
+ require_relative "redis_storage/config"
16
+ require_relative "redis_storage/pool"
17
+ require_relative "redis_storage/queue_stats"
18
+ require_relative "redis_storage/queue"
19
+
20
+ Esse::Config.__send__ :include, Esse::RedisStorage::Config
@@ -0,0 +1,3 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "esse/redis_storage"
@@ -0,0 +1,3 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "esse/redis_storage"
metadata ADDED
@@ -0,0 +1,188 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: esse-redis_storage
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.2
5
+ platform: ruby
6
+ authors:
7
+ - Marcos G. Zimmermann
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2024-07-18 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: esse
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: 0.2.4
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: 0.2.4
27
+ - !ruby/object:Gem::Dependency
28
+ name: redis
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: 4.0.0
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: 4.0.0
41
+ - !ruby/object:Gem::Dependency
42
+ name: connection_pool
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: pry
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rspec
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: standard
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: rubocop
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: rubocop-performance
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ - !ruby/object:Gem::Dependency
126
+ name: rubocop-rspec
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - ">="
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - ">="
137
+ - !ruby/object:Gem::Version
138
+ version: '0'
139
+ description: Add-on for the esse gem to be used with Redis as a storage backend.
140
+ email:
141
+ - mgzmaster@gmail.com
142
+ executables: []
143
+ extensions: []
144
+ extra_rdoc_files: []
145
+ files:
146
+ - ".rubocop.yml"
147
+ - CHANGELOG.md
148
+ - Gemfile
149
+ - Gemfile.lock
150
+ - LICENSE
151
+ - README.md
152
+ - Rakefile
153
+ - docker-compose.yml
154
+ - lib/esse-redis-storage.rb
155
+ - lib/esse-redis_storage.rb
156
+ - lib/esse/redis_storage.rb
157
+ - lib/esse/redis_storage/config.rb
158
+ - lib/esse/redis_storage/pool.rb
159
+ - lib/esse/redis_storage/queue.rb
160
+ - lib/esse/redis_storage/queue_stats.rb
161
+ - lib/esse/redis_storage/version.rb
162
+ homepage: https://github.com/marcosgz/esse-redis_storage
163
+ licenses:
164
+ - MIT
165
+ metadata:
166
+ homepage_uri: https://github.com/marcosgz/esse-redis_storage
167
+ source_code_uri: https://github.com/marcosgz/esse-redis_storage
168
+ changelog_uri: https://github.com/marcosgz/esse-redis_storage/blob/main/CHANGELOG.md
169
+ post_install_message:
170
+ rdoc_options: []
171
+ require_paths:
172
+ - lib
173
+ required_ruby_version: !ruby/object:Gem::Requirement
174
+ requirements:
175
+ - - ">="
176
+ - !ruby/object:Gem::Version
177
+ version: 2.7.0
178
+ required_rubygems_version: !ruby/object:Gem::Requirement
179
+ requirements:
180
+ - - ">="
181
+ - !ruby/object:Gem::Version
182
+ version: '0'
183
+ requirements: []
184
+ rubygems_version: 3.1.6
185
+ signing_key:
186
+ specification_version: 4
187
+ summary: Add-on for the esse gem to be used with Redis as a storage backend.
188
+ test_files: []