Вы можете избежать использования такого списка, используя флаг LIST_WRITE_INSERT_BOUNDED
как часть политики операции со списком. Такая операция выдает определенный c код ошибки 26. Например (Python):
from __future__ import print_function
import aerospike
import sys
from aerospike_helpers.operations import list_operations as lh
config = {"hosts": [("127.0.0.1", 3000)]}
try:
client = aerospike.client(config).connect()
except e.ClientError:
print("Error: {0} [{1}]".format(e.msg, e.code))
sys.exit(1)
key = ("test", "example", "here")
try:
client.remove(key)
except:
pass
try:
ops = [
# increment the seventh element of a non-existent record with boundary
# restriction
lh.list_increment(
"incre", 7, 2, {"write_flags": aerospike.LIST_WRITE_INSERT_BOUNDED}
)
]
k, m, b = client.operate(key, ops)
except Exception as e:
print("Error: {0} [{1}]".format(e.msg, e.code))
print("Could not increment outside the boundary, in this case no record\n")
# try again, without limit on inserting into the bounds of the list
try:
ops = [
# increment the seventh element of a non-existent record
lh.list_increment(
"incre", 7, 2, {}
)
]
k, m, b = client.operate(key, ops)
(key, meta, bins) = client.get(key)
print(bins)
ops = [
# increment the sixth element of the newly created record
lh.list_increment(
"incre", 6, 1, {}
)
]
k, m, b = client.operate(key, ops)
except Exception as e:
print("Error: {0} [{1}]".format(e.msg, e.code))
print("Can't increment a None (NIL) value\n")
client.close()
, который выдает
Error: 127.0.0.1:3000 AEROSPIKE_ERR_OP_NOT_APPLICABLE [26]
Could not increment outside the boundary, in this case no record
{'incre': [None, None, None, None, None, None, None, 2]}
Error: 127.0.0.1:3000 AEROSPIKE_ERR_REQUEST_INVALID [4]
Can't increment a None (NIL) value
В клиенте Java это это ListWriteFlag.INSERT_BOUNDED
флаг ListPolicy
.
Но на самом деле, если у вас есть кортеж, где позиции 0-6 имеют специфику c это означает, что вы должны инициализировать корзину с [0, 0, 0, 0, 0, 0, 0]
.