This repository has been archived by the owner on Feb 11, 2022. It is now read-only.
forked from aerospike/aerospike-client-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
large_map.go
124 lines (104 loc) · 3.84 KB
/
large_map.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
// Copyright 2013-2015 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.
/////////////////////////////////////////////////////////////
//
// NOTICE:
// THIS FEATURE HAS BEEN DEPRECATED ON SERVER.
// THE API WILL BE REMOVED FROM THE CLIENT IN THE FUTURE.
//
/////////////////////////////////////////////////////////////
package aerospike
// LargeMap encapsulates a map within a single bin.
type LargeMap struct {
*baseLargeObject
}
// NewLargeMap initializes a large map operator.
func NewLargeMap(client *Client, policy *WritePolicy, key *Key, binName string, userModule string) *LargeMap {
return &LargeMap{
baseLargeObject: newLargeObject(client, policy, key, binName, userModule, "lmap"),
}
}
// Put adds an entry to the map.
// If the map does not exist, create it using specified userModule configuration.
func (lm *LargeMap) Put(name interface{}, value interface{}) error {
_, err := lm.client.Execute(lm.policy, lm.key, lm.packageName, "put", lm.binName, NewValue(name), NewValue(value), lm.userModule)
return err
}
// PutMap adds map values to the map.
// If the map does not exist, create it using specified userModule configuration.
func (lm *LargeMap) PutMap(theMap map[interface{}]interface{}) error {
_, err := lm.client.Execute(lm.policy, lm.key, lm.packageName, "put_all", lm.binName, NewMapValue(theMap), lm.userModule)
return err
}
// Check existence of key in the map.
func (lm *LargeMap) Exists(keyValue interface{}) (bool, error) {
res, err := lm.client.Execute(lm.policy, lm.key, lm.packageName, "exists", lm.binName, NewValue(keyValue))
if err != nil {
return false, err
}
if res == nil {
return false, nil
}
return (res.(int) != 0), err
}
// Get returns value from map corresponding with the provided key.
func (lm *LargeMap) Get(name interface{}) (map[interface{}]interface{}, error) {
res, err := lm.client.Execute(lm.policy, lm.key, lm.packageName, "get", lm.binName, NewValue(name))
if err != nil {
return nil, err
}
if res == nil {
return nil, nil
}
return res.(map[interface{}]interface{}), err
}
// Remove deletes a value from map given a key.
func (lm *LargeMap) Remove(name interface{}) error {
_, err := lm.client.Execute(lm.policy, lm.key, lm.packageName, "remove", lm.binName, NewValue(name))
return err
}
// Scan returns all objects in the map.
func (lm *LargeMap) Scan() (map[interface{}]interface{}, error) {
res, err := lm.client.Execute(lm.policy, lm.key, lm.packageName, "scan", lm.binName)
if err != nil {
return nil, err
}
if res == nil {
return nil, nil
}
return res.(map[interface{}]interface{}), err
}
// Filter selects items from the map.
func (lm *LargeMap) Filter(filterName string, filterArgs ...interface{}) (map[interface{}]interface{}, error) {
res, err := lm.client.Execute(lm.policy, lm.key, lm.packageName, "filter", lm.binName, lm.userModule, NewStringValue(filterName), ToValueArray(filterArgs))
if err != nil {
return nil, err
}
if res == nil {
return nil, nil
}
return res.(map[interface{}]interface{}), err
}
// Destroy deletes the bin containing the map.
func (lm *LargeMap) Destroy() error {
return lm.destroy(lm)
}
// Size returns size of the map.
func (lm *LargeMap) Size() (int, error) {
return lm.size(lm)
}
// GetConfig returns map of map configuration parameters.
func (lm *LargeMap) GetConfig() (map[interface{}]interface{}, error) {
return lm.getConfig(lm)
}