3

I am using the NodeJS client for aerospike, and trying to set the ttl for a record, below is the code for the same.

insert(key, value) {
    return new Promise(function (resolve, reject) {
        aerospike.put(key, value, function (err) {
            if (err.code !== aerospikeStatus.AEROSPIKE_OK) {
                reject("Failed to insert in secondary storage");
            }
            else {
                resolve(true);
            }
        });
    });
}

I am following the official documentation, but unable to find the a way to set ttl through NodeJS client. Would someone happen to know how to do the same?

(http://www.aerospike.com/docs/client/nodejs/usage/kvs/write.html)

Ajay Pal Singh
  • 682
  • 1
  • 5
  • 16
  • 1
    Please refer to the API docs at http://www.aerospike.com/apidocs/nodejs/ for full details about the supported database operations. E.g. the documentation for the PUT call can be found [here](http://www.aerospike.com/apidocs/nodejs/Client.html#put__anchor). – Jan Hecking May 09 '16 at 16:20

1 Answers1

3

Actually, there are four parameters of put function, (key, record, metadata, policy).
You can see the example here. The following is my simple code to show how to set ttl:

  var key = new Aerospike.Key(ns, set, "ask")

  var rec = {
    as_bin: 'bin-content'
  }

  var meta = {
      ttl: 1000
  }

  var policy = {
    key: Aerospike.policy.key.SEND
  }

  client.put(key, rec, meta, policy, function (error) {
    if (error) {
        console.log('error: %s', error.message)
    } else {
      console.log('Record written to database successfully.')
    }
  })
sel-fish
  • 4,308
  • 2
  • 20
  • 39