Exist call in aeropsike client

New to aerospike. Just wondering what’s the different between exist and get call, performance wise, in aerospike client.

Do I really need to check if the key exists and then do the retrieval with get? Will that be causing an extra call to the aerospike server and therefore much latency?

Can I use just one get call and decide what to do by checking whether the returned record is null or not?

If there any other optimization going on under the hood?

Could anyone please explain that? Many thanks in advance.

Hi @H2_L, welcome to the forum!

exists only checks the existence of the Primary Index; it does not access the record from its storage location. You can also use only one get call; if the record does not exist, you would get a not found. Check out more information about record operations in our docs.

If your data model does need to know if the record already exists, you can use the write mode WritePolicy.recordExistsAction to specify how to handle writes where the record already exists.