Put an existing record and touch in atomic operation not working

NameSpace - person
Set - personData
PersonId (Key) | name (bin name)| birthDate (bin name)

NameSpace - person
Set - cityVisitedData
PersonId+CityVisited (Key)| cityName (bin name) | personId (bin name)

UseCase: put onto existing record and extend TTL.

I am trying to put the record and extend TTL in atomic operation but when I add Operation.touch() then no record is inserted and if i remove then record is inserted properly.

client.operate(writePolicy, profileKey, Operation.put(PersonId), Operation.put(name), Operation.put(birthDate),Operation.touch());


You need to show a few more lines of code there. The WritePolicy is where the TTL is defined, otherwise the touch should pick up the default TTL for the namespace. What is that value in your person namespace?


Thanks Ronen for the reply. Below is sample test code.

public class PersonTest {
	private AerospikeClient client;
	private WritePolicy writePolicy;

	public PersonTest() throws AerospikeException {
		ClientPolicy clientPolicy = new ClientPolicy();		
		Host host=new Host(aerospikeHost, aerospikePort);				
		client = new com.aerospike.client.AerospikeClient(clientPolicy, host);
		writePolicy = new WritePolicy();
		writePolicy.maxRetries = 3;
		writePolicy.timeout = 5000;
		writePolicy.expiration = 3 * 60;

	public void addPerson() throws AerospikeException {
		Key key = new Key("profile", "personData", Value.get("personId"));
		Bin channels = new Bin("firstName", Value.get("testFirstName"));
		Bin name = new Bin("lastName", Value.get("testLastName"));
		client.operate(writePolicy, key, Operation.put(channels), Operation.put(name), Operation.touch());  

	public static void main(String[] args) throws AerospikeException {
		PersonTest person = new PersonTest();

Assume there is no record currently in aerospike then at addPerson() method on client.operate() code if we have Operation.touch() in last option then record is not inserted where as if we remove operation.touch() then record is inserted properly. Basically i want to try to achieve that if record exists then simply touch the record to extend expiration period but here if record is not present it is not even inserted with the above code.

Configuration for namespace is as below:

namespace profile{ replication-factor 2 memory-size 4G default-ttl 30d store-engine memory }