redis-prescription 2.1.0 → 2.3.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
  SHA256:
3
- metadata.gz: 617a2c55e0d763f97983c56f3e7c7fbea30b4c999736a0eb8eaa4f38dab3a684
4
- data.tar.gz: 16ab341290e6ee88abe15d0c0ee5523b1aaa1ab7b0228e05c9650ff4b861cf52
3
+ metadata.gz: fd1b8f036fcc8230f39b8df81688c9026fd2e65d3e5a825d6d1233a9ba7b9093
4
+ data.tar.gz: f60221b43f1ddbaa96d57212f8a1e849a94daa9c4d018c90aee7e68d6b9c7df4
5
5
  SHA512:
6
- metadata.gz: 654c70a9fda3e076291c0c5339cde768c430c4d960d434fedf9e3bf7e8aaab5d4ea280a1be3a8d554015b09fd8adec26a4f2349ee169cd43e3139ce2b9b6badd
7
- data.tar.gz: ce8112a9aa153b41e05e4e327dbcb6b6bf62abd120a96dad1eacbf818e747899abd7615bf975484850cad540cd4669764e320ce7a07e07d447a371397fe33c55
6
+ metadata.gz: 11d25b6dc569ed64cab7d439b7688102549a20e714c8a6ff2abfe7a2ccdb91a0fce7097089fd08c196b36b53ca7bcaae149edb0fb3272ec210f95efbcc5134e8
7
+ data.tar.gz: 386d2fbc0b0104e183c3c58ca871dd0120efe313ea7ece14904137c67139d97d82accc8b8537a0a9887e875596b2b08ec128ce52b73aca534387f873e73e4db9
data/README.adoc CHANGED
@@ -31,20 +31,30 @@ script.call(redis, keys: [:xxx]) # => 123
31
31
  ----
32
32
 
33
33
 
34
- == Supported Ruby Versions
34
+ == Compatibility
35
35
 
36
36
  This library aims to support and is tested against:
37
37
 
38
38
  * https://www.ruby-lang.org[Ruby]
39
+ ** MRI 2.7.x
39
40
  ** MRI 3.0.x
40
41
  ** MRI 3.1.x
42
+ ** MRI 3.2.x
41
43
  * https://redis.io[Redis Server]
42
44
  ** 6.2.x
43
45
  ** 7.0.x
44
46
  * https://github.com/redis/redis-rb[redis-rb]
47
+ ** 4.1.x
48
+ ** 4.2.x
49
+ ** 4.3.x
50
+ ** 4.4.x
51
+ ** 4.5.x
52
+ ** 4.6.x
45
53
  ** 4.7.x
46
54
  ** 4.8.x
47
55
  ** 5.0.x
56
+ * https://github.com/resque/redis-namespace[redis-namespace]
57
+ ** 1.10.x
48
58
  * https://github.com/redis-rb/redis-client[redis-client]
49
59
  ** 0.12.x
50
60
  ** 0.13.x
@@ -63,7 +73,8 @@ patches in a timely fashion. If critical issues for a particular implementation
63
73
  exist at the time of a major release, support for that Ruby version may be
64
74
  dropped.
65
75
 
66
- Same rules apply to *Redis Server*, *redis-rb*, and *redis-client* support.
76
+ The same applies to *Redis Server*, *redis-rb*, *redis-namespace*,
77
+ and *redis-client* support.
67
78
 
68
79
 
69
80
  == Similar Projects
@@ -14,6 +14,10 @@ class RedisPrescription
14
14
  @redis = redis
15
15
  end
16
16
 
17
+ def adapter_name
18
+ "redis"
19
+ end
20
+
17
21
  def eval(script, keys, argv)
18
22
  @redis.eval(script, keys, argv)
19
23
  rescue ::Redis::CommandError => e
@@ -17,6 +17,10 @@ class RedisPrescription
17
17
  @redis = redis
18
18
  end
19
19
 
20
+ def adapter_name
21
+ "redis-client"
22
+ end
23
+
20
24
  def eval(script, keys, argv)
21
25
  @redis.call("EVAL", script, keys.size, *keys, *argv)
22
26
  rescue ::RedisClient::CommandError => e
@@ -0,0 +1,39 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "../errors"
4
+
5
+ class RedisPrescription
6
+ module Adapters
7
+ # redis-namespace adapter
8
+ class RedisNamespace
9
+ def self.adapts?(redis)
10
+ defined?(::Redis::Namespace) && redis.is_a?(::Redis::Namespace)
11
+ end
12
+
13
+ def initialize(redis)
14
+ @redis = redis
15
+ end
16
+
17
+ def adapter_name
18
+ "redis-namespace"
19
+ end
20
+
21
+ def eval(script, keys, argv)
22
+ @redis.eval(script, keys, argv)
23
+ rescue ::Redis::CommandError => e
24
+ raise CommandError, e.message
25
+ end
26
+
27
+ def evalsha(digest, keys, argv)
28
+ @redis.evalsha(digest, keys, argv)
29
+ rescue ::Redis::CommandError => e
30
+ raise CommandError, e.message
31
+ end
32
+
33
+ def purge!
34
+ @redis.redis.script("flush")
35
+ @redis.redis.flushdb
36
+ end
37
+ end
38
+ end
39
+ end
@@ -2,6 +2,7 @@
2
2
 
3
3
  require_relative "./adapters/redis"
4
4
  require_relative "./adapters/redis_client"
5
+ require_relative "./adapters/redis_namespace"
5
6
 
6
7
  class RedisPrescription
7
8
  # @api internal
@@ -10,6 +11,7 @@ class RedisPrescription
10
11
  def [](redis)
11
12
  return Adapters::Redis.new(redis) if Adapters::Redis.adapts?(redis)
12
13
  return Adapters::RedisClient.new(redis) if Adapters::RedisClient.adapts?(redis)
14
+ return Adapters::RedisNamespace.new(redis) if Adapters::RedisNamespace.adapts?(redis)
13
15
 
14
16
  raise TypeError, "Unsupported redis client: #{redis.class}"
15
17
  end
@@ -33,7 +33,7 @@ class RedisPrescription
33
33
  (?::\s\h+,\son\s@[^:]+:\d+\.)? # Redis 7.0
34
34
  )
35
35
  \z
36
- }x
36
+ }x.freeze
37
37
  private_constant :LUA_ERROR_MESSAGE
38
38
  # rubocop:enable Layout/LineLength
39
39
 
@@ -2,5 +2,5 @@
2
2
 
3
3
  class RedisPrescription
4
4
  # Gem version.
5
- VERSION = "2.1.0"
5
+ VERSION = "2.3.0"
6
6
  end
@@ -44,21 +44,13 @@ class RedisPrescription
44
44
  # @raise [ScriptError] if script execution failed
45
45
  # @return depends on the script
46
46
  def call(redis, keys: EMPTY_LIST, argv: EMPTY_LIST)
47
- unpool(redis) { |r| evalsha_with_fallback(r, keys, argv) }
47
+ evalsha_with_fallback(Adapters[redis], keys, argv)
48
48
  rescue CommandError => e
49
49
  raise ScriptError.new(e.message, @source)
50
50
  end
51
51
 
52
52
  private
53
53
 
54
- def unpool(redis)
55
- if redis.respond_to?(:with)
56
- redis.with { |r| yield Adapters[r] }
57
- else
58
- yield Adapters[redis]
59
- end
60
- end
61
-
62
54
  def evalsha_with_fallback(redis, keys, argv)
63
55
  redis.evalsha(@digest, keys, argv)
64
56
  rescue CommandError => e
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: redis-prescription
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.1.0
4
+ version: 2.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alexey Zapparov
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2023-04-05 00:00:00.000000000 Z
11
+ date: 2023-04-07 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: |
14
14
  Preloads (and reloads when needed, e.g. when scripts were flushed away)
@@ -26,6 +26,7 @@ files:
26
26
  - lib/redis_prescription/adapters.rb
27
27
  - lib/redis_prescription/adapters/redis.rb
28
28
  - lib/redis_prescription/adapters/redis_client.rb
29
+ - lib/redis_prescription/adapters/redis_namespace.rb
29
30
  - lib/redis_prescription/errors.rb
30
31
  - lib/redis_prescription/version.rb
31
32
  homepage: https://gitlab.com/ixti/redis-prescription
@@ -35,7 +36,7 @@ metadata:
35
36
  homepage_uri: https://gitlab.com/ixti/redis-prescription
36
37
  source_code_uri: https://gitlab.com/ixti/redis-prescription
37
38
  bug_tracker_uri: https://gitlab.com/ixti/redis-prescription/issues
38
- changelog_uri: https://gitlab.com/ixti/redis-prescription/blob/v2.1.0/CHANGES.md
39
+ changelog_uri: https://gitlab.com/ixti/redis-prescription/blob/v2.3.0/CHANGES.md
39
40
  rubygems_mfa_required: 'true'
40
41
  post_install_message:
41
42
  rdoc_options: []
@@ -45,7 +46,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
45
46
  requirements:
46
47
  - - ">="
47
48
  - !ruby/object:Gem::Version
48
- version: '3.0'
49
+ version: '2.7'
49
50
  required_rubygems_version: !ruby/object:Gem::Requirement
50
51
  requirements:
51
52
  - - ">="