beansdb4jbeansdb的java客户端
这是beansdb的java客户端, 它使用了和python客户端一模一样的hash算法, 所以它和python客户端是完全兼容 — 这意味着你可以用python客户端存一个东西进beansdb, 然后用java客户端把它取出来。
示例代码:
// specify the beansdb nodes.
Map<InetSocketAddress, Range> servers = new HashMap<InetSocketAddress, Range>();
servers.put(new InetSocketAddress("localhost", 7900), new Range(, 16));
servers.put(new InetSocketAddress("localhost", 7901), new Range(, 16));
servers.put(new InetSocketAddress("localhost", 7902), new Range(, 16));
// 3,2,2 is the NRW number in the Dynamo thesis
Beansdb db = new Beansdb(servers, 16, 3, 2, 2);
// set the key: foo to value: bar
db.set("foo", "bar");
// get the value of foo
System.out.println(db.get("foo"));
// get the value for keys: hello, james, foo
List<String> keys = new ArrayList<String>(3);
keys.add("hello");
keys.add("james");
keys.add("foo");
Map<String, Object> ret = db.getMulti(keys);
for (String key : ret.keySet()) {
System.out.println(key + " : " + ret.get(key));
}
// delete the key: foo
db.delete("foo");
// close the db connection
db.close();
评论