Java Redis 客户端:labs-redis
jopen
11年前
labs-redis是一个使用JBoss Netty (N)IO开发的Java Redis 客户端。
labs-redis公开两个级别的API。最低水平实现了Redis的请求/响应协议。
// creates a protocol client connecting to 127.0.0.1 RedisProtocolClient client = new RedisProtocolClient(); // sends PING and prints response System.out.println("ping -> " + client.send("PING").asString());
暴露的Redis命令API
RedisClient client = new RedisClient("127.0.0.1", 6379); // set a value and wait for server response // set() returns a ResponseFuture client.set("mykey", "myvalue").block(); // the future allows client to control timeouts Object value = client. get("mykey"). withTimeout(1, TimeUnit.SECONDS); System.out.println("mykey = " + value); // and response type demarshalling and conversions String value2 = client.get("mykey").asString(); System.out.println("mykey = " + value2);