Function increment

  • Increments the value at the given list index and returns the new value after increment.

    Parameters

    • bin: string

      The name of the bin. The bin must contain a List value.

    • index: number

      Index of the list element to increment.

    • Optionalvalue: number

      Value to increment the element by. Default is 1.

    • Optionalpolicy: policy.ListPolicy

      Optional list policy.

    Returns ListOperation

    Operation that can be passed to the Client#operate command.

    v2.4

    const Aerospike = require('aerospike')
    const lists = Aerospike.lists
    const key = new Aerospike.Key('test', 'demo', 'mykey1')

    var ops = [
    lists.increment('counters', 1, 3)
    ]

    // INSERT HOSTNAME AND PORT NUMBER OF AEROSPIKE SERVER NODE HERE!
    var config = {
    hosts: '192.168.33.10:3000',
    // Timeouts disabled, latency dependent on server location. Configure as needed.
    policies: {
    read : new Aerospike.ReadPolicy({socketTimeout : 0, totalTimeout : 0}),
    write : new Aerospike.WritePolicy({socketTimeout : 0, totalTimeout : 0}),
    operate : new Aerospike.OperatePolicy({socketTimeout : 0, totalTimeout : 0})
    }
    }

    Aerospike.client(config).connect((error, client) => {
    if (error) throw error
    client.put(key, { counters: [1, 2, 3] }, (error) => {
    if (error) throw error
    client.operate(key, ops, (error, result) => {
    if (error) throw error
    console.log(result['bins']['counters']) // => 5
    client.get(key, (error, record) => {
    if (error) throw error
    console.log(record['bins']['counters']) // => { [1, 5, 3] }
    client.close()
    })
    })
    })
    })
MMNEPVFCICPMFPCPTTAAATR