Search code examples
aerospike

Read policy for aerospike java client


I am working with com.aerospike:aerospike-client:4.0.6

When reading the records client.get() expects policy. However I could not find exactly what to be passed here Its working with null, but I cannot find REadPolicy (like its there for Write). Is it ok to send null for policy, or is there better use of policy when reading the records


Solution

  • Send null to use read Policy defaults. There are few read policy options that you can set. Usually defaults is all you need.

    For reads, you create a Policy object and you can set timeout, maximum retries, sleep between retries, consistency level etc. replica is also an interesting one replica.RANDOM can be used if deploying Aerospike in a look up table design - Read Java API docs help on "Policy" and see all the ones that apply to read operations. For replica settings, explore Replica further in the help. http://www.aerospike.com/apidocs/java/

    eg:
    // Java policy
    Policy policy = new Policy();
    policy.timeout = 50; // 50 milliseconds