-
Notifications
You must be signed in to change notification settings - Fork 93
Dyno Jedis Client Examples
opuneet edited this page Oct 13, 2014
·
3 revisions
DynoJedisClient client = new DynoJedisClient.Builder()
.withApplicationName("demo")
.withDynomiteClusterName("MY DYNOMITE CLUSTER")
.withHostSupplier(hostSupplier)
.withCPConfig(new ConnectionPoolConfigurationImpl("MY APP NAME"))
.withPort(port)
.build();
int numKeys = 11;
// write
for (int i=0; i<numKeys; i++) {
client.set("DynoTest" + i, "" + i);
}
// read
for (int i=0; i<numKeys; i++) {
String result = ;
System.out.println("Key: " + i + ", Value: " + client.get("DynoTest"+i));
}
There is an alternate api for every operation in Dyno. This gives some metadata about the call.
for (int i=0; i<numKeys; i++) {
OperationResult<String> result = client.d_get("DynoTest"+i);
System.out.println("Key: " + i + ", Value: " + result.getResult() + " " + result.getNode());
}
Dyno also supports Redis commands pipelining as provided by the Jedis client underneath.
Note - Since Dyno is token aware and uses the specific connection, you must ensure that you use the same keys for the pipeline example
DynoJedisPipeline pipeline = client.pipelined();
Response<Long> resultA1 = pipeline.hset("pipelinetest", "a1", "v1");
Response<Long> resultA2 = pipeline.hset("pipelinetest", "a2", "v2");
pipeline.sync();
System.out.println(resultA1.get());
System.out.println(resultA2.get());
A Netflix Original Production
Tech Blog | Twitter @NetflixOSS | Jobs