vertexcache 1.0.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 +7 -0
- data/lib/vertexcache/comm/client_connector.rb +111 -0
- data/lib/vertexcache/comm/gcm_crypto_helper.rb +98 -0
- data/lib/vertexcache/comm/key_parser_helper.rb +64 -0
- data/lib/vertexcache/comm/message_codec.rb +76 -0
- data/lib/vertexcache/comm/read_write_stream.rb +55 -0
- data/lib/vertexcache/comm/socket_helper.rb +70 -0
- data/lib/vertexcache/comm/ssl_helper.rb +75 -0
- data/lib/vertexcache/command/command_base.rb +88 -0
- data/lib/vertexcache/command/command_type.rb +29 -0
- data/lib/vertexcache/command/impl/del_command.rb +45 -0
- data/lib/vertexcache/command/impl/get_command.rb +50 -0
- data/lib/vertexcache/command/impl/get_secondary_idx_one_command.rb +50 -0
- data/lib/vertexcache/command/impl/get_secondary_idx_two_command.rb +50 -0
- data/lib/vertexcache/command/impl/ping_command.rb +35 -0
- data/lib/vertexcache/command/impl/set_command.rb +78 -0
- data/lib/vertexcache/model/client_option.rb +129 -0
- data/lib/vertexcache/model/command_result.rb +36 -0
- data/lib/vertexcache/model/encryption_mode.rb +32 -0
- data/lib/vertexcache/model/get_result.rb +30 -0
- data/lib/vertexcache/model/vertex_cache_sdk_exception.rb +24 -0
- data/lib/vertexcache/version.rb +3 -0
- data/lib/vertexcache_sdk.rb +76 -0
- metadata +96 -0
@@ -0,0 +1,45 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# ------------------------------------------------------------------------------
|
4
|
+
# Copyright 2025 to Present, Jason Lam - VertexCache (https://github.com/vertexcache/vertexcache)
|
5
|
+
#
|
6
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
7
|
+
# you may not use this file except in compliance with the License.
|
8
|
+
# You may obtain a copy of the License at
|
9
|
+
#
|
10
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
11
|
+
#
|
12
|
+
# Unless required by applicable law or agreed to in writing, software
|
13
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
14
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
15
|
+
# ------------------------------------------------------------------------------
|
16
|
+
|
17
|
+
require_relative '../command_base'
|
18
|
+
require_relative '../command_type'
|
19
|
+
require_relative '../../model/vertex_cache_sdk_exception'
|
20
|
+
|
21
|
+
module VertexCache
|
22
|
+
module Command
|
23
|
+
module Impl
|
24
|
+
class DelCommand < CommandBase
|
25
|
+
def initialize(key)
|
26
|
+
if key.nil? || key.strip.empty?
|
27
|
+
raise VertexCache::Model::VertexCacheSdkException.new("#{VertexCache::Command::CommandType::DEL} command requires a non-empty key")
|
28
|
+
end
|
29
|
+
|
30
|
+
@key = key
|
31
|
+
end
|
32
|
+
|
33
|
+
def build_command
|
34
|
+
"#{VertexCache::Command::CommandType::DEL} #{@key}"
|
35
|
+
end
|
36
|
+
|
37
|
+
def parse_response(body)
|
38
|
+
unless body.strip.casecmp('OK').zero?
|
39
|
+
set_failure("DEL failed: #{body}")
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
@@ -0,0 +1,50 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# ------------------------------------------------------------------------------
|
4
|
+
# Copyright 2025 to Present, Jason Lam - VertexCache (https://github.com/vertexcache/vertexcache)
|
5
|
+
#
|
6
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
7
|
+
# you may not use this file except in compliance with the License.
|
8
|
+
# You may obtain a copy of the License at
|
9
|
+
#
|
10
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
11
|
+
#
|
12
|
+
# Unless required by applicable law or agreed to in writing, software
|
13
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
14
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
15
|
+
# ------------------------------------------------------------------------------
|
16
|
+
|
17
|
+
require_relative '../command_base'
|
18
|
+
require_relative '../../model/vertex_cache_sdk_exception'
|
19
|
+
|
20
|
+
module VertexCache
|
21
|
+
module Command
|
22
|
+
module Impl
|
23
|
+
class GetCommand < CommandBase
|
24
|
+
attr_reader :value
|
25
|
+
|
26
|
+
def initialize(key)
|
27
|
+
if key.nil? || key.strip.empty?
|
28
|
+
raise VertexCache::Model::VertexCacheSdkException.new('GET command requires a non-empty key')
|
29
|
+
end
|
30
|
+
@key = key
|
31
|
+
@value = nil
|
32
|
+
end
|
33
|
+
|
34
|
+
def build_command
|
35
|
+
"GET #{@key}"
|
36
|
+
end
|
37
|
+
|
38
|
+
def parse_response(body)
|
39
|
+
if body.strip.casecmp('(nil)').zero?
|
40
|
+
set_success('No matching key found, +(nil)')
|
41
|
+
elsif body.start_with?('ERR')
|
42
|
+
set_failure("GET failed: #{body}")
|
43
|
+
else
|
44
|
+
@value = body
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
@@ -0,0 +1,50 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# ------------------------------------------------------------------------------
|
4
|
+
# Copyright 2025 to Present, Jason Lam - VertexCache (https://github.com/vertexcache/vertexcache)
|
5
|
+
#
|
6
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
7
|
+
# you may not use this file except in compliance with the License.
|
8
|
+
# You may obtain a copy of the License at
|
9
|
+
#
|
10
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
11
|
+
#
|
12
|
+
# Unless required by applicable law or agreed to in writing, software
|
13
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
14
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
15
|
+
# ------------------------------------------------------------------------------
|
16
|
+
|
17
|
+
require_relative '../command_base'
|
18
|
+
require_relative '../../model/vertex_cache_sdk_exception'
|
19
|
+
|
20
|
+
module VertexCache
|
21
|
+
module Command
|
22
|
+
module Impl
|
23
|
+
class GetSecondaryIdxOneCommand < CommandBase
|
24
|
+
attr_reader :value
|
25
|
+
|
26
|
+
def initialize(key)
|
27
|
+
if key.nil? || key.strip.empty?
|
28
|
+
raise VertexCache::Model::VertexCacheSdkException.new('GET By Secondary Index (idx1) command requires a non-empty key')
|
29
|
+
end
|
30
|
+
@key = key
|
31
|
+
@value = nil
|
32
|
+
end
|
33
|
+
|
34
|
+
def build_command
|
35
|
+
"GETIDX1 #{@key}"
|
36
|
+
end
|
37
|
+
|
38
|
+
def parse_response(body)
|
39
|
+
if body.strip.casecmp('(nil)').zero?
|
40
|
+
set_success('No matching key found, +(nil)')
|
41
|
+
elsif body.start_with?('ERR')
|
42
|
+
set_failure("GETIDX1 failed: #{body}")
|
43
|
+
else
|
44
|
+
@value = body
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
@@ -0,0 +1,50 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# ------------------------------------------------------------------------------
|
4
|
+
# Copyright 2025 to Present, Jason Lam - VertexCache (https://github.com/vertexcache/vertexcache)
|
5
|
+
#
|
6
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
7
|
+
# you may not use this file except in compliance with the License.
|
8
|
+
# You may obtain a copy of the License at
|
9
|
+
#
|
10
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
11
|
+
#
|
12
|
+
# Unless required by applicable law or agreed to in writing, software
|
13
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
14
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
15
|
+
# ------------------------------------------------------------------------------
|
16
|
+
|
17
|
+
require_relative '../command_base'
|
18
|
+
require_relative '../../model/vertex_cache_sdk_exception'
|
19
|
+
|
20
|
+
module VertexCache
|
21
|
+
module Command
|
22
|
+
module Impl
|
23
|
+
class GetSecondaryIdxTwoCommand < CommandBase
|
24
|
+
attr_reader :value
|
25
|
+
|
26
|
+
def initialize(key)
|
27
|
+
if key.nil? || key.strip.empty?
|
28
|
+
raise VertexCache::Model::VertexCacheSdkException.new('GET By Secondary Index (idx2) command requires a non-empty key')
|
29
|
+
end
|
30
|
+
@key = key
|
31
|
+
@value = nil
|
32
|
+
end
|
33
|
+
|
34
|
+
def build_command
|
35
|
+
"GETIDX2 #{@key}"
|
36
|
+
end
|
37
|
+
|
38
|
+
def parse_response(body)
|
39
|
+
if body.strip.casecmp('(nil)').zero?
|
40
|
+
set_success('No matching key found, +(nil)')
|
41
|
+
elsif body.start_with?('ERR')
|
42
|
+
set_failure("GETIDX2 failed: #{body}")
|
43
|
+
else
|
44
|
+
@value = body
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# ------------------------------------------------------------------------------
|
4
|
+
# Copyright 2025 to Present, Jason Lam - VertexCache (https://github.com/vertexcache/vertexcache)
|
5
|
+
#
|
6
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
7
|
+
# you may not use this file except in compliance with the License.
|
8
|
+
# You may obtain a copy of the License at
|
9
|
+
#
|
10
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
11
|
+
#
|
12
|
+
# Unless required by applicable law or agreed to in writing, software
|
13
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
14
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
15
|
+
# ------------------------------------------------------------------------------
|
16
|
+
|
17
|
+
require_relative '../command_base'
|
18
|
+
|
19
|
+
module VertexCache
|
20
|
+
module Command
|
21
|
+
module Impl
|
22
|
+
class PingCommand < CommandBase
|
23
|
+
def build_command
|
24
|
+
'PING'
|
25
|
+
end
|
26
|
+
|
27
|
+
def parse_response(body)
|
28
|
+
if body.nil? || body.strip.empty? || body.strip.downcase != 'pong'
|
29
|
+
set_failure('PONG not received')
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,78 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# ------------------------------------------------------------------------------
|
4
|
+
# Copyright 2025 to Present, Jason Lam - VertexCache (https://github.com/vertexcache/vertexcache)
|
5
|
+
#
|
6
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
7
|
+
# you may not use this file except in compliance with the License.
|
8
|
+
# You may obtain a copy of the License at
|
9
|
+
#
|
10
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
11
|
+
#
|
12
|
+
# Unless required by applicable law or agreed to in writing, software
|
13
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
14
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
15
|
+
# ------------------------------------------------------------------------------
|
16
|
+
|
17
|
+
require_relative '../command_base'
|
18
|
+
require_relative '../command_type'
|
19
|
+
require_relative '../../model/vertex_cache_sdk_exception'
|
20
|
+
|
21
|
+
module VertexCache
|
22
|
+
module Command
|
23
|
+
module Impl
|
24
|
+
class SetCommand < CommandBase
|
25
|
+
def initialize(primary_key, value, secondary_key = nil, tertiary_key = nil)
|
26
|
+
if primary_key.nil? || primary_key.strip.empty?
|
27
|
+
raise VertexCache::Model::VertexCacheSdkException.new('Missing Primary Key')
|
28
|
+
end
|
29
|
+
|
30
|
+
if value.nil? || value.strip.empty?
|
31
|
+
raise VertexCache::Model::VertexCacheSdkException.new('Missing Value')
|
32
|
+
end
|
33
|
+
|
34
|
+
if !secondary_key.nil? && secondary_key.strip.empty?
|
35
|
+
raise VertexCache::Model::VertexCacheSdkException.new("Secondary key can't be empty when used")
|
36
|
+
end
|
37
|
+
|
38
|
+
if secondary_key && !secondary_key.strip.empty? && tertiary_key && tertiary_key.strip.empty?
|
39
|
+
raise VertexCache::Model::VertexCacheSdkException.new("Tertiary key can't be empty when used")
|
40
|
+
end
|
41
|
+
|
42
|
+
@primary_key = primary_key
|
43
|
+
@value = value
|
44
|
+
@secondary_key = secondary_key
|
45
|
+
@tertiary_key = tertiary_key
|
46
|
+
end
|
47
|
+
|
48
|
+
def build_command
|
49
|
+
parts = [
|
50
|
+
VertexCache::Command::CommandType::SET,
|
51
|
+
@primary_key,
|
52
|
+
@value
|
53
|
+
]
|
54
|
+
|
55
|
+
if @secondary_key && !@secondary_key.strip.empty?
|
56
|
+
parts << VertexCache::Command::CommandType::IDX1
|
57
|
+
parts << @secondary_key
|
58
|
+
end
|
59
|
+
|
60
|
+
if @tertiary_key && !@tertiary_key.strip.empty?
|
61
|
+
parts << VertexCache::Command::CommandType::IDX2
|
62
|
+
parts << @tertiary_key
|
63
|
+
end
|
64
|
+
|
65
|
+
parts.join(CommandBase::COMMAND_SPACER)
|
66
|
+
end
|
67
|
+
|
68
|
+
def parse_response(body)
|
69
|
+
if body.strip.casecmp('OK').zero?
|
70
|
+
set_success
|
71
|
+
else
|
72
|
+
set_failure('OK Not received')
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
@@ -0,0 +1,129 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# ------------------------------------------------------------------------------
|
4
|
+
# Copyright 2025 to Present, Jason Lam - VertexCache (https://github.com/vertexcache/vertexcache)
|
5
|
+
#
|
6
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
7
|
+
# you may not use this file except in compliance with the License.
|
8
|
+
# You may obtain a copy of the License at
|
9
|
+
#
|
10
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
11
|
+
#
|
12
|
+
# Unless required by applicable law or agreed to in writing, software
|
13
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
14
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
15
|
+
# See the License for the specific language governing permissions and
|
16
|
+
# limitations under the License.
|
17
|
+
# ------------------------------------------------------------------------------
|
18
|
+
|
19
|
+
require_relative 'encryption_mode'
|
20
|
+
require 'vertexcache/comm/message_codec'
|
21
|
+
require 'vertexcache/comm/key_parser_helper'
|
22
|
+
require 'vertexcache/model/vertex_cache_sdk_exception'
|
23
|
+
require 'base64'
|
24
|
+
|
25
|
+
module VertexCache
|
26
|
+
module Model
|
27
|
+
class ClientOption
|
28
|
+
DEFAULT_CLIENT_ID = 'sdk-client'
|
29
|
+
DEFAULT_HOST = '127.0.0.1'
|
30
|
+
DEFAULT_PORT = 50505
|
31
|
+
DEFAULT_READ_TIMEOUT = 3000
|
32
|
+
DEFAULT_CONNECT_TIMEOUT = 3000
|
33
|
+
|
34
|
+
attr_accessor :client_id,
|
35
|
+
:client_token,
|
36
|
+
:server_host,
|
37
|
+
:server_port,
|
38
|
+
:enable_tls_encryption,
|
39
|
+
:tls_certificate,
|
40
|
+
:verify_certificate,
|
41
|
+
:encryption_mode,
|
42
|
+
:encrypt_with_public_key,
|
43
|
+
:encrypt_with_shared_key,
|
44
|
+
:public_key,
|
45
|
+
:shared_encryption_key,
|
46
|
+
:read_timeout,
|
47
|
+
:connect_timeout
|
48
|
+
|
49
|
+
def initialize
|
50
|
+
@client_id = DEFAULT_CLIENT_ID
|
51
|
+
@client_token = nil
|
52
|
+
@server_host = DEFAULT_HOST
|
53
|
+
@server_port = DEFAULT_PORT
|
54
|
+
@enable_tls_encryption = false
|
55
|
+
@tls_certificate = nil
|
56
|
+
@verify_certificate = false
|
57
|
+
@encryption_mode = EncryptionMode::NONE
|
58
|
+
@encrypt_with_public_key = false
|
59
|
+
@encrypt_with_shared_key = false
|
60
|
+
@public_key = nil
|
61
|
+
@shared_encryption_key = nil
|
62
|
+
@read_timeout = DEFAULT_READ_TIMEOUT
|
63
|
+
@connect_timeout = DEFAULT_CONNECT_TIMEOUT
|
64
|
+
end
|
65
|
+
|
66
|
+
def get_client_id
|
67
|
+
@client_id.nil? ? '' : @client_id
|
68
|
+
end
|
69
|
+
|
70
|
+
def get_client_token
|
71
|
+
@client_token.nil? ? '' : @client_token
|
72
|
+
end
|
73
|
+
|
74
|
+
def build_ident_command
|
75
|
+
"IDENT {\"client_id\":\"#{get_client_id}\", \"token\":\"#{get_client_token}\"}"
|
76
|
+
end
|
77
|
+
|
78
|
+
def resolve_protocol_version
|
79
|
+
case @encryption_mode
|
80
|
+
when EncryptionMode::ASYMMETRIC
|
81
|
+
VertexCache::Comm::MessageCodec::PROTOCOL_VERSION_RSA_PKCS1
|
82
|
+
when EncryptionMode::SYMMETRIC
|
83
|
+
VertexCache::Comm::MessageCodec::PROTOCOL_VERSION_AES_GCM
|
84
|
+
else
|
85
|
+
VertexCache::Comm::MessageCodec::DEFAULT_PROTOCOL_VERSION
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
def public_key_as_object
|
90
|
+
raise VertexCache::Model::VertexCacheSdkException.new('Missing public key for asymmetric encryption') if @public_key.nil?
|
91
|
+
|
92
|
+
begin
|
93
|
+
OpenSSL::PKey.read(Base64.decode64(@public_key))
|
94
|
+
rescue
|
95
|
+
raise VertexCache::Model::VertexCacheSdkException.new('Failed to parse RSA public key from PEM')
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
99
|
+
def shared_encryption_key_as_bytes
|
100
|
+
raise VertexCache::Model::VertexCacheSdkException.new('Missing shared encryption key for symmetric mode') if @shared_encryption_key.nil?
|
101
|
+
|
102
|
+
begin
|
103
|
+
Base64.strict_decode64(@shared_encryption_key)
|
104
|
+
rescue
|
105
|
+
raise VertexCache::Model::VertexCacheSdkException.new('Invalid shared key format')
|
106
|
+
end
|
107
|
+
end
|
108
|
+
|
109
|
+
def public_key=(pem)
|
110
|
+
begin
|
111
|
+
OpenSSL::PKey::RSA.new(pem)
|
112
|
+
rescue OpenSSL::PKey::RSAError => e
|
113
|
+
raise VertexCache::Model::VertexCacheSdkException.new("Invalid public key: #{e.message}")
|
114
|
+
end
|
115
|
+
@public_key = pem
|
116
|
+
end
|
117
|
+
|
118
|
+
def shared_encryption_key=(key)
|
119
|
+
begin
|
120
|
+
decoded = Base64.strict_decode64(key)
|
121
|
+
raise unless decoded.bytesize == 32
|
122
|
+
rescue
|
123
|
+
raise VertexCache::Model::VertexCacheSdkException.new('Invalid shared key: must be 32 bytes base64')
|
124
|
+
end
|
125
|
+
@shared_encryption_key = key
|
126
|
+
end
|
127
|
+
end
|
128
|
+
end
|
129
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# ------------------------------------------------------------------------------
|
4
|
+
# Copyright 2025 to Present, Jason Lam - VertexCache (https://github.com/vertexcache/vertexcache)
|
5
|
+
#
|
6
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
7
|
+
# you may not use this file except in compliance with the License.
|
8
|
+
# You may obtain a copy of the License at
|
9
|
+
#
|
10
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
11
|
+
#
|
12
|
+
# Unless required by applicable law or agreed to in writing, software
|
13
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
14
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
15
|
+
# ------------------------------------------------------------------------------
|
16
|
+
|
17
|
+
module VertexCache
|
18
|
+
module Model
|
19
|
+
class CommandResult
|
20
|
+
attr_reader :success, :message
|
21
|
+
|
22
|
+
def initialize(success, message)
|
23
|
+
@success = success
|
24
|
+
@message = message
|
25
|
+
end
|
26
|
+
|
27
|
+
def success?
|
28
|
+
@success
|
29
|
+
end
|
30
|
+
|
31
|
+
def error?
|
32
|
+
!@success
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# ------------------------------------------------------------------------------
|
4
|
+
# Copyright 2025 to Present, Jason Lam - VertexCache (https://github.com/vertexcache/vertexcache)
|
5
|
+
#
|
6
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
7
|
+
# you may not use this file except in compliance with the License.
|
8
|
+
# You may obtain a copy of the License at
|
9
|
+
#
|
10
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
11
|
+
#
|
12
|
+
# Unless required by applicable law or agreed to in writing, software
|
13
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
14
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
15
|
+
# See the License for the specific language governing permissions and
|
16
|
+
# limitations under the License.
|
17
|
+
# ------------------------------------------------------------------------------
|
18
|
+
|
19
|
+
module VertexCache
|
20
|
+
module Model
|
21
|
+
module EncryptionMode
|
22
|
+
# No encryption is applied; data is sent in plaintext.
|
23
|
+
NONE = 'NONE'
|
24
|
+
|
25
|
+
# Uses public/private key encryption (e.g., RSA).
|
26
|
+
ASYMMETRIC = 'ASYMMETRIC'
|
27
|
+
|
28
|
+
# Uses a shared secret key (e.g., AES-GCM) for encryption.
|
29
|
+
SYMMETRIC = 'SYMMETRIC'
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# ------------------------------------------------------------------------------
|
4
|
+
# Copyright 2025 to Present, Jason Lam - VertexCache (https://github.com/vertexcache/vertexcache)
|
5
|
+
#
|
6
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
7
|
+
# you may not use this file except in compliance with the License.
|
8
|
+
# You may obtain a copy of the License at
|
9
|
+
#
|
10
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
11
|
+
#
|
12
|
+
# Unless required by applicable law or agreed to in writing, software
|
13
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
14
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
15
|
+
# ------------------------------------------------------------------------------
|
16
|
+
|
17
|
+
require_relative 'command_result'
|
18
|
+
|
19
|
+
module VertexCache
|
20
|
+
module Model
|
21
|
+
class GetResult < CommandResult
|
22
|
+
attr_reader :value
|
23
|
+
|
24
|
+
def initialize(success, message, value)
|
25
|
+
super(success, message)
|
26
|
+
@value = value
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# ------------------------------------------------------------------------------
|
4
|
+
# Copyright 2025 to Present, Jason Lam - VertexCache (https://github.com/vertexcache/vertexcache)
|
5
|
+
#
|
6
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
7
|
+
# you may not use this file except in compliance with the License.
|
8
|
+
# You may obtain a copy of the License at
|
9
|
+
#
|
10
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
11
|
+
#
|
12
|
+
# Unless required by applicable law or agreed to in writing, software
|
13
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
14
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
15
|
+
# See the License for the specific language governing permissions and
|
16
|
+
# limitations under the License.
|
17
|
+
# ------------------------------------------------------------------------------
|
18
|
+
|
19
|
+
module VertexCache
|
20
|
+
module Model
|
21
|
+
class VertexCacheSdkException < StandardError; end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
@@ -0,0 +1,76 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# ------------------------------------------------------------------------------
|
4
|
+
# Copyright 2025 to Present, Jason Lam - VertexCache (https://github.com/vertexcache/vertexcache)
|
5
|
+
#
|
6
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
7
|
+
# you may not use this file except in compliance with the License.
|
8
|
+
# You may obtain a copy of the License at
|
9
|
+
#
|
10
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
11
|
+
#
|
12
|
+
# Unless required by applicable law or agreed to in writing, software
|
13
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
14
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
15
|
+
# ------------------------------------------------------------------------------
|
16
|
+
|
17
|
+
require_relative 'vertexcache/version'
|
18
|
+
require_relative 'vertexcache/comm/client_connector'
|
19
|
+
require_relative 'vertexcache/command/impl/ping_command'
|
20
|
+
require_relative 'vertexcache/command/impl/set_command'
|
21
|
+
require_relative 'vertexcache/command/impl/del_command'
|
22
|
+
require_relative 'vertexcache/command/impl/get_command'
|
23
|
+
require_relative 'vertexcache/command/impl/get_secondary_idx_one_command'
|
24
|
+
require_relative 'vertexcache/command/impl/get_secondary_idx_two_command'
|
25
|
+
require_relative 'vertexcache/model/command_result'
|
26
|
+
require_relative 'vertexcache/model/get_result'
|
27
|
+
|
28
|
+
module VertexCache
|
29
|
+
class VertexCacheSDK
|
30
|
+
def initialize(client_option)
|
31
|
+
@client_connector = VertexCache::Comm::ClientConnector.new(client_option)
|
32
|
+
end
|
33
|
+
|
34
|
+
def open_connection
|
35
|
+
@client_connector.connect
|
36
|
+
end
|
37
|
+
|
38
|
+
def close
|
39
|
+
@client_connector.close
|
40
|
+
end
|
41
|
+
|
42
|
+
def is_connected?
|
43
|
+
@client_connector.connected?
|
44
|
+
end
|
45
|
+
|
46
|
+
def ping
|
47
|
+
cmd = VertexCache::Command::Impl::PingCommand.new.execute(@client_connector)
|
48
|
+
VertexCache::Model::CommandResult.new(cmd.success?, cmd.get_status_message)
|
49
|
+
end
|
50
|
+
|
51
|
+
def set(key, value, secondary_key = nil, tertiary_key = nil)
|
52
|
+
cmd = VertexCache::Command::Impl::SetCommand.new(key, value, secondary_key, tertiary_key).execute(@client_connector)
|
53
|
+
VertexCache::Model::CommandResult.new(cmd.success?, cmd.get_status_message)
|
54
|
+
end
|
55
|
+
|
56
|
+
def del(key)
|
57
|
+
cmd = VertexCache::Command::Impl::DelCommand.new(key).execute(@client_connector)
|
58
|
+
VertexCache::Model::CommandResult.new(cmd.success?, cmd.get_status_message)
|
59
|
+
end
|
60
|
+
|
61
|
+
def get(key)
|
62
|
+
cmd = VertexCache::Command::Impl::GetCommand.new(key).execute(@client_connector)
|
63
|
+
VertexCache::Model::GetResult.new(cmd.success?, cmd.get_status_message, cmd.value)
|
64
|
+
end
|
65
|
+
|
66
|
+
def get_by_secondary_index(key)
|
67
|
+
cmd = VertexCache::Command::Impl::GetSecondaryIdxOneCommand.new(key).execute(@client_connector)
|
68
|
+
VertexCache::Model::GetResult.new(cmd.success?, cmd.get_status_message, cmd.value)
|
69
|
+
end
|
70
|
+
|
71
|
+
def get_by_tertiary_index(key)
|
72
|
+
cmd = VertexCache::Command::Impl::GetSecondaryIdxTwoCommand.new(key).execute(@client_connector)
|
73
|
+
VertexCache::Model::GetResult.new(cmd.success?, cmd.get_status_message, cmd.value)
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|