Class: Aerospike::CDT::ListOperation

Inherits:
Object
  • Object
show all
Defined in:
lib/aerospike/cdt/list_operation.rb

Overview

List bin operations. Create list operations used by the Client#operate command. List operations support negative indexing. If the index is negative, the resolved index starts backwards from end of list.

Index/Range examples:

  • Index 0: First item in list.

  • Index 4: Fifth item in list.

  • Index -1: Last item in list.

  • Index -3: Third to last item in list.

  • Index 1 Count 2: Second and third items in list.

  • Index -3 Count 3: Last three items in list.

  • Index -5 Count 4: Range between fifth to last item to second to last item inclusive.

If an index is out of bounds, a parameter error will be returned. If a range is partially out of bounds, the valid part of the range will be returned.

Constant Summary collapse

APPEND =
1
APPEND_ITEMS =
2
INSERT =
3
INSERT_ITEMS =
4
POP =
5
POP_RANGE =
6
REMOVE =
7
REMOVE_RANGE =
8
SET =
9
TRIM =
10
CLEAR =
11
SIZE =
16
GET =
17
GET_RANGE =
18

Class Method Summary collapse

Class Method Details

.append(bin_name, *values) ⇒ Object

Create list append operation.

Server appends value(s) to end of the list bin.
Server returns list size.


60
61
62
63
64
65
66
# File 'lib/aerospike/cdt/list_operation.rb', line 60

def self.append(bin_name, *values)
  if values.length > 1
    create_operation(Operation::CDT_MODIFY, APPEND_ITEMS, bin_name, values)
  else
    create_operation(Operation::CDT_MODIFY, APPEND, bin_name, values.first)
  end
end

.clear(bin_name) ⇒ Object

Create list clear operation. Server removes all items in the list bin. Server does not return a result by default.



149
150
151
# File 'lib/aerospike/cdt/list_operation.rb', line 149

def self.clear(bin_name)
  create_operation(Operation::CDT_MODIFY, CLEAR, bin_name)
end

.get(bin_name, index) ⇒ Object

Create list get operation. Server returns the item at the specified index in the list bin.



163
164
165
# File 'lib/aerospike/cdt/list_operation.rb', line 163

def self.get(bin_name, index)
  create_operation(Operation::CDT_READ, GET, bin_name, index)
end

.get_range(bin_name, index, count = nil) ⇒ Object

Create list get range operation. Server returns “count” items starting at the specified index in the list bin. If “count” is not specified, the server returns all items starting at the specified index to the end of the list.



172
173
174
175
176
177
178
# File 'lib/aerospike/cdt/list_operation.rb', line 172

def self.get_range(bin_name, index, count=nil)
  if count
    create_operation(Operation::CDT_READ, GET_RANGE, bin_name, index, count)
  else
    create_operation(Operation::CDT_READ, GET_RANGE, bin_name, index)
  end
end

.insert(bin_name, index, *values) ⇒ Object

Create list insert operation.

Server inserts value(s) at the specified index of the list bin.
Server returns list size.


72
73
74
75
76
77
78
# File 'lib/aerospike/cdt/list_operation.rb', line 72

def self.insert(bin_name, index, *values)
  if values.length > 1
    create_operation(Operation::CDT_MODIFY, INSERT_ITEMS, bin_name, index, values)
  else
    create_operation(Operation::CDT_MODIFY, INSERT, bin_name, index, values.first)
  end
end

.pop(bin_name, index) ⇒ Object

Create list pop operation. Server returns item at specified index and removes item from list bin.



83
84
85
# File 'lib/aerospike/cdt/list_operation.rb', line 83

def self.pop(bin_name, index)
  create_operation(Operation::CDT_MODIFY, POP, bin_name, index)
end

.pop_range(bin_name, index, count = nil) ⇒ Object

Create list pop range operation. Server returns “count” items starting at specified index and removes items from list bin. If “count” is not specified, the server returns items starting at the specified index to the end of the list and removes those items from the list bin.



93
94
95
96
97
98
99
# File 'lib/aerospike/cdt/list_operation.rb', line 93

def self.pop_range(bin_name, index, count=nil)
  if count
    create_operation(Operation::CDT_MODIFY, POP_RANGE, bin_name, index, count)
  else
    create_operation(Operation::CDT_MODIFY, POP_RANGE, bin_name, index)
  end
end

.remove(bin_name, index) ⇒ Object

Create list remove operation. Server removes item at specified index from list bin. Server returns number of items removed.



105
106
107
# File 'lib/aerospike/cdt/list_operation.rb', line 105

def self.remove(bin_name, index)
  create_operation(Operation::CDT_MODIFY, REMOVE, bin_name, index)
end

.remove_range(bin_name, index, count = nil) ⇒ Object

Create list remove range operation. Server removes “count” items at specified index from list bin. If “count” is not specified, the server removes all items starting at the specified index to the end of the list. Server returns number of items removed.



115
116
117
118
119
120
121
# File 'lib/aerospike/cdt/list_operation.rb', line 115

def self.remove_range(bin_name, index, count=nil)
  if count
    create_operation(Operation::CDT_MODIFY, REMOVE_RANGE, bin_name, index, count)
  else
    create_operation(Operation::CDT_MODIFY, REMOVE_RANGE, bin_name, index)
  end
end

.set(bin_name, index, value) ⇒ Object

Create list set operation. Server sets item value at specified index in list bin. Server does not return a result by default.



127
128
129
# File 'lib/aerospike/cdt/list_operation.rb', line 127

def self.set(bin_name, index, value)
  create_operation(Operation::CDT_MODIFY, SET, bin_name, index, value)
end

.size(bin_name) ⇒ Object

Create list size operation. Server returns size of list.



156
157
158
# File 'lib/aerospike/cdt/list_operation.rb', line 156

def self.size(bin_name)
  create_operation(Operation::CDT_READ, SIZE, bin_name)
end

.trim(bin_name, index, count = nil) ⇒ Object

Create list trim operation. Server removes items in list bin that do not fall into range specified by index and count. If count is not specified, server will keep all items starting at the specified index to the end of the list. Server returns number of items removed.



137
138
139
140
141
142
143
# File 'lib/aerospike/cdt/list_operation.rb', line 137

def self.trim(bin_name, index, count=nil)
  if count
    create_operation(Operation::CDT_MODIFY, TRIM, bin_name, index, count)
  else
    create_operation(Operation::CDT_MODIFY, TRIM, bin_name, index)
  end
end