redis-promise 0.1.0 → 0.1.2
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/CHANGELOG.md +13 -0
- data/lib/redis/promise/resolver.rb +15 -8
- data/lib/redis/promise/resque.rb +20 -2
- data/lib/redis/promise/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 29ae6ae3cc2cef2bb8b373a7eb43c4b3903c6ff82da18c71940023cd7ce9575b
|
|
4
|
+
data.tar.gz: 8ac4be637cf3f9c6a2c3ad23c621d22197913d4a5c58347382a270ffbb41ea20
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: db0b24c5c5594008a7e37e2cc0a2d7b3bbd21a0cb69f06e397482847dfa32841e01ba4162ac235fe7820868d1214d004835644ad1fd203176401d6851b881f22
|
|
7
|
+
data.tar.gz: a36e9b9628a1ef8c7087a87965562faf2d74e1fe1c72fb419f5eae2f710e85485e0c1b360b79c3ebc205e8b3ecae8bab37cfa69cbbc954d002607224c975e9ba
|
data/CHANGELOG.md
CHANGED
|
@@ -12,6 +12,19 @@ Add changes in new features here. Do not change the gem's version in pull/merge
|
|
|
12
12
|
### Changes
|
|
13
13
|
-
|
|
14
14
|
|
|
15
|
+
## [0.1.2] - 22.05.2026
|
|
16
|
+
|
|
17
|
+
[Diff](https://github.com/Verseth/ruby-redis-promise/compare/v0.1.1...v0.1.2)
|
|
18
|
+
|
|
19
|
+
- Use `expire` method in `Redis::Promise::Resque`
|
|
20
|
+
|
|
21
|
+
## [0.1.1] - 22.05.2026
|
|
22
|
+
|
|
23
|
+
[Diff](https://github.com/Verseth/ruby-redis-promise/compare/v0.1.0...v0.1.1)
|
|
24
|
+
|
|
25
|
+
- Add optional `expire:` arguments to `resolve` and `reject` methods in `Redis::Promise::Resolver`
|
|
26
|
+
- Add an overridable `expire` method under `Redis::Promise::Resque`
|
|
27
|
+
|
|
15
28
|
## [0.1.0] - 22.05.2026
|
|
16
29
|
|
|
17
30
|
[Diff](https://github.com/Verseth/ruby-redis-promise/compare/v0.0.0...v0.1.0)
|
|
@@ -21,26 +21,33 @@ class Redis
|
|
|
21
21
|
# Resolve the promise with the given value.
|
|
22
22
|
# The value gets serialized to JSON using `to_json`.
|
|
23
23
|
#
|
|
24
|
-
|
|
25
|
-
|
|
24
|
+
# There is an optional argument `expire:` that determines
|
|
25
|
+
# the amount of seconds after which the key-value will get automatically deleted from redis.
|
|
26
|
+
#
|
|
27
|
+
#: (top, ?expire: Integer?) -> void
|
|
28
|
+
def resolve(value, expire: nil)
|
|
26
29
|
serialized = { value: value }.to_json
|
|
27
|
-
push(serialized)
|
|
30
|
+
push(serialized, expire)
|
|
28
31
|
end
|
|
29
32
|
|
|
30
33
|
# Reject the promise with the given value.
|
|
31
34
|
# The value gets serialized to JSON using `to_json`.
|
|
32
35
|
#
|
|
33
|
-
|
|
34
|
-
|
|
36
|
+
# There is an optional argument `expire:` that determines
|
|
37
|
+
# the amount of seconds after which the key-value will get automatically deleted from redis.
|
|
38
|
+
#
|
|
39
|
+
#: (top, ?expire: Integer?) -> void
|
|
40
|
+
def reject(err, expire: nil)
|
|
35
41
|
serialized = { err: err }.to_json
|
|
36
|
-
push(serialized)
|
|
42
|
+
push(serialized, expire)
|
|
37
43
|
end
|
|
38
44
|
|
|
39
45
|
private
|
|
40
46
|
|
|
41
|
-
#: (String) -> void
|
|
42
|
-
def push(serialized)
|
|
47
|
+
#: (String, Integer?) -> void
|
|
48
|
+
def push(serialized, expire)
|
|
43
49
|
@redis.rpush(@key, serialized)
|
|
50
|
+
@redis.expire(@key, expire) if expire
|
|
44
51
|
end
|
|
45
52
|
end
|
|
46
53
|
end
|
data/lib/redis/promise/resque.rb
CHANGED
|
@@ -13,9 +13,22 @@ class Redis
|
|
|
13
13
|
|
|
14
14
|
# @requires_ancestor: Kernel
|
|
15
15
|
module ClassMethods
|
|
16
|
+
# Returns a custom redis connection that will be used in promises
|
|
17
|
+
# and resolvers.
|
|
18
|
+
#
|
|
19
|
+
# By default it uses `Resque.redis`
|
|
20
|
+
#
|
|
16
21
|
#: -> Redis
|
|
17
22
|
def promise_redis = ::Resque.redis
|
|
18
23
|
|
|
24
|
+
# The amount of time after which the resolved/rejected value will
|
|
25
|
+
# get deleted from redis.
|
|
26
|
+
#
|
|
27
|
+
# By default `nil` which means it will never be deleted.
|
|
28
|
+
#
|
|
29
|
+
#: -> Integer?
|
|
30
|
+
def expire = nil
|
|
31
|
+
|
|
19
32
|
#: (*top) -> Promise
|
|
20
33
|
def enqueue(*args)
|
|
21
34
|
promise = Promise.new(promise_redis)
|
|
@@ -27,6 +40,11 @@ class Redis
|
|
|
27
40
|
#: (String, *untyped) -> void
|
|
28
41
|
def perform(promise_key, *args); end
|
|
29
42
|
|
|
43
|
+
# Defines the body of the job.
|
|
44
|
+
#
|
|
45
|
+
# Returned value will be used to resolve the promise.
|
|
46
|
+
# Any thrown errors are caught and used to reject the promise.
|
|
47
|
+
#
|
|
30
48
|
#: { (untyped) -> void } -> void
|
|
31
49
|
def run(&block)
|
|
32
50
|
define_singleton_method :perform do |promise_key, *args|
|
|
@@ -34,9 +52,9 @@ class Redis
|
|
|
34
52
|
|
|
35
53
|
begin
|
|
36
54
|
result = block.call(*args)
|
|
37
|
-
promise.resolve(result)
|
|
55
|
+
promise.resolve(result, expire: expire)
|
|
38
56
|
rescue StandardError => e
|
|
39
|
-
promise.reject("[#{e.class}]: #{e.message}")
|
|
57
|
+
promise.reject("[#{e.class}]: #{e.message}", expire: expire)
|
|
40
58
|
end
|
|
41
59
|
end
|
|
42
60
|
end
|