使用Aerospike操作命令创建记录

问题描述 投票:0回答:1

我正在尝试遵循以下代码。出现“找不到密钥”错误。我想知道是否可以使用Aerospike Multi Ops创建记录。

public long incrementSingle(String counterName, long by){

        // Create a key
        Key recordKey = new Key(Constants.NAMESPACE, Constants.SINGLE_SET, counterName);

        // Increment operation
        Bin incrementCounter = new Bin(Constants.SINGLE_COUNTER_BIN, by);

        // https://www.aerospike.com/docs/client/java/usage/kvs/multiops.html#operation-specification
        Record record = asClient.operate(null, recordKey, 
                            Operation.add(incrementCounter), 
                            Operation.get(Constants.SINGLE_COUNTER_BIN));

        return record.getLong(Constants.SINGLE_COUNTER_BIN);
    } 
aerospike
1个回答
0
投票

我认为要使add()起作用,记录必须之前存在。测试在计数器仓中创建带有record初值(例如初始化为0)的recordKey所引用的记录,然后对其递增。 add()的Operation API并未具体指出这一点,但是我只是在猜测,因为add()首先会读取磁盘上的现有记录,也许找不到它。

© www.soinside.com 2019 - 2024. All rights reserved.