momento 0.1.0 → 0.4.9
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.release-please-manifest.json +3 -0
- data/.rubocop.yml +26 -1
- data/.ruby-version +1 -1
- data/.yardopts +2 -0
- data/CHANGELOG.md +119 -0
- data/CONTRIBUTING.md +6 -7
- data/Gemfile +1 -6
- data/Gemfile.lock +34 -24
- data/README.md +143 -38
- data/README.template.md +93 -0
- data/examples/.gitignore +1 -0
- data/examples/Gemfile +5 -0
- data/examples/README.md +34 -0
- data/examples/compact.rb +47 -0
- data/examples/example.rb +72 -0
- data/examples/file.rb +58 -0
- data/lib/README-generating-pb.txt +1 -1
- data/lib/momento/auth/credential_provider.rb +78 -0
- data/lib/momento/cache_client.rb +457 -0
- data/lib/momento/collection_ttl.rb +79 -0
- data/lib/momento/config/configuration.rb +16 -0
- data/lib/momento/config/configurations.rb +17 -0
- data/lib/momento/config/transport/grpc_configuration.rb +25 -0
- data/lib/momento/config/transport/static_transport_strategy.rb +12 -0
- data/lib/momento/config/transport/transport_strategy.rb +16 -0
- data/lib/momento/error/grpc_details.rb +38 -0
- data/lib/momento/error/transport_details.rb +20 -0
- data/lib/momento/error/types.rb +247 -0
- data/lib/momento/error.rb +54 -0
- data/lib/momento/error_builder.rb +50 -0
- data/lib/momento/exceptions.rb +7 -0
- data/lib/momento/generated/README.md +16 -0
- data/lib/momento/generated/auth_pb.rb +52 -0
- data/lib/momento/generated/auth_services_pb.rb +27 -0
- data/lib/momento/generated/cacheclient_pb.rb +203 -0
- data/lib/momento/generated/cacheclient_services_pb.rb +90 -0
- data/lib/momento/generated/cacheping_pb.rb +38 -0
- data/lib/momento/generated/cacheping_services_pb.rb +23 -0
- data/lib/momento/generated/cachepubsub_pb.rb +48 -0
- data/lib/momento/generated/cachepubsub_services_pb.rb +56 -0
- data/lib/momento/generated/common_pb.rb +44 -0
- data/lib/momento/generated/controlclient_pb.rb +72 -0
- data/lib/momento/generated/controlclient_services_pb.rb +35 -0
- data/lib/momento/generated/extensions_pb.rb +35 -0
- data/lib/momento/generated/generate_protos.sh +47 -0
- data/lib/momento/generated/leaderboard_pb.rb +56 -0
- data/lib/momento/generated/leaderboard_services_pb.rb +57 -0
- data/lib/momento/generated/permissionmessages_pb.rb +48 -0
- data/lib/momento/generated/token_pb.rb +43 -0
- data/lib/momento/generated/token_services_pb.rb +23 -0
- data/lib/momento/generated/webhook_pb.rb +49 -0
- data/lib/momento/generated/webhook_services_pb.rb +32 -0
- data/lib/momento/{create_cache_response.rb → response/control/create_cache_response.rb} +33 -24
- data/lib/momento/{delete_cache_response.rb → response/control/delete_cache_response.rb} +28 -21
- data/lib/momento/response/control/list_caches_response.rb +80 -0
- data/lib/momento/response/delete_response.rb +45 -0
- data/lib/momento/response/error.rb +10 -3
- data/lib/momento/response/get_response.rb +107 -0
- data/lib/momento/response/response.rb +67 -0
- data/lib/momento/response/response_builder.rb +18 -0
- data/lib/momento/response/set_response.rb +59 -0
- data/lib/momento/response/sort_order.rb +11 -0
- data/lib/momento/response/sorted_set/sorted_set_fetch_response.rb +107 -0
- data/lib/momento/response/sorted_set/sorted_set_put_element_response.rb +44 -0
- data/lib/momento/response/sorted_set/sorted_set_put_elements_response.rb +44 -0
- data/lib/momento/ttl.rb +48 -0
- data/lib/momento/version.rb +2 -1
- data/lib/momento.rb +6 -1
- data/momento.gemspec +6 -3
- data/release-please-config.json +15 -0
- data/sig/momento/auth/credential_provider.rbs +11 -0
- data/sig/momento/cache_client.rbs +12 -0
- data/sig/momento/collection_ttl.rbs +22 -0
- data/sig/momento/config/configuration.rbs +9 -0
- data/sig/momento/config/configurations.rbs +9 -0
- data/sig/momento/config/transport/grpc_configuration.rbs +7 -0
- data/sig/momento/config/transport/transport_strategy.rbs +7 -0
- data/sig/momento/list_caches_response.rbs +7 -0
- data/sig/momento/sorted_set_fetch_response.rbs +13 -0
- data/sig/momento/sorted_set_put_element_response.rbs +5 -0
- data/sig/momento/sorted_set_put_elements_response.rbs +5 -0
- metadata +127 -28
- data/examples/basic.rb +0 -45
- data/lib/momento/cacheclient_pb.rb +0 -332
- data/lib/momento/cacheclient_services_pb.rb +0 -42
- data/lib/momento/controlclient_pb.rb +0 -71
- data/lib/momento/controlclient_services_pb.rb +0 -29
- data/lib/momento/delete_response.rb +0 -33
- data/lib/momento/get_response.rb +0 -80
- data/lib/momento/list_caches_response.rb +0 -53
- data/lib/momento/response.rb +0 -17
- data/lib/momento/set_response.rb +0 -39
- data/lib/momento/simple_cache_client.rb +0 -204
@@ -1,39 +1,46 @@
|
|
1
|
-
|
2
|
-
|
1
|
+
require_relative '../error'
|
2
|
+
require_relative '../../generated/controlclient_pb'
|
3
3
|
|
4
4
|
module Momento
|
5
|
-
#
|
5
|
+
# A response from deleting a cache.
|
6
6
|
class DeleteCacheResponse < Response
|
7
|
-
#
|
8
|
-
#
|
9
|
-
#
|
10
|
-
# @return [Momento::DeleteCacheResponse]
|
11
|
-
# @raise [StandardError] when the exception is not recognized.
|
12
|
-
# @raise [TypeError] when the response is not recognized.
|
13
|
-
def self.from_block
|
14
|
-
response = yield
|
15
|
-
rescue GRPC::BadStatus => e
|
16
|
-
Error.new(grpc_exception: e)
|
17
|
-
else
|
18
|
-
raise TypeError unless response.is_a?(Momento::ControlClient::DeleteCacheResponse)
|
19
|
-
|
20
|
-
return Success.new
|
21
|
-
end
|
22
|
-
|
7
|
+
# Was the cache deleted?
|
8
|
+
# @return [Boolean]
|
23
9
|
def success?
|
24
10
|
false
|
25
11
|
end
|
26
12
|
|
27
|
-
#
|
13
|
+
# @private
|
28
14
|
class Error < DeleteCacheResponse
|
29
15
|
include ::Momento::Response::Error
|
30
16
|
end
|
31
17
|
|
32
|
-
#
|
18
|
+
# @private
|
33
19
|
class Success < DeleteCacheResponse
|
34
20
|
def success?
|
35
21
|
true
|
36
22
|
end
|
37
23
|
end
|
38
24
|
end
|
25
|
+
|
26
|
+
# @private
|
27
|
+
class DeleteCacheResponseBuilder < ResponseBuilder
|
28
|
+
# Build a Momento::DeleteCacheResponse from a block of code
|
29
|
+
# which returns a Momento::ControlClient::DeleteCacheResponse..
|
30
|
+
#
|
31
|
+
# @return [Momento::DeleteCacheResponse]
|
32
|
+
# @raise [StandardError] when the exception is not recognized.
|
33
|
+
# @raise [TypeError] when the response is not recognized.
|
34
|
+
def from_block
|
35
|
+
response = yield
|
36
|
+
rescue *RESCUED_EXCEPTIONS => e
|
37
|
+
DeleteCacheResponse::Error.new(
|
38
|
+
exception: e, context: context
|
39
|
+
)
|
40
|
+
else
|
41
|
+
raise TypeError unless response.is_a?(::MomentoProtos::ControlClient::PB__DeleteCacheResponse)
|
42
|
+
|
43
|
+
return DeleteCacheResponse::Success.new
|
44
|
+
end
|
45
|
+
end
|
39
46
|
end
|
@@ -0,0 +1,80 @@
|
|
1
|
+
require_relative '../error'
|
2
|
+
require_relative '../../generated/controlclient_pb'
|
3
|
+
|
4
|
+
module Momento
|
5
|
+
# A response from listing the caches.
|
6
|
+
class ListCachesResponse < Response
|
7
|
+
# Did it get a list of caches?
|
8
|
+
# @return [Boolean]
|
9
|
+
def success?
|
10
|
+
false
|
11
|
+
end
|
12
|
+
|
13
|
+
# The names of the caches.
|
14
|
+
# @return [Array,nil]
|
15
|
+
def cache_names
|
16
|
+
nil
|
17
|
+
end
|
18
|
+
|
19
|
+
# @!method to_s
|
20
|
+
# Displays the response and the list of cache names.
|
21
|
+
# The list of cache names will be truncated.
|
22
|
+
# @return [String]
|
23
|
+
|
24
|
+
# @private
|
25
|
+
class Success < ListCachesResponse
|
26
|
+
CACHE_NAMES_TO_DISPLAY = 5
|
27
|
+
|
28
|
+
# rubocop:disable Lint/MissingSuper
|
29
|
+
def initialize(grpc_response:)
|
30
|
+
@grpc_response = grpc_response
|
31
|
+
end
|
32
|
+
# rubocop:enable Lint/MissingSuper
|
33
|
+
|
34
|
+
def success?
|
35
|
+
true
|
36
|
+
end
|
37
|
+
|
38
|
+
def cache_names
|
39
|
+
@grpc_response.cache.map(&:cache_name)
|
40
|
+
end
|
41
|
+
|
42
|
+
def to_s
|
43
|
+
"#{super}: #{display_cache_names}"
|
44
|
+
end
|
45
|
+
|
46
|
+
private
|
47
|
+
|
48
|
+
def display_cache_names
|
49
|
+
display = cache_names&.take(CACHE_NAMES_TO_DISPLAY)&.join(", ")
|
50
|
+
cache_names&.size&.>(CACHE_NAMES_TO_DISPLAY) ? "#{display}, ..." : display.to_s
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
# @private
|
55
|
+
class Error < ListCachesResponse
|
56
|
+
include ::Momento::Response::Error
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
# @private
|
61
|
+
class ListCachesResponseBuilder < ResponseBuilder
|
62
|
+
# Build a Momento::ListCachesResponse from a block of code
|
63
|
+
# which returns a Momento::ControlClient::ListCachesResponse..
|
64
|
+
#
|
65
|
+
# @return [Momento::ListCachesResponse]
|
66
|
+
# @raise [StandardError] when the exception is not recognized.
|
67
|
+
# @raise [TypeError] when the response is not recognized.
|
68
|
+
def from_block
|
69
|
+
response = yield
|
70
|
+
rescue GRPC::BadStatus => e
|
71
|
+
ListCachesResponse::Error.new(
|
72
|
+
exception: e, context: context
|
73
|
+
)
|
74
|
+
else
|
75
|
+
raise TypeError unless response.is_a?(::MomentoProtos::ControlClient::PB__ListCachesResponse)
|
76
|
+
|
77
|
+
return ListCachesResponse::Success.new(grpc_response: response)
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
require_relative 'error'
|
2
|
+
require 'grpc'
|
3
|
+
require_relative '../generated/cacheclient_pb'
|
4
|
+
|
5
|
+
module Momento
|
6
|
+
# A response from deleting a key.
|
7
|
+
class DeleteResponse < Response
|
8
|
+
# Was the key deleted?
|
9
|
+
# @return [Boolean]
|
10
|
+
def success?
|
11
|
+
false
|
12
|
+
end
|
13
|
+
|
14
|
+
# @private
|
15
|
+
class Success < DeleteResponse
|
16
|
+
def success?
|
17
|
+
true
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
# @private
|
22
|
+
class Error < DeleteResponse
|
23
|
+
include Momento::Response::Error
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
# @private
|
28
|
+
class DeleteResponseBuilder < ResponseBuilder
|
29
|
+
# Build a Momento::DeleteResponse from a block of code
|
30
|
+
# which returns a Momento::CacheClient::DeleteResponse..
|
31
|
+
#
|
32
|
+
# @return [Momento::DeleteResponse]
|
33
|
+
# @raise [StandardError] when the exception is not recognized.
|
34
|
+
# @raise [TypeError] when the response is not recognized.
|
35
|
+
def from_block
|
36
|
+
response = yield
|
37
|
+
rescue *RESCUED_EXCEPTIONS => e
|
38
|
+
DeleteResponse::Error.new(exception: e, context: context)
|
39
|
+
else
|
40
|
+
raise TypeError unless response.is_a?(::MomentoProtos::CacheClient::PB__DeleteResponse)
|
41
|
+
|
42
|
+
DeleteResponse::Success.new
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
@@ -1,16 +1,23 @@
|
|
1
1
|
module Momento
|
2
2
|
class Response
|
3
3
|
# A module for responses which contain errors.
|
4
|
+
# @private
|
4
5
|
module Error
|
5
|
-
|
6
|
+
attr_reader :error
|
6
7
|
|
7
|
-
def initialize(
|
8
|
-
@
|
8
|
+
def initialize(exception:, context: {})
|
9
|
+
@error = Momento::ErrorBuilder.from_exception(
|
10
|
+
exception, context: context
|
11
|
+
).freeze
|
9
12
|
end
|
10
13
|
|
11
14
|
def error?
|
12
15
|
true
|
13
16
|
end
|
17
|
+
|
18
|
+
def to_s
|
19
|
+
"#{super}: #{error.message}"
|
20
|
+
end
|
14
21
|
end
|
15
22
|
end
|
16
23
|
end
|
@@ -0,0 +1,107 @@
|
|
1
|
+
require_relative 'error'
|
2
|
+
require_relative '../generated/cacheclient_pb'
|
3
|
+
|
4
|
+
module Momento
|
5
|
+
# A response containing the value retrieved from a cache.
|
6
|
+
class GetResponse < Response
|
7
|
+
# There was a value for the key.
|
8
|
+
# @return [Boolean]
|
9
|
+
def hit?
|
10
|
+
false
|
11
|
+
end
|
12
|
+
|
13
|
+
# There was no value for the key.
|
14
|
+
# @return [Boolean]
|
15
|
+
def miss?
|
16
|
+
false
|
17
|
+
end
|
18
|
+
|
19
|
+
# The gotten value, if any, as binary data: an ASCII_8BIT encoded frozen String.
|
20
|
+
#
|
21
|
+
# @return [String,nil] the value, if any, frozen and ASCII_8BIT encoded
|
22
|
+
def value_bytes
|
23
|
+
nil
|
24
|
+
end
|
25
|
+
|
26
|
+
# The gotten value, if any, as a UTF-8 string.
|
27
|
+
#
|
28
|
+
# @return [String,nil] the value, if any.
|
29
|
+
def value_string
|
30
|
+
nil
|
31
|
+
end
|
32
|
+
|
33
|
+
# @!method to_s
|
34
|
+
# Displays the response and the value, if any.
|
35
|
+
# A long value will be truncated.
|
36
|
+
# @return [String]
|
37
|
+
|
38
|
+
# @private
|
39
|
+
class Hit < GetResponse
|
40
|
+
# rubocop:disable Lint/MissingSuper
|
41
|
+
def initialize(grpc_response:)
|
42
|
+
@grpc_response = grpc_response
|
43
|
+
end
|
44
|
+
# rubocop:enable Lint/MissingSuper
|
45
|
+
|
46
|
+
def hit?
|
47
|
+
true
|
48
|
+
end
|
49
|
+
|
50
|
+
def value_bytes
|
51
|
+
@grpc_response.cache_body
|
52
|
+
end
|
53
|
+
|
54
|
+
def value_string
|
55
|
+
value_bytes.dup.force_encoding('UTF-8')
|
56
|
+
end
|
57
|
+
|
58
|
+
def to_s
|
59
|
+
"#{super}: #{display_string(value_string)}"
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
# @private
|
64
|
+
class Miss < GetResponse
|
65
|
+
def miss?
|
66
|
+
true
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
# @private
|
71
|
+
class Error < GetResponse
|
72
|
+
include Momento::Response::Error
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
# @private
|
77
|
+
class GetResponseBuilder < ResponseBuilder
|
78
|
+
# Build a Momento::GetResponse from a block of code
|
79
|
+
# which returns a Momento::ControlClient::GetResponse.
|
80
|
+
#
|
81
|
+
# @return [Momento::GetResponse]
|
82
|
+
# @raise [StandardError] when the exception is not recognized.
|
83
|
+
# @raise [TypeError] when the response is not recognized.
|
84
|
+
def from_block
|
85
|
+
response = yield
|
86
|
+
rescue *RESCUED_EXCEPTIONS => e
|
87
|
+
GetResponse::Error.new(exception: e, context: context)
|
88
|
+
else
|
89
|
+
from_response(response)
|
90
|
+
end
|
91
|
+
|
92
|
+
private
|
93
|
+
|
94
|
+
def from_response(response)
|
95
|
+
raise TypeError unless response.is_a?(MomentoProtos::CacheClient::PB__GetResponse)
|
96
|
+
|
97
|
+
case response.result
|
98
|
+
when :Hit
|
99
|
+
GetResponse::Hit.new(grpc_response: response)
|
100
|
+
when :Miss
|
101
|
+
GetResponse::Miss.new
|
102
|
+
else
|
103
|
+
raise "Unknown get result: #{response.result}"
|
104
|
+
end
|
105
|
+
end
|
106
|
+
end
|
107
|
+
end
|
@@ -0,0 +1,67 @@
|
|
1
|
+
require 'grpc'
|
2
|
+
require_relative 'error'
|
3
|
+
require_relative '../error'
|
4
|
+
require_relative '../error/grpc_details'
|
5
|
+
require_relative '../error/transport_details'
|
6
|
+
require_relative '../error_builder'
|
7
|
+
require_relative 'response_builder'
|
8
|
+
require_relative 'control/create_cache_response'
|
9
|
+
require_relative 'delete_response'
|
10
|
+
require_relative 'control/delete_cache_response'
|
11
|
+
require_relative 'get_response'
|
12
|
+
require_relative 'control/list_caches_response'
|
13
|
+
require_relative 'set_response'
|
14
|
+
require_relative 'sorted_set/sorted_set_put_element_response'
|
15
|
+
require_relative 'sorted_set/sorted_set_put_elements_response'
|
16
|
+
require_relative 'sorted_set/sorted_set_fetch_response'
|
17
|
+
|
18
|
+
module Momento
|
19
|
+
# The response from a Momento service request.
|
20
|
+
#
|
21
|
+
# {Momento::CacheClient} returns a response for both success
|
22
|
+
# and error, as well as other states. See the documenation for each
|
23
|
+
# type of response for more.
|
24
|
+
#
|
25
|
+
# You can always check for an error response with
|
26
|
+
# `response.error?` and get the error itself with `response.error`.
|
27
|
+
#
|
28
|
+
# `response.error` is an Exception and can be raised. It contains
|
29
|
+
# additional information about the error, see {Momento::Error} for
|
30
|
+
# more information.
|
31
|
+
#
|
32
|
+
# @see Momento::Error
|
33
|
+
class Response
|
34
|
+
MAX_STRING_DISPLAY_LENGTH = 32
|
35
|
+
private_constant :MAX_STRING_DISPLAY_LENGTH
|
36
|
+
|
37
|
+
# Returns the error portion of the response, if any.
|
38
|
+
#
|
39
|
+
# @return [Momento::Error, nil]
|
40
|
+
def error
|
41
|
+
nil
|
42
|
+
end
|
43
|
+
|
44
|
+
# Is the response an error?
|
45
|
+
#
|
46
|
+
# @return [Boolean]
|
47
|
+
def error?
|
48
|
+
false
|
49
|
+
end
|
50
|
+
|
51
|
+
# Displays the type of response and additional info, if any.
|
52
|
+
# @return [String]
|
53
|
+
def to_s
|
54
|
+
self.class.to_s
|
55
|
+
end
|
56
|
+
|
57
|
+
protected
|
58
|
+
|
59
|
+
def display_string(string, max_length: MAX_STRING_DISPLAY_LENGTH)
|
60
|
+
if string.length < max_length
|
61
|
+
string
|
62
|
+
else
|
63
|
+
"#{string[0, max_length]}..."
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
module Momento
|
2
|
+
# A superclass for building responses.
|
3
|
+
#
|
4
|
+
# @private
|
5
|
+
class ResponseBuilder
|
6
|
+
attr_accessor :context
|
7
|
+
|
8
|
+
RESCUED_EXCEPTIONS = ErrorBuilder::EXCEPTION_MAP.keys.freeze
|
9
|
+
|
10
|
+
def initialize(context: {})
|
11
|
+
@context = context
|
12
|
+
end
|
13
|
+
|
14
|
+
def from_block
|
15
|
+
raise NotImplementedError
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,59 @@
|
|
1
|
+
require_relative 'error'
|
2
|
+
require_relative '../generated/cacheclient_pb'
|
3
|
+
|
4
|
+
module Momento
|
5
|
+
# A response from setting a key.
|
6
|
+
class SetResponse < Response
|
7
|
+
# Was the key/value pair added to the cache?
|
8
|
+
# @return [Boolean]
|
9
|
+
def success?
|
10
|
+
false
|
11
|
+
end
|
12
|
+
|
13
|
+
# @private
|
14
|
+
class Success < SetResponse
|
15
|
+
attr_accessor :key, :value
|
16
|
+
|
17
|
+
# rubocop:disable Lint/MissingSuper
|
18
|
+
def initialize(key:, value:)
|
19
|
+
@key = key
|
20
|
+
@value = value
|
21
|
+
|
22
|
+
return
|
23
|
+
end
|
24
|
+
# rubocop:enable Lint/MissingSuper
|
25
|
+
|
26
|
+
def success?
|
27
|
+
true
|
28
|
+
end
|
29
|
+
|
30
|
+
def to_s
|
31
|
+
"#{super}: '#{display_string(key)}' = '#{display_string(value)}'"
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
# @private
|
36
|
+
class Error < SetResponse
|
37
|
+
include Momento::Response::Error
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
# @private
|
42
|
+
class SetResponseBuilder < ResponseBuilder
|
43
|
+
# Build a Momento::SetResponse from a block of code
|
44
|
+
# which returns a Momento::CacheClient::SetResponse..
|
45
|
+
#
|
46
|
+
# @return [Momento::SetResponse]
|
47
|
+
# @raise [StandardError] when the exception is not recognized.
|
48
|
+
# @raise [TypeError] when the response is not recognized.
|
49
|
+
def from_block
|
50
|
+
response = yield
|
51
|
+
rescue *RESCUED_EXCEPTIONS => e
|
52
|
+
SetResponse::Error.new(exception: e, context: context)
|
53
|
+
else
|
54
|
+
raise TypeError unless response.is_a?(::MomentoProtos::CacheClient::PB__SetResponse)
|
55
|
+
|
56
|
+
SetResponse::Success.new(key: context[:key], value: context[:value])
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
@@ -0,0 +1,107 @@
|
|
1
|
+
require_relative '../error'
|
2
|
+
require_relative '../../generated/cacheclient_pb'
|
3
|
+
|
4
|
+
module Momento
|
5
|
+
# A response containing the elements retrieved from a sorted set.
|
6
|
+
class SortedSetFetchResponse < Response
|
7
|
+
# The sorted set exists and any matching elements were fetched.
|
8
|
+
# @return [Boolean]
|
9
|
+
def hit?
|
10
|
+
false
|
11
|
+
end
|
12
|
+
|
13
|
+
# The sorted set does not exist.
|
14
|
+
# @return [Boolean]
|
15
|
+
def miss?
|
16
|
+
false
|
17
|
+
end
|
18
|
+
|
19
|
+
# The fetched values as UTF-8 Strings and their scores.
|
20
|
+
# @return [(Array[{ value: String, score: Float }] | nil)] the UTF-8 elements and their scores
|
21
|
+
def value_string_elements
|
22
|
+
nil
|
23
|
+
end
|
24
|
+
|
25
|
+
alias value value_string_elements
|
26
|
+
|
27
|
+
# The fetched values as ASCII_8BIT Strings and their scores.
|
28
|
+
# @return [(Array[{ value: String, score: Float }] | nil)] the ASCII_8BIT elements and their scores
|
29
|
+
def value_bytes_elements
|
30
|
+
nil
|
31
|
+
end
|
32
|
+
|
33
|
+
# @!method to_s
|
34
|
+
# Displays the response and the value, if any.
|
35
|
+
# A long value will be truncated.
|
36
|
+
# @return [String]
|
37
|
+
|
38
|
+
# @private
|
39
|
+
class Hit < SortedSetFetchResponse
|
40
|
+
# rubocop:disable Lint/MissingSuper
|
41
|
+
def initialize(grpc_response:)
|
42
|
+
@grpc_response = grpc_response
|
43
|
+
end
|
44
|
+
# rubocop:enable Lint/MissingSuper
|
45
|
+
|
46
|
+
def hit?
|
47
|
+
true
|
48
|
+
end
|
49
|
+
|
50
|
+
def value_string_elements
|
51
|
+
@grpc_response.elements.map do |element|
|
52
|
+
{ value: element.value.dup.force_encoding('UTF-8'), score: element.score }
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
alias value value_string_elements
|
57
|
+
|
58
|
+
def value_bytes_elements
|
59
|
+
@grpc_response.elements.map do |element|
|
60
|
+
{ value: element.value, score: element.score }
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
def to_s
|
65
|
+
"#{super}: #{display_string(value_string)}"
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
# @private
|
70
|
+
class Miss < SortedSetFetchResponse
|
71
|
+
def miss?
|
72
|
+
true
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
# @private
|
77
|
+
class Error < SortedSetFetchResponse
|
78
|
+
include Momento::Response::Error
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
# @private
|
83
|
+
class SortedSetFetchResponseBuilder < ResponseBuilder
|
84
|
+
# Build a Momento::SortedSetFetchResponse from a block of code
|
85
|
+
# which returns a MomentoProtos::CacheClient::PB__SortedSetFetchResponse.
|
86
|
+
#
|
87
|
+
# @return [Momento::SortedSetFetchResponse]
|
88
|
+
# @raise [StandardError] when the exception is not recognized.
|
89
|
+
# @raise [TypeError] when the response is not recognized.
|
90
|
+
def from_block
|
91
|
+
response = yield
|
92
|
+
rescue *RESCUED_EXCEPTIONS => e
|
93
|
+
SortedSetFetchResponse::Error.new(exception: e, context: context)
|
94
|
+
else
|
95
|
+
raise TypeError unless response.is_a?(MomentoProtos::CacheClient::PB__SortedSetFetchResponse)
|
96
|
+
|
97
|
+
case response.sorted_set
|
98
|
+
when :found
|
99
|
+
SortedSetFetchResponse::Hit.new(grpc_response: response.found.values_with_scores)
|
100
|
+
when :missing
|
101
|
+
SortedSetFetchResponse::Miss.new
|
102
|
+
else
|
103
|
+
raise "Unknown sorted set fetch result: #{response.sorted_set}"
|
104
|
+
end
|
105
|
+
end
|
106
|
+
end
|
107
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
require_relative '../error'
|
2
|
+
require_relative '../../generated/cacheclient_pb'
|
3
|
+
|
4
|
+
module Momento
|
5
|
+
# A response representing the result of a sorted set put element operation.
|
6
|
+
class SortedSetPutElementResponse < Response
|
7
|
+
# Was the element added to the sorted set?
|
8
|
+
# @return [Boolean]
|
9
|
+
def success?
|
10
|
+
false
|
11
|
+
end
|
12
|
+
|
13
|
+
# @private
|
14
|
+
class Success < SortedSetPutElementResponse
|
15
|
+
def success?
|
16
|
+
true
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
# @private
|
21
|
+
class Error < SortedSetPutElementResponse
|
22
|
+
include Momento::Response::Error
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
# @private
|
27
|
+
class SortedSetPutElementResponseBuilder < ResponseBuilder
|
28
|
+
# Build a Momento::SortedSetPutElementResponse from a block of code
|
29
|
+
# which returns a MomentoProtos::CacheClient::PB__SortedSetPutElementResponse.
|
30
|
+
#
|
31
|
+
# @return [Momento::SortedSetPutElementResponse]
|
32
|
+
# @raise [StandardError] when the exception is not recognized.
|
33
|
+
# @raise [TypeError] when the response is not recognized.
|
34
|
+
def from_block
|
35
|
+
response = yield
|
36
|
+
rescue *RESCUED_EXCEPTIONS => e
|
37
|
+
SortedSetPutElementResponse::Error.new(exception: e, context: context)
|
38
|
+
else
|
39
|
+
raise TypeError unless response.is_a?(::MomentoProtos::CacheClient::PB__SortedSetPutResponse)
|
40
|
+
|
41
|
+
SortedSetPutElementResponse::Success.new
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
require_relative '../error'
|
2
|
+
require_relative '../../generated/cacheclient_pb'
|
3
|
+
|
4
|
+
module Momento
|
5
|
+
# A response representing the result of a sorted set put elements operation.
|
6
|
+
class SortedSetPutElementsResponse < Response
|
7
|
+
# Were the elements added to the sorted set?
|
8
|
+
# @return [Boolean]
|
9
|
+
def success?
|
10
|
+
false
|
11
|
+
end
|
12
|
+
|
13
|
+
# @private
|
14
|
+
class Success < SortedSetPutElementsResponse
|
15
|
+
def success?
|
16
|
+
true
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
# @private
|
21
|
+
class Error < SortedSetPutElementsResponse
|
22
|
+
include Momento::Response::Error
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
# @private
|
27
|
+
class SortedSetPutElementsResponseBuilder < ResponseBuilder
|
28
|
+
# Build a Momento::SortedSetPutElementsResponse from a block of code
|
29
|
+
# which returns a MomentoProtos::CacheClient::PB__SortedSetPutElementsResponse.
|
30
|
+
#
|
31
|
+
# @return [Momento::SortedSetPutElementsResponse]
|
32
|
+
# @raise [StandardError] when the exception is not recognized.
|
33
|
+
# @raise [TypeError] when the response is not recognized.
|
34
|
+
def from_block
|
35
|
+
response = yield
|
36
|
+
rescue *RESCUED_EXCEPTIONS => e
|
37
|
+
SortedSetPutElementsResponse::Error.new(exception: e, context: context)
|
38
|
+
else
|
39
|
+
raise TypeError unless response.is_a?(::MomentoProtos::CacheClient::PB__SortedSetPutResponse)
|
40
|
+
|
41
|
+
SortedSetPutElementsResponse::Success.new
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|