Skip to Content

Java Client SDK

Installing Java client SDK

<dependency> <groupId>io.github.oxia-db</groupId> <artifactId>oxia-client</artifactId> <version>${VERSION}</version> </dependency>

Javadoc documentation is available at https://oxia-db.github.io/oxia-client-java/apidocs/latest 

Sync and Async APIs

Oxia provides two API flavors in the client:

  • Sync: Easier and convenient to use. Methods are blocking and return the result of the operation.
  • Async: Returns futures to track completion of the operations. Allows having more operations outstanding and achieving higher throughput.

Client API

Initializing the client

To use the Oxia client, you need to create a client instance. Once created, a client instance will be valid until it’s explicitly closed, and it can be used from different threads.

SyncOxiaClient client = OxiaClientBuilder.create("localhost:6648") .namespace("my-namespace") .syncClient();

For the full list of options when creating an Oxia clint, please refer to the OxiaClientBuilder Javadocs .

Writing records

// Write a record to Oxia with the specified key and value, and with the expectation // that the record does not already exist. PutResult res = client.put("my-key", "my-value".getBytes(), Set.of(IfRecordDoesNotExist)); // Write a record with the expectation that it has not changed since the previous write. // If there was any change, the operation will fail client.put("my-key", "my-value-2".getBytes(), Set.of(IfVersionIdEquals(res.version().versionId())));

All the options for the put operation are available in the Javadocs .

Reading records

Reading the value of a record

GetResult res = client.get("my-key"); log.info("Got key: {} - value: {} - version: {}", res.getKey(), res.getValue(), res.getVersion());

All the options for the get operation are available in the Javadocs .

Last updated on