aerospike 1.0.12 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +54 -18
- data/README.md +7 -2
- data/lib/aerospike.rb +8 -0
- data/lib/aerospike/cdt/list_operation.rb +199 -0
- data/lib/aerospike/cdt/map_operation.rb +352 -0
- data/lib/aerospike/cdt/map_order.rb +38 -0
- data/lib/aerospike/cdt/map_policy.rb +37 -0
- data/lib/aerospike/cdt/map_return_type.rb +74 -0
- data/lib/aerospike/cdt/map_write_mode.rb +41 -0
- data/lib/aerospike/client.rb +84 -119
- data/lib/aerospike/cluster/cluster.rb +4 -4
- data/lib/aerospike/command/admin_command.rb +325 -325
- data/lib/aerospike/command/command.rb +2 -2
- data/lib/aerospike/command/roles.rb +13 -13
- data/lib/aerospike/key.rb +24 -5
- data/lib/aerospike/operation.rb +2 -0
- data/lib/aerospike/policy/admin_policy.rb +10 -10
- data/lib/aerospike/policy/consistency_level.rb +4 -4
- data/lib/aerospike/query/stream_command.rb +1 -1
- data/lib/aerospike/result_code.rb +1 -1
- data/lib/aerospike/task/execute_task.rb +68 -68
- data/lib/aerospike/task/task.rb +2 -6
- data/lib/aerospike/utils/packer.rb +47 -0
- data/lib/aerospike/utils/unpacker.rb +106 -0
- data/lib/aerospike/value/value.rb +19 -51
- data/lib/aerospike/version.rb +1 -1
- metadata +17 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 235bd4afc86f8bf263a458a22f7e13a247bdda6c
|
4
|
+
data.tar.gz: 35e141ffb29702a9cf1ea046fe731a89e2de9bb5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e4e54c1051e29cf790f4df58ee1822c3e20fb8120f3d2aef61c69c0da516a6389d429a99d71ad8d1df8fd05b92f18c245b9e0bd2215610ee4c527dca36ae72ed
|
7
|
+
data.tar.gz: be8ec2b6d0247dc6fdec77eba9269561970a6688d0a328cfda38cb7a822c9b9047cdb6ff34a101dfcf60b10de629daf9113cebfa3095bd4b3d2c3cb20e04bfca
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,21 @@
|
|
1
|
+
v2.0.0 / 2016-05-27
|
2
|
+
===================
|
3
|
+
|
4
|
+
* **Breaking Changes** - Please refer to detailed list of [API changes](docs/api-changes.md#v2.0.0) for further details.
|
5
|
+
* Incompatible integer key digests: digests for integer keys computed by v2 and v1 are different; the Aerospike server uses the key digest to retrieve records. This will impact your ability to read records with integer keys that were created by a v1 client version.
|
6
|
+
* Backward incompatible changes to the `Aerospike::Client.new` initializer.
|
7
|
+
* The `Aerospike::Client.new_many` initializer has been removed; use `Aerospike::Client.new` instead.
|
8
|
+
* Drop support for Ruby 1.9.3; requires Ruby 2.0 or later.
|
9
|
+
|
10
|
+
* **Improvements**
|
11
|
+
* Add support for List and Map operations on List/Map Complex Data Types (CDT); requires Aerospike Server version 3.9 or later. [CLIENT-559]
|
12
|
+
* Read Aerospike server address from AEROSPIKE_HOSTS env variable if not specified explicity in client constructor.
|
13
|
+
* Add 2.3.1 to supported Ruby versions on Travis-CI.
|
14
|
+
|
15
|
+
* **Fixes**
|
16
|
+
* Fix digest creation for integer keys. [PR #34](https://github.com/aerospike/aerospike-client-ruby/pull/34). Thanks to [@murphyslaw](https://github.com/murphyslaw)!
|
17
|
+
* Prevent "value must be enumerable" error when client cannot connect to cluster. [#35](https://github.com/aerospike/aerospike-client-ruby/issues/35). Thanks to [@rohanthewiz](https://github.com/rohanthewiz)!
|
18
|
+
|
1
19
|
1.0.12 / 2016-02-11
|
2
20
|
===================
|
3
21
|
|
@@ -10,7 +28,8 @@
|
|
10
28
|
bins; thanks to [fs-wu](https://github.com/fs-wu) for finding the issue and
|
11
29
|
reporting it. [aerospike/aerospike-client-ruby#33]
|
12
30
|
|
13
|
-
|
31
|
+
1.0.11 / 2015-12-04
|
32
|
+
===================
|
14
33
|
|
15
34
|
Major feature and bug fix release.
|
16
35
|
|
@@ -39,7 +58,8 @@
|
|
39
58
|
|
40
59
|
* Scan and Query termination has been fixed.
|
41
60
|
|
42
|
-
|
61
|
+
1.0.10 / 2015-09-22
|
62
|
+
===================
|
43
63
|
|
44
64
|
Major fix release.
|
45
65
|
|
@@ -51,7 +71,8 @@
|
|
51
71
|
|
52
72
|
* Fixes an issue with dead connections that would cause an infinite loop.
|
53
73
|
|
54
|
-
|
74
|
+
1.0.9 / 2015-08-11
|
75
|
+
==================
|
55
76
|
|
56
77
|
Minor fix release.
|
57
78
|
|
@@ -59,7 +80,8 @@
|
|
59
80
|
|
60
81
|
* Sends the original key value to the server for all relevant commands, including `operate` and `execute_udf`
|
61
82
|
|
62
|
-
|
83
|
+
1.0.8 / 2015-07-23
|
84
|
+
==================
|
63
85
|
|
64
86
|
Minor fix release.
|
65
87
|
|
@@ -75,7 +97,8 @@
|
|
75
97
|
|
76
98
|
* Fixes an issue with including the `statement.rb` in the manifest. Thanks to [Ángel M](https://github.com/Angelmmiguel)
|
77
99
|
|
78
|
-
|
100
|
+
1.0.7 / 2015-05-15
|
101
|
+
==================
|
79
102
|
|
80
103
|
Minor fixes.
|
81
104
|
|
@@ -95,7 +118,8 @@
|
|
95
118
|
|
96
119
|
* Removed deprecated `SetCapacity()` and `GetCapacity()` methods for LDTs.
|
97
120
|
|
98
|
-
|
121
|
+
1.0.6 / 2015-04-02
|
122
|
+
==================
|
99
123
|
|
100
124
|
Minor fixes.
|
101
125
|
|
@@ -103,7 +127,8 @@
|
|
103
127
|
|
104
128
|
* Fixed running a stream query without parameters to the function.
|
105
129
|
|
106
|
-
|
130
|
+
1.0.5 / 2015-03-25
|
131
|
+
==================
|
107
132
|
|
108
133
|
Minor improvements.
|
109
134
|
|
@@ -111,7 +136,8 @@
|
|
111
136
|
|
112
137
|
* Added `:execute_udf_on_query` method to `Aerospike::Client`
|
113
138
|
|
114
|
-
|
139
|
+
1.0.4 / 2015-03-24
|
140
|
+
==================
|
115
141
|
|
116
142
|
Hot fix.
|
117
143
|
|
@@ -119,7 +145,8 @@
|
|
119
145
|
|
120
146
|
* Close a socket if connection raises an exception to avoid leaking the file descriptor.
|
121
147
|
|
122
|
-
|
148
|
+
1.0.3 / 2015-03-24
|
149
|
+
==================
|
123
150
|
|
124
151
|
Minor fixes and improvements.
|
125
152
|
|
@@ -132,7 +159,8 @@
|
|
132
159
|
* Wait for a good connection on `socket.connect_nonblock` to prevent infinite loops on read/write operations.
|
133
160
|
|
134
161
|
|
135
|
-
|
162
|
+
1.0.2 / 2015-03-14
|
163
|
+
==================
|
136
164
|
|
137
165
|
Minor improvements.
|
138
166
|
|
@@ -140,7 +168,8 @@
|
|
140
168
|
|
141
169
|
* Added `:new_many` method to `Aerospike::Client`
|
142
170
|
|
143
|
-
|
171
|
+
1.0.1 / 2015-01-28
|
172
|
+
==================
|
144
173
|
|
145
174
|
Hot fix.
|
146
175
|
|
@@ -148,7 +177,8 @@
|
|
148
177
|
|
149
178
|
* Added `bcrypt` to the gem dependencies.
|
150
179
|
|
151
|
-
|
180
|
+
1.0.0 / 2015-01-26
|
181
|
+
==================
|
152
182
|
|
153
183
|
Major release. With this release, Ruby client graduates to version 1.
|
154
184
|
|
@@ -170,7 +200,8 @@
|
|
170
200
|
|
171
201
|
* fixed size returned from `BytesValue.write`
|
172
202
|
|
173
|
-
|
203
|
+
0.1.6 / 2014-12-28
|
204
|
+
==================
|
174
205
|
|
175
206
|
Minor features added, minor fixes and improvements.
|
176
207
|
|
@@ -184,7 +215,8 @@
|
|
184
215
|
* Fixed setting timeout on connection
|
185
216
|
* Fixed exception handling typo for Connection#write
|
186
217
|
|
187
|
-
|
218
|
+
0.1.5 / 2014-12-08
|
219
|
+
==================
|
188
220
|
|
189
221
|
Major features added, minor fixes and improvements.
|
190
222
|
|
@@ -197,7 +229,8 @@
|
|
197
229
|
|
198
230
|
* Fixed getting back results only for specified bin names.
|
199
231
|
|
200
|
-
|
232
|
+
0.1.3 / 2014-10-27
|
233
|
+
==================
|
201
234
|
|
202
235
|
Minor fix.
|
203
236
|
|
@@ -205,7 +238,8 @@
|
|
205
238
|
|
206
239
|
* Fixed LDT bin and module name packing.
|
207
240
|
|
208
|
-
|
241
|
+
0.1.2 / 2014-10-25
|
242
|
+
==================
|
209
243
|
|
210
244
|
Minor fix.
|
211
245
|
|
@@ -213,7 +247,8 @@
|
|
213
247
|
|
214
248
|
* Fixed String unpacking for single byte strings.
|
215
249
|
|
216
|
-
|
250
|
+
0.1.1 / 2014-10-25
|
251
|
+
==================
|
217
252
|
|
218
253
|
Minor fixes.
|
219
254
|
|
@@ -222,6 +257,7 @@
|
|
222
257
|
* Fixed String packing header in Hash and Array.
|
223
258
|
* #find on LDTs returns `nil` instad of raising an exception if the item is not found.
|
224
259
|
|
225
|
-
|
260
|
+
0.1.0 / 2014-10-14
|
261
|
+
==================
|
226
262
|
|
227
263
|
* Initial Release.
|
data/README.md
CHANGED
@@ -1,4 +1,9 @@
|
|
1
|
-
# Aerospike Ruby Client
|
1
|
+
# Aerospike Ruby Client [![travis][travis-image]][travis-url] [![gem][gem-image]][gem-url]
|
2
|
+
|
3
|
+
[travis-image]: https://travis-ci.org/aerospike/aerospike-client-ruby.svg?branch=master
|
4
|
+
[travis-url]: https://travis-ci.org/aerospike/aerospike-client-ruby
|
5
|
+
[gem-image]: https://img.shields.io/gem/v/aerospike.svg
|
6
|
+
[gem-url]: https://rubygems.org/gems/aerospike
|
2
7
|
|
3
8
|
An Aerospike library for Ruby.
|
4
9
|
|
@@ -26,7 +31,7 @@ require 'aerospike'
|
|
26
31
|
|
27
32
|
include Aerospike
|
28
33
|
|
29
|
-
client = Client.new("127.0.0.1"
|
34
|
+
client = Client.new("127.0.0.1")
|
30
35
|
|
31
36
|
key = Key.new('test', 'test', 'key value')
|
32
37
|
bin_map = {
|
data/lib/aerospike.rb
CHANGED
@@ -11,6 +11,8 @@ require 'aerospike/atomic/atomic'
|
|
11
11
|
|
12
12
|
require 'aerospike/client'
|
13
13
|
require 'aerospike/utils/pool'
|
14
|
+
require 'aerospike/utils/packer'
|
15
|
+
require 'aerospike/utils/unpacker'
|
14
16
|
require 'aerospike/utils/epoc'
|
15
17
|
require 'aerospike/utils/buffer'
|
16
18
|
require 'aerospike/host'
|
@@ -40,6 +42,12 @@ require 'aerospike/command/admin_command'
|
|
40
42
|
require 'aerospike/command/unsupported_particle_type_validator'
|
41
43
|
require 'aerospike/key'
|
42
44
|
require 'aerospike/operation'
|
45
|
+
require 'aerospike/cdt/list_operation'
|
46
|
+
require 'aerospike/cdt/map_operation'
|
47
|
+
require 'aerospike/cdt/map_order'
|
48
|
+
require 'aerospike/cdt/map_return_type'
|
49
|
+
require 'aerospike/cdt/map_write_mode'
|
50
|
+
require 'aerospike/cdt/map_policy'
|
43
51
|
require 'aerospike/geo_json'
|
44
52
|
|
45
53
|
require 'aerospike/policy/client_policy'
|
@@ -0,0 +1,199 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
# Copyright 2016 Aerospike, Inc.
|
3
|
+
#
|
4
|
+
# Portions may be licensed to Aerospike, Inc. under one or more contributor
|
5
|
+
# license agreements.
|
6
|
+
#
|
7
|
+
# Licensed under the Apache License, Version 2.0 (the "License"); you may not
|
8
|
+
# use this file except in compliance with the License. You may obtain a copy of
|
9
|
+
# the License at http:#www.apache.org/licenses/LICENSE-2.0
|
10
|
+
#
|
11
|
+
# Unless required by applicable law or agreed to in writing, software
|
12
|
+
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
13
|
+
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
14
|
+
# License for the specific language governing permissions and limitations under
|
15
|
+
# the License.
|
16
|
+
|
17
|
+
module Aerospike
|
18
|
+
module CDT
|
19
|
+
|
20
|
+
##
|
21
|
+
# List bin operations. Create list operations used by the Client#operate
|
22
|
+
# command. List operations support negative indexing. If the index is
|
23
|
+
# negative, the resolved index starts backwards from end of list.
|
24
|
+
#
|
25
|
+
# Index/Range examples:
|
26
|
+
# * Index 0: First item in list.
|
27
|
+
# * Index 4: Fifth item in list.
|
28
|
+
# * Index -1: Last item in list.
|
29
|
+
# * Index -3: Third to last item in list.
|
30
|
+
# * Index 1 Count 2: Second and third items in list.
|
31
|
+
# * Index -3 Count 3: Last three items in list.
|
32
|
+
# * Index -5 Count 4: Range between fifth to last item to second to last
|
33
|
+
# item inclusive.
|
34
|
+
#
|
35
|
+
# If an index is out of bounds, a parameter error will be returned. If a
|
36
|
+
# range is partially out of bounds, the valid part of the range will be
|
37
|
+
# returned.
|
38
|
+
|
39
|
+
class ListOperation
|
40
|
+
|
41
|
+
APPEND = 1
|
42
|
+
APPEND_ITEMS = 2
|
43
|
+
INSERT = 3
|
44
|
+
INSERT_ITEMS = 4
|
45
|
+
POP = 5
|
46
|
+
POP_RANGE = 6
|
47
|
+
REMOVE = 7
|
48
|
+
REMOVE_RANGE = 8
|
49
|
+
SET = 9
|
50
|
+
TRIM = 10
|
51
|
+
CLEAR = 11
|
52
|
+
SIZE = 16
|
53
|
+
GET = 17
|
54
|
+
GET_RANGE = 18
|
55
|
+
|
56
|
+
##
|
57
|
+
# Create list append operation.
|
58
|
+
# Server appends value(s) to end of the list bin.
|
59
|
+
# Server returns list size.
|
60
|
+
def self.append(bin_name, *values)
|
61
|
+
if values.length > 1
|
62
|
+
create_operation(Operation::CDT_MODIFY, APPEND_ITEMS, bin_name, values)
|
63
|
+
else
|
64
|
+
create_operation(Operation::CDT_MODIFY, APPEND, bin_name, values.first)
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
##
|
69
|
+
# Create list insert operation.
|
70
|
+
# Server inserts value(s) at the specified index of the list bin.
|
71
|
+
# Server returns list size.
|
72
|
+
def self.insert(bin_name, index, *values)
|
73
|
+
if values.length > 1
|
74
|
+
create_operation(Operation::CDT_MODIFY, INSERT_ITEMS, bin_name, index, values)
|
75
|
+
else
|
76
|
+
create_operation(Operation::CDT_MODIFY, INSERT, bin_name, index, values.first)
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
##
|
81
|
+
# Create list pop operation.
|
82
|
+
# Server returns item at specified index and removes item from list bin.
|
83
|
+
def self.pop(bin_name, index)
|
84
|
+
create_operation(Operation::CDT_MODIFY, POP, bin_name, index)
|
85
|
+
end
|
86
|
+
|
87
|
+
##
|
88
|
+
# Create list pop range operation.
|
89
|
+
# Server returns "count" items starting at specified index and removes
|
90
|
+
# items from list bin. If "count" is not specified, the server returns
|
91
|
+
# items starting at the specified index to the end of the list and
|
92
|
+
# removes those items from the list bin.
|
93
|
+
def self.pop_range(bin_name, index, count=nil)
|
94
|
+
if count
|
95
|
+
create_operation(Operation::CDT_MODIFY, POP_RANGE, bin_name, index, count)
|
96
|
+
else
|
97
|
+
create_operation(Operation::CDT_MODIFY, POP_RANGE, bin_name, index)
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
101
|
+
##
|
102
|
+
# Create list remove operation.
|
103
|
+
# Server removes item at specified index from list bin.
|
104
|
+
# Server returns number of items removed.
|
105
|
+
def self.remove(bin_name, index)
|
106
|
+
create_operation(Operation::CDT_MODIFY, REMOVE, bin_name, index)
|
107
|
+
end
|
108
|
+
|
109
|
+
##
|
110
|
+
# Create list remove range operation.
|
111
|
+
# Server removes "count" items at specified index from list bin. If
|
112
|
+
# "count" is not specified, the server removes all items starting at the
|
113
|
+
# specified index to the end of the list.
|
114
|
+
# Server returns number of items removed.
|
115
|
+
def self.remove_range(bin_name, index, count=nil)
|
116
|
+
if count
|
117
|
+
create_operation(Operation::CDT_MODIFY, REMOVE_RANGE, bin_name, index, count)
|
118
|
+
else
|
119
|
+
create_operation(Operation::CDT_MODIFY, REMOVE_RANGE, bin_name, index)
|
120
|
+
end
|
121
|
+
end
|
122
|
+
|
123
|
+
##
|
124
|
+
# Create list set operation.
|
125
|
+
# Server sets item value at specified index in list bin.
|
126
|
+
# Server does not return a result by default.
|
127
|
+
def self.set(bin_name, index, value)
|
128
|
+
create_operation(Operation::CDT_MODIFY, SET, bin_name, index, value)
|
129
|
+
end
|
130
|
+
|
131
|
+
##
|
132
|
+
# Create list trim operation.
|
133
|
+
# Server removes items in list bin that do not fall into range specified
|
134
|
+
# by index and count. If count is not specified, server will keep all
|
135
|
+
# items starting at the specified index to the end of the list.
|
136
|
+
# Server returns number of items removed.
|
137
|
+
def self.trim(bin_name, index, count=nil)
|
138
|
+
if count
|
139
|
+
create_operation(Operation::CDT_MODIFY, TRIM, bin_name, index, count)
|
140
|
+
else
|
141
|
+
create_operation(Operation::CDT_MODIFY, TRIM, bin_name, index)
|
142
|
+
end
|
143
|
+
end
|
144
|
+
|
145
|
+
##
|
146
|
+
# Create list clear operation.
|
147
|
+
# Server removes all items in the list bin.
|
148
|
+
# Server does not return a result by default.
|
149
|
+
def self.clear(bin_name)
|
150
|
+
create_operation(Operation::CDT_MODIFY, CLEAR, bin_name)
|
151
|
+
end
|
152
|
+
|
153
|
+
##
|
154
|
+
# Create list size operation.
|
155
|
+
# Server returns size of list.
|
156
|
+
def self.size(bin_name)
|
157
|
+
create_operation(Operation::CDT_READ, SIZE, bin_name)
|
158
|
+
end
|
159
|
+
|
160
|
+
##
|
161
|
+
# Create list get operation.
|
162
|
+
# Server returns the item at the specified index in the list bin.
|
163
|
+
def self.get(bin_name, index)
|
164
|
+
create_operation(Operation::CDT_READ, GET, bin_name, index)
|
165
|
+
end
|
166
|
+
|
167
|
+
##
|
168
|
+
# Create list get range operation.
|
169
|
+
# Server returns "count" items starting at the specified index in the
|
170
|
+
# list bin. If "count" is not specified, the server returns all items
|
171
|
+
# starting at the specified index to the end of the list.
|
172
|
+
def self.get_range(bin_name, index, count=nil)
|
173
|
+
if count
|
174
|
+
create_operation(Operation::CDT_READ, GET_RANGE, bin_name, index, count)
|
175
|
+
else
|
176
|
+
create_operation(Operation::CDT_READ, GET_RANGE, bin_name, index)
|
177
|
+
end
|
178
|
+
end
|
179
|
+
|
180
|
+
private
|
181
|
+
|
182
|
+
def self.create_operation(type, cdt_type, bin, *args)
|
183
|
+
bytes = nil
|
184
|
+
Packer.use do |packer|
|
185
|
+
packer.write_raw_short(cdt_type)
|
186
|
+
if args.length > 0
|
187
|
+
packer.write_array_header(args.length)
|
188
|
+
args.each do |value|
|
189
|
+
Value.of(value).pack(packer)
|
190
|
+
end
|
191
|
+
end
|
192
|
+
bytes = packer.bytes
|
193
|
+
end
|
194
|
+
return Operation.new(type, bin, BytesValue.new(bytes))
|
195
|
+
end
|
196
|
+
|
197
|
+
end
|
198
|
+
end
|
199
|
+
end
|
@@ -0,0 +1,352 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
# Copyright 2016 Aerospike, Inc.
|
3
|
+
#
|
4
|
+
# Portions may be licensed to Aerospike, Inc. under one or more contributor
|
5
|
+
# license agreements.
|
6
|
+
#
|
7
|
+
# Licensed under the Apache License, Version 2.0 (the "License"); you may not
|
8
|
+
# use this file except in compliance with the License. You may obtain a copy of
|
9
|
+
# the License at http:#www.apache.org/licenses/LICENSE-2.0
|
10
|
+
#
|
11
|
+
# Unless required by applicable law or agreed to in writing, software
|
12
|
+
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
13
|
+
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
14
|
+
# License for the specific language governing permissions and limitations under
|
15
|
+
# the License.
|
16
|
+
|
17
|
+
module Aerospike
|
18
|
+
module CDT
|
19
|
+
|
20
|
+
class MapOperation < Operation
|
21
|
+
|
22
|
+
SET_TYPE = 64
|
23
|
+
ADD = 65
|
24
|
+
ADD_ITEMS = 66
|
25
|
+
PUT = 67
|
26
|
+
PUT_ITEMS = 68
|
27
|
+
REPLACE = 69
|
28
|
+
REPLACE_ITEMS = 70
|
29
|
+
INCREMENT = 73
|
30
|
+
DECREMENT = 74
|
31
|
+
CLEAR = 75
|
32
|
+
REMOVE_BY_KEY = 76
|
33
|
+
REMOVE_BY_INDEX = 77
|
34
|
+
REMOVE_BY_RANK = 79
|
35
|
+
REMOVE_BY_KEY_LIST = 81
|
36
|
+
REMOVE_BY_VALUE = 82
|
37
|
+
REMOVE_BY_VALUE_LIST = 83
|
38
|
+
REMOVE_BY_KEY_INTERVAL = 84
|
39
|
+
REMOVE_BY_INDEX_RANGE = 85
|
40
|
+
REMOVE_BY_VALUE_INTERVAL = 86
|
41
|
+
REMOVE_BY_RANK_RANGE = 87
|
42
|
+
SIZE = 96
|
43
|
+
GET_BY_KEY = 97
|
44
|
+
GET_BY_INDEX = 98
|
45
|
+
GET_BY_RANK = 100
|
46
|
+
GET_BY_VALUE = 102
|
47
|
+
GET_BY_KEY_INTERVAL = 103
|
48
|
+
GET_BY_INDEX_RANGE = 104
|
49
|
+
GET_BY_VALUE_INTERVAL = 105
|
50
|
+
GET_BY_RANK_RANGE = 106
|
51
|
+
|
52
|
+
attr_reader :map_op, :arguments, :policy, :return_type
|
53
|
+
|
54
|
+
def initialize(op_type, map_op, bin_name, *arguments, policy: nil, return_type: nil)
|
55
|
+
@op_type = op_type
|
56
|
+
@bin_name = bin_name
|
57
|
+
@bin_value = nil
|
58
|
+
@map_op = map_op
|
59
|
+
@arguments = arguments
|
60
|
+
@policy = policy
|
61
|
+
@return_type = return_type
|
62
|
+
self
|
63
|
+
end
|
64
|
+
|
65
|
+
##
|
66
|
+
# Create set map policy operation.
|
67
|
+
# Server sets map policy attributes. Server returns null.
|
68
|
+
#
|
69
|
+
# The required map policy attributes can be changed after the map is created.
|
70
|
+
def self.set_policy(bin_name, policy)
|
71
|
+
MapOperation.new(Operation::CDT_MODIFY, SET_TYPE, bin_name, policy: policy)
|
72
|
+
end
|
73
|
+
|
74
|
+
##
|
75
|
+
# Create map put operation.
|
76
|
+
# Server writes key/value item to map bin and returns map size.
|
77
|
+
#
|
78
|
+
# The map policy dictates the type of map to create when it does not exist.
|
79
|
+
# The map policy also specifies the mode used when writing items to the map.
|
80
|
+
def self.put(bin_name, key, value, policy: MapPolicy::DEFAULT)
|
81
|
+
cmd =
|
82
|
+
case policy.write_mode
|
83
|
+
when MapWriteMode::UPDATE then PUT
|
84
|
+
when MapWriteMode::UPDATE_ONLY then REPLACE
|
85
|
+
when MapWriteMode::CREATE_ONLY then ADD
|
86
|
+
else PUT
|
87
|
+
end
|
88
|
+
MapOperation.new(Operation::CDT_MODIFY, cmd, bin_name, key, value, policy: policy)
|
89
|
+
end
|
90
|
+
|
91
|
+
##
|
92
|
+
# Create map put items operation
|
93
|
+
# Server writes each map item to map bin and returns map size.
|
94
|
+
#
|
95
|
+
# The map policy dictates the type of map to create when it does not exist.
|
96
|
+
# The map policy also specifies the mode used when writing items to the map.
|
97
|
+
def self.put_items(bin_name, values, policy: MapPolicy::DEFAULT)
|
98
|
+
cmd =
|
99
|
+
case policy.write_mode
|
100
|
+
when MapWriteMode::UPDATE then PUT_ITEMS
|
101
|
+
when MapWriteMode::UPDATE_ONLY then REPLACE_ITEMS
|
102
|
+
when MapWriteMode::CREATE_ONLY then ADD_ITEMS
|
103
|
+
else PUT_ITEMS
|
104
|
+
end
|
105
|
+
MapOperation.new(Operation::CDT_MODIFY, cmd, bin_name, values, policy: policy)
|
106
|
+
end
|
107
|
+
|
108
|
+
##
|
109
|
+
# Create map increment operation.
|
110
|
+
# Server increments values by incr for all items identified by key and returns final result.
|
111
|
+
# Valid only for numbers.
|
112
|
+
#
|
113
|
+
# The map policy dictates the type of map to create when it does not exist.
|
114
|
+
# The map policy also specifies the mode used when writing items to the map.
|
115
|
+
def self.increment(bin_name, key, incr, policy: MapPolicy::DEFAULT)
|
116
|
+
MapOperation.new(Operation::CDT_MODIFY, INCREMENT, bin_name, key, incr, policy: policy)
|
117
|
+
end
|
118
|
+
|
119
|
+
##
|
120
|
+
# Create map decrement operation.
|
121
|
+
# Server decrements values by decr for all items identified by key and returns final result.
|
122
|
+
# Valid only for numbers.
|
123
|
+
#
|
124
|
+
# The map policy dictates the type of map to create when it does not exist.
|
125
|
+
# The map policy also specifies the mode used when writing items to the map.
|
126
|
+
def self.decrement(bin_name, key, decr, policy: MapPolicy::DEFAULT)
|
127
|
+
MapOperation.new(Operation::CDT_MODIFY, DECREMENT, bin_name, key, decr, policy: policy)
|
128
|
+
end
|
129
|
+
|
130
|
+
##
|
131
|
+
# Create map clear operation.
|
132
|
+
# Server removes all items in map. Server returns null.
|
133
|
+
def self.clear(bin_name)
|
134
|
+
MapOperation.new(Operation::CDT_MODIFY, CLEAR, bin_name)
|
135
|
+
end
|
136
|
+
|
137
|
+
##
|
138
|
+
# Create map remove operation.
|
139
|
+
# Server removes map item identified by key and returns removed data specified by return_type.
|
140
|
+
def self.remove_keys(bin_name, *keys, return_type: MapReturnType::NONE)
|
141
|
+
if keys.length > 1
|
142
|
+
MapOperation.new(Operation::CDT_MODIFY, REMOVE_BY_KEY_LIST, bin_name, keys, return_type: return_type)
|
143
|
+
else
|
144
|
+
MapOperation.new(Operation::CDT_MODIFY, REMOVE_BY_KEY, bin_name, keys.first, return_type: return_type)
|
145
|
+
end
|
146
|
+
end
|
147
|
+
|
148
|
+
##
|
149
|
+
# Create map remove operation.
|
150
|
+
# Server removes map items identified by key range (key_begin inclusive, key_end exclusive).
|
151
|
+
# If key_begin is null, the range is less than key_end.
|
152
|
+
# If key_end is null, the range is greater than equal to key_begin.
|
153
|
+
#
|
154
|
+
# Server returns removed data specified by return_type.
|
155
|
+
def self.remove_key_range(bin_name, key_begin, key_end = nil, return_type: MapReturnType::NONE)
|
156
|
+
if key_end
|
157
|
+
MapOperation.new(Operation::CDT_MODIFY, REMOVE_BY_KEY_INTERVAL, bin_name, key_begin, key_end, return_type: return_type)
|
158
|
+
else
|
159
|
+
MapOperation.new(Operation::CDT_MODIFY, REMOVE_BY_KEY_INTERVAL, bin_name, key_begin, return_type: return_type)
|
160
|
+
end
|
161
|
+
end
|
162
|
+
|
163
|
+
##
|
164
|
+
# Create map remove operation.
|
165
|
+
# Server removes map items identified by value and returns removed data specified by return_type.
|
166
|
+
def self.remove_values(bin_name, *values, return_type: MapReturnType::NONE)
|
167
|
+
if values.length > 1
|
168
|
+
MapOperation.new(Operation::CDT_MODIFY, REMOVE_BY_VALUE_LIST, bin_name, values, return_type: return_type)
|
169
|
+
else
|
170
|
+
MapOperation.new(Operation::CDT_MODIFY, REMOVE_BY_VALUE, bin_name, values.first, return_type: return_type)
|
171
|
+
end
|
172
|
+
end
|
173
|
+
|
174
|
+
##
|
175
|
+
# Create map remove operation.
|
176
|
+
# Server removes map items identified by value range (value_begin inclusive, value_end exclusive).
|
177
|
+
# If value_begin is null, the range is less than value_end.
|
178
|
+
# If value_end is null, the range is greater than equal to value_begin.
|
179
|
+
#
|
180
|
+
# Server returns removed data specified by return_type.
|
181
|
+
def self.remove_value_range(bin_name, value_begin, value_end = nil, return_type: MapReturnType::NONE)
|
182
|
+
if value_end
|
183
|
+
MapOperation.new(Operation::CDT_MODIFY, REMOVE_BY_VALUE_INTERVAL, bin_name, value_begin, value_end, return_type: return_type)
|
184
|
+
else
|
185
|
+
MapOperation.new(Operation::CDT_MODIFY, REMOVE_BY_VALUE_INTERVAL, bin_name, value_begin, return_type: return_type)
|
186
|
+
end
|
187
|
+
end
|
188
|
+
|
189
|
+
##
|
190
|
+
# Create map remove operation.
|
191
|
+
# Server removes map item identified by index and returns removed data specified by return_type.
|
192
|
+
def self.remove_index(bin_name, index, return_type: MapReturnType::NONE)
|
193
|
+
MapOperation.new(Operation::CDT_MODIFY, REMOVE_BY_INDEX, bin_name, index, return_type: return_type)
|
194
|
+
end
|
195
|
+
|
196
|
+
##
|
197
|
+
# Create map remove operation.
|
198
|
+
# Server removes "count" map items starting at specified index and
|
199
|
+
# returns removed data specified by return_type. If "count" is not
|
200
|
+
# specified, the server selects map items starting at specified index to
|
201
|
+
# the end of map.
|
202
|
+
def self.remove_index_range(bin_name, index, count = nil, return_type: MapReturnType::NONE)
|
203
|
+
if count
|
204
|
+
MapOperation.new(Operation::CDT_MODIFY, REMOVE_BY_INDEX_RANGE, bin_name, index, count, return_type: return_type)
|
205
|
+
else
|
206
|
+
MapOperation.new(Operation::CDT_MODIFY, REMOVE_BY_INDEX_RANGE, bin_name, index, return_type: return_type)
|
207
|
+
end
|
208
|
+
end
|
209
|
+
|
210
|
+
##
|
211
|
+
# Create map remove operation.
|
212
|
+
# Server removes map item identified by rank and returns removed data specified by return_type.
|
213
|
+
def self.remove_by_rank(bin_name, rank, return_type: MapReturnType::NONE)
|
214
|
+
MapOperation.new(Operation::CDT_MODIFY, REMOVE_BY_RANK, bin_name, rank, return_type: return_type)
|
215
|
+
end
|
216
|
+
|
217
|
+
##
|
218
|
+
# Create map remove operation.
|
219
|
+
# Server selects "count" map items starting at specified rank and returns
|
220
|
+
# selected data specified by return_type. If "count" is not specified,
|
221
|
+
# server removes map items starting at specified rank to the last ranked.
|
222
|
+
def self.remove_by_rank_range(bin_name, rank, count = nil, return_type: MapReturnType::NONE)
|
223
|
+
if count
|
224
|
+
MapOperation.new(Operation::CDT_MODIFY, REMOVE_BY_RANK_RANGE, bin_name, rank, count, return_type: return_type)
|
225
|
+
else
|
226
|
+
MapOperation.new(Operation::CDT_MODIFY, REMOVE_BY_RANK_RANGE, bin_name, rank, return_type: return_type)
|
227
|
+
end
|
228
|
+
end
|
229
|
+
|
230
|
+
##
|
231
|
+
# Create map size operation.
|
232
|
+
# Server returns size of map.
|
233
|
+
def self.size(bin_name)
|
234
|
+
MapOperation.new(Operation::CDT_READ, SIZE, bin_name)
|
235
|
+
end
|
236
|
+
|
237
|
+
##
|
238
|
+
# Create map get by key operation.
|
239
|
+
# Server selects map item identified by key and returns selected data specified by return_type.
|
240
|
+
def self.get_key(bin_name, key, return_type: MapReturnType::NONE)
|
241
|
+
MapOperation.new(Operation::CDT_READ, GET_BY_KEY, bin_name, key, return_type: return_type)
|
242
|
+
end
|
243
|
+
|
244
|
+
# Create map get by key range operation.
|
245
|
+
# Server selects map items identified by key range (key_begin inclusive, key_end exclusive).
|
246
|
+
# If key_begin is null, the range is less than key_end.
|
247
|
+
# If key_end is null, the range is greater than equal to key_begin.
|
248
|
+
# <p>
|
249
|
+
# Server returns selected data specified by return_type.
|
250
|
+
def self.get_key_range(bin_name, key_begin, key_end = nil, return_type: MapReturnType::NONE)
|
251
|
+
if key_end
|
252
|
+
MapOperation.new(Operation::CDT_READ, GET_BY_KEY_INTERVAL, bin_name, key_begin, key_end, return_type: return_type)
|
253
|
+
else
|
254
|
+
MapOperation.new(Operation::CDT_READ, GET_BY_KEY_INTERVAL, bin_name, key_begin, return_type: return_type)
|
255
|
+
end
|
256
|
+
end
|
257
|
+
|
258
|
+
# Create map get by value operation.
|
259
|
+
# Server selects map items identified by value and returns selected data specified by return_type.
|
260
|
+
def self.get_value(bin_name, value, return_type: MapReturnType::NONE)
|
261
|
+
MapOperation.new(Operation::CDT_READ, GET_BY_VALUE, bin_name, value, return_type: return_type)
|
262
|
+
end
|
263
|
+
|
264
|
+
# Create map get by value range operation.
|
265
|
+
# Server selects map items identified by value range (value_begin inclusive, value_end exclusive)
|
266
|
+
# If value_begin is null, the range is less than value_end.
|
267
|
+
# If value_end is null, the range is greater than equal to value_begin.
|
268
|
+
# <p>
|
269
|
+
# Server returns selected data specified by return_type.
|
270
|
+
def self.get_value_range(bin_name, value_begin, value_end = nil, return_type: MapReturnType::NONE)
|
271
|
+
if value_end
|
272
|
+
MapOperation.new(Operation::CDT_READ, GET_BY_VALUE_INTERVAL, bin_name, value_begin, value_end, return_type: return_type)
|
273
|
+
else
|
274
|
+
MapOperation.new(Operation::CDT_READ, GET_BY_VALUE_INTERVAL, bin_name, value_begin, return_type: return_type)
|
275
|
+
end
|
276
|
+
end
|
277
|
+
|
278
|
+
# Create map get by index operation.
|
279
|
+
# Server selects map item identified by index and returns selected data specified by return_type.
|
280
|
+
def self.get_index(bin_name, index, return_type: MapReturnType::NONE)
|
281
|
+
MapOperation.new(Operation::CDT_READ, GET_BY_INDEX, bin_name, index, return_type: return_type)
|
282
|
+
end
|
283
|
+
|
284
|
+
# Create map get by index range operation.
|
285
|
+
# Server selects "count" map items starting at specified index and
|
286
|
+
# returns selected data specified by return_type. If "count" is not
|
287
|
+
# specified, server selects map items starting at specified index to the
|
288
|
+
# end of map.
|
289
|
+
def self.get_index_range(bin_name, index, count = nil, return_type: MapReturnType::NONE)
|
290
|
+
if count
|
291
|
+
MapOperation.new(Operation::CDT_READ, GET_BY_INDEX_RANGE, bin_name, index, count, return_type: return_type)
|
292
|
+
else
|
293
|
+
MapOperation.new(Operation::CDT_READ, GET_BY_INDEX_RANGE, bin_name, index, return_type: return_type)
|
294
|
+
end
|
295
|
+
end
|
296
|
+
|
297
|
+
# Create map get by rank operation.
|
298
|
+
# Server selects map item identified by rank and returns selected data
|
299
|
+
# specified by return_type.
|
300
|
+
def self.get_by_rank(bin_name, rank, return_type: MapReturnType::NONE)
|
301
|
+
MapOperation.new(Operation::CDT_READ, GET_BY_RANK, bin_name, rank, return_type: return_type)
|
302
|
+
end
|
303
|
+
|
304
|
+
# Create map get by rank range operation.
|
305
|
+
# Server selects "count" map items starting at specified rank and returns
|
306
|
+
# selected data specified by returnType. If "count" is not specified,
|
307
|
+
# server selects map items starting at specified rank to the last ranked
|
308
|
+
# item.
|
309
|
+
def self.get_by_rank_range(bin_name, rank, count = nil, return_type: MapReturnType::NONE)
|
310
|
+
if count
|
311
|
+
MapOperation.new(Operation::CDT_READ, GET_BY_RANK_RANGE, bin_name, rank, count, return_type: return_type)
|
312
|
+
else
|
313
|
+
MapOperation.new(Operation::CDT_READ, GET_BY_RANK_RANGE, bin_name, rank, return_type: return_type)
|
314
|
+
end
|
315
|
+
end
|
316
|
+
|
317
|
+
def and_return(return_type)
|
318
|
+
@return_type = return_type
|
319
|
+
@bin_value = nil
|
320
|
+
self
|
321
|
+
end
|
322
|
+
|
323
|
+
def bin_value
|
324
|
+
@bin_value ||= pack_bin_value
|
325
|
+
end
|
326
|
+
|
327
|
+
private
|
328
|
+
|
329
|
+
def pack_bin_value
|
330
|
+
bytes = nil
|
331
|
+
Packer.use do |packer|
|
332
|
+
packer.write_raw_short(map_op)
|
333
|
+
args = arguments.dup
|
334
|
+
args.unshift(return_type) if return_type
|
335
|
+
if policy && policy.write_mode != MapWriteMode::UPDATE_ONLY
|
336
|
+
args << policy.value
|
337
|
+
end
|
338
|
+
if args.length > 0
|
339
|
+
packer.write_array_header(args.length)
|
340
|
+
args.each do |value|
|
341
|
+
Value.of(value).pack(packer)
|
342
|
+
end
|
343
|
+
end
|
344
|
+
bytes = packer.bytes
|
345
|
+
end
|
346
|
+
BytesValue.new(bytes)
|
347
|
+
end
|
348
|
+
|
349
|
+
end
|
350
|
+
|
351
|
+
end
|
352
|
+
end
|