sidekiq_smart_cache 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/sidekiq_smart_cache/redis.rb +44 -17
- data/lib/sidekiq_smart_cache/result.rb +1 -1
- data/lib/sidekiq_smart_cache/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e5e2eaeccb56ff1b361713b28c59b5535ba4dcb03ce09892b78829452733e204
|
4
|
+
data.tar.gz: 7d2223177c94a71ff9d00aa8eb7a37ecb80b6c8c5777c7d5321043220563d730
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5f2d87f31936b45cb6636536117d8b4625efd7f180d41b3b3fb1b8182adca8af567896809ae0991bb29babf63abd9a06f2bb439cc894b2f2c16757181ae0db7a
|
7
|
+
data.tar.gz: 399039ca0b02a6818d291f02295e0e9bf42ebe0cc33aea2fb846094287328c33b75198a15f8ca10a6abfbf49ed586341a5e34f6c4168cffcc5f0ab56c570833a
|
@@ -1,6 +1,6 @@
|
|
1
1
|
module SidekiqSmartCache
|
2
2
|
BLOCKING_COMMANDS = %i[ brpop ].freeze
|
3
|
-
COMMANDS = BLOCKING_COMMANDS + %i[
|
3
|
+
COMMANDS = BLOCKING_COMMANDS + %i[get set lpush expire flushdb del ttl].freeze
|
4
4
|
|
5
5
|
ERROR_TO_CATCH = if defined?(::RedisClient)
|
6
6
|
::RedisClient::CommandError
|
@@ -14,7 +14,7 @@ module SidekiqSmartCache
|
|
14
14
|
end
|
15
15
|
|
16
16
|
def job_completion_key(key)
|
17
|
-
key
|
17
|
+
"#{key}/done"
|
18
18
|
end
|
19
19
|
|
20
20
|
def send_done_message(key)
|
@@ -25,31 +25,60 @@ module SidekiqSmartCache
|
|
25
25
|
def wait_for_done_message(key, timeout)
|
26
26
|
return true if defined?(Sidekiq::Testing) && Sidekiq::Testing.inline?
|
27
27
|
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
28
|
+
return unless brpop(job_completion_key(key), timeout: timeout.to_i)
|
29
|
+
|
30
|
+
# log_msg("got done message for #{key}")
|
31
|
+
send_done_message(key) # put it back for any other readers
|
32
|
+
true
|
33
33
|
end
|
34
34
|
|
35
35
|
def log_msg(msg) # WIP all this
|
36
36
|
Rails.logger.info("#{Time.now.iso8601(3)} #{Thread.current[:name]} redis #{msg}")
|
37
37
|
end
|
38
38
|
|
39
|
-
|
40
|
-
|
41
|
-
|
39
|
+
# In support of syntax like redis.set('foo', 'bar', nx: true, ex: 60)
|
40
|
+
# the new client wants that called like redis.set('foo', 'bar', 'NX', 'EX', '60')
|
41
|
+
def arrayify_args(args)
|
42
|
+
out = []
|
43
|
+
args.each do |arg|
|
44
|
+
if arg.is_a?(Hash)
|
45
|
+
arg.each do |kw, val|
|
46
|
+
# nx: true becomes 'NX'
|
47
|
+
if val == true
|
48
|
+
out << kw.upcase.to_s
|
49
|
+
elsif val
|
50
|
+
# ex: 60 becomes ['EX', '60']
|
51
|
+
out << kw.upcase.to_s
|
52
|
+
out << val.to_s
|
53
|
+
end
|
54
|
+
end
|
55
|
+
else
|
56
|
+
out << arg
|
57
|
+
end
|
58
|
+
end
|
59
|
+
out.presence
|
60
|
+
end
|
61
|
+
|
62
|
+
# Defining methods like `redis.set('foo', 'bar')`
|
63
|
+
COMMANDS.each do |name|
|
64
|
+
define_method(name) do |*args|
|
65
|
+
@pool.with do |r|
|
42
66
|
retryable = true
|
43
67
|
begin
|
44
68
|
# log_msg("#{name} #{args}")
|
45
|
-
if r.
|
46
|
-
|
47
|
-
|
69
|
+
if defined?(::Redis) && r.is_a?(::Redis)
|
70
|
+
if r.respond_to?(name)
|
71
|
+
# old redis gem implements methods including `brpop` and `flusdb`
|
72
|
+
r.send(name, *args)
|
73
|
+
else
|
74
|
+
r.call(name.to_s.upcase, *args)
|
75
|
+
end
|
48
76
|
elsif BLOCKING_COMMANDS.include? name
|
49
77
|
# support redis-client semantics
|
50
|
-
make_blocking_call(r, name,
|
78
|
+
make_blocking_call(r, name, *args)
|
51
79
|
else
|
52
|
-
|
80
|
+
# Translate keyword args to new style array on RedisClient (even wrapped by Sidekiq)
|
81
|
+
r.send(name, *arrayify_args(args))
|
53
82
|
end
|
54
83
|
# stolen from sidekiq - Thanks Mike!
|
55
84
|
# Quietly consume this one and return nil
|
@@ -63,8 +92,6 @@ module SidekiqSmartCache
|
|
63
92
|
end
|
64
93
|
raise
|
65
94
|
end
|
66
|
-
else
|
67
|
-
super
|
68
95
|
end
|
69
96
|
end
|
70
97
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sidekiq_smart_cache
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Bill Kirtley
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-
|
11
|
+
date: 2023-12-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: sidekiq
|
@@ -77,7 +77,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
77
77
|
- !ruby/object:Gem::Version
|
78
78
|
version: '0'
|
79
79
|
requirements: []
|
80
|
-
rubygems_version: 3.
|
80
|
+
rubygems_version: 3.4.1
|
81
81
|
signing_key:
|
82
82
|
specification_version: 4
|
83
83
|
summary: Cache objects in redis, generated with thundering herd prevention via sidekiq.
|