forked from aerospike/aerospike-client-go
-
Notifications
You must be signed in to change notification settings - Fork 1
/
large_list.go
262 lines (222 loc) · 8.88 KB
/
large_list.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
// Copyright 2013-2016 Aerospike, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package aerospike
// LargeList encapsulates a list within a single bin.
type LargeList struct {
*baseLargeObject
}
// NewLargeList initializes a large list operator.
func NewLargeList(client *Client, policy *WritePolicy, key *Key, binName string, userModule string) *LargeList {
return &LargeList{
baseLargeObject: newLargeObject(client, policy, key, binName, userModule, "llist"),
}
}
// Add adds values to the list.
// If the list does not exist, create it
func (ll *LargeList) Add(values ...interface{}) (err error) {
_, err = ll.client.Execute(ll.policy, ll.key, ll.packageName, "add", ll.binName, ToValueArray(values))
return err
}
// Update updates/adds each value in values list depending if key exists or not.
func (ll *LargeList) Update(values ...interface{}) (err error) {
_, err = ll.client.Execute(ll.policy, ll.key, ll.packageName, "update", ll.binName, ToValueArray(values))
return err
}
// Remove deletes value from list.
func (ll *LargeList) Remove(values ...interface{}) (err error) {
_, err = ll.client.Execute(ll.policy, ll.key, ll.packageName, "remove", ll.binName, ToValueArray(values))
return err
}
// Find selects values from list.
func (ll *LargeList) Find(value interface{}) ([]interface{}, error) {
res, err := ll.client.Execute(ll.policy, ll.key, ll.packageName, "find", ll.binName, NewValue(value))
if err != nil {
return nil, err
}
if res == nil {
return []interface{}{}, nil
}
return res.([]interface{}), err
}
// Do key/values exist? Return list of results in one batch call.
func (ll *LargeList) Exist(values ...interface{}) ([]bool, error) {
res, err := ll.client.Execute(ll.policy, ll.key, ll.packageName, "exists", ll.binName, NewValue(values))
if err != nil {
return nil, err
}
var ret []bool
if res == nil {
return make([]bool, len(values)), nil
} else {
ret = make([]bool, len(values))
resTyped := res.([]interface{})
for i := range resTyped {
ret[i] = resTyped[i].(int) != 0
}
}
return ret, err
}
// FindThenFilter selects values from list and applies specified Lua filter.
func (ll *LargeList) FindThenFilter(value interface{}, filterModule, filterName string, filterArgs ...interface{}) ([]interface{}, error) {
res, err := ll.client.Execute(ll.policy, ll.key, ll.packageName, "find", ll.binName, NewValue(value), NewValue(filterModule), NewValue(filterName), ToValueArray(filterArgs))
if err != nil {
return nil, err
}
if res == nil {
return []interface{}{}, nil
}
return res.([]interface{}), err
}
// FindFirst selects values from the beginning of list up to a maximum count.
func (ll *LargeList) FindFirst(count int) ([]interface{}, error) {
res, err := ll.client.Execute(ll.policy, ll.key, ll.packageName, "find_first", ll.binName, NewValue(count))
if err != nil {
return nil, err
}
if res == nil {
return []interface{}{}, nil
}
return res.([]interface{}), err
}
// FFilterThenindFirst selects values from the beginning of list up to a maximum count after applying lua filter.
func (ll *LargeList) FFilterThenindFirst(count int, filterModule, filterName string, filterArgs ...interface{}) ([]interface{}, error) {
res, err := ll.client.Execute(ll.policy, ll.key, ll.packageName, "find_first", ll.binName, NewValue(count), NewValue(filterModule), NewValue(filterName), ToValueArray(filterArgs))
if err != nil {
return nil, err
}
if res == nil {
return []interface{}{}, nil
}
return res.([]interface{}), err
}
// FindLast selects values from the end of list up to a maximum count.
func (ll *LargeList) FindLast(count int) ([]interface{}, error) {
res, err := ll.client.Execute(ll.policy, ll.key, ll.packageName, "find_last", ll.binName, NewValue(count))
if err != nil {
return nil, err
}
if res == nil {
return []interface{}{}, nil
}
return res.([]interface{}), err
}
// FilterThenFindLast selects values from the end of list up to a maximum count after applying lua filter.
func (ll *LargeList) FilterThenFindLast(count int, filterModule, filterName string, filterArgs ...interface{}) ([]interface{}, error) {
res, err := ll.client.Execute(ll.policy, ll.key, ll.packageName, "find_last", ll.binName, NewValue(count), NewValue(filterModule), NewValue(filterName), ToValueArray(filterArgs))
if err != nil {
return nil, err
}
if res == nil {
return []interface{}{}, nil
}
return res.([]interface{}), err
}
// FindFrom selects values from the begin key up to a maximum count.
func (ll *LargeList) FindFrom(begin interface{}, count int) ([]interface{}, error) {
res, err := ll.client.Execute(ll.policy, ll.key, ll.packageName, "find_from", ll.binName, NewValue(begin), NewValue(count))
if err != nil {
return nil, err
}
if res == nil {
return []interface{}{}, nil
}
return res.([]interface{}), err
}
// FilterThenFindFrom selects values from the begin key up to a maximum count after applying lua filter.
func (ll *LargeList) FilterThenFindFrom(begin interface{}, count int, filterModule, filterName string, filterArgs ...interface{}) ([]interface{}, error) {
res, err := ll.client.Execute(ll.policy, ll.key, ll.packageName, "find_from", ll.binName, NewValue(begin), NewValue(count), NewValue(filterModule), NewValue(filterName), ToValueArray(filterArgs))
if err != nil {
return nil, err
}
if res == nil {
return []interface{}{}, nil
}
return res.([]interface{}), err
}
// Range selects a range of values from the large list.
func (ll *LargeList) Range(begin, end interface{}) ([]interface{}, error) {
res, err := ll.client.Execute(ll.policy, ll.key, ll.packageName, "find_range", ll.binName, NewValue(begin), NewValue(end))
if err != nil {
return nil, err
}
if res == nil {
return []interface{}{}, nil
}
return res.([]interface{}), err
}
// RangeN selects a range of values up to a maximum count from the large list.
func (ll *LargeList) RangeN(begin, end interface{}, count int) ([]interface{}, error) {
res, err := ll.client.Execute(ll.policy, ll.key, ll.packageName, "find_range", ll.binName, NewValue(begin), NewValue(end), NewValue(count))
if err != nil {
return nil, err
}
if res == nil {
return []interface{}{}, nil
}
return res.([]interface{}), err
}
// RangeThenFilter selects a range of values from the large list then apply filter.
func (ll *LargeList) RangeThenFilter(begin, end interface{}, filterModule string, filterName string, filterArgs ...interface{}) ([]interface{}, error) {
res, err := ll.client.Execute(ll.policy, ll.key, ll.packageName, "range", ll.binName, NewValue(begin), NewValue(end), NewValue(0), NewValue(filterModule), NewValue(filterName), ToValueArray(filterArgs))
if err != nil {
return nil, err
}
if res == nil {
return []interface{}{}, nil
}
return res.([]interface{}), err
}
// RangeNThenFilter selects a range of values up to a maximum count from the large list then apply filter.
func (ll *LargeList) RangeNThenFilter(begin, end interface{}, count int, filterModule string, filterName string, filterArgs ...interface{}) ([]interface{}, error) {
res, err := ll.client.Execute(ll.policy, ll.key, ll.packageName, "range", ll.binName, NewValue(begin), NewValue(end), NewValue(count), NewValue(filterModule), NewValue(filterName), ToValueArray(filterArgs))
if err != nil {
return nil, err
}
if res == nil {
return []interface{}{}, nil
}
return res.([]interface{}), err
}
// Scan returns all objects in the list.
func (ll *LargeList) Scan() ([]interface{}, error) {
return ll.scan(ll)
}
// Filter selects values from list and apply specified Lua filter.
func (ll *LargeList) Filter(filterModule, filterName string, filterArgs ...interface{}) ([]interface{}, error) {
res, err := ll.client.Execute(ll.policy, ll.key, ll.packageName, "scan", ll.binName, NewValue(filterModule), NewValue(filterName), ToValueArray(filterArgs))
if err != nil {
return nil, err
}
if res == nil {
return []interface{}{}, nil
}
return res.([]interface{}), err
}
// Destroy deletes the bin containing the list.
func (ll *LargeList) Destroy() error {
return ll.destroy(ll)
}
// Size returns size of list.
func (ll *LargeList) Size() (int, error) {
return ll.size(ll)
}
// SetPageSize sets the LDT page size.
func (ll *LargeList) SetPageSize(pageSize int) error {
_, err := ll.client.Execute(ll.policy, ll.key, ll.packageName, "setPageSize", ll.binName, NewValue(pageSize))
return err
}
// GetConfig returns map of list configuration parameters.
func (ll *LargeList) GetConfig() (map[interface{}]interface{}, error) {
return ll.getConfig(ll)
}