这是beansdb的java客户端,它使用了和python客户端一模一样的hash算法,所以它和python客户端是完全兼容—这意味着你可以用python客户端存一个东西进beansdb,然后用java客户端把它取出来。
示例代码:
//specifythebeansdbnodes. Map<InetSocketAddress,Range>servers=newHashMap<InetSocketAddress,Range>(); servers.put(newInetSocketAddress("localhost",7900),newRange(,16)); servers.put(newInetSocketAddress("localhost",7901),newRange(,16)); servers.put(newInetSocketAddress("localhost",7902),newRange(,16)); //3,2,2istheNRWnumberintheDynamothesis Beansdbdb=newBeansdb(servers,16,3,2,2); //setthekey:footovalue:bar db.set("foo","bar"); //getthevalueoffoo System.out.println(db.get("foo")); //getthevalueforkeys:hello,james,foo List<String>keys=newArrayList<String>(3); keys.add("hello"); keys.add("james"); keys.add("foo"); Map<String,Object>ret=db.getMulti(keys); for(Stringkey:ret.keySet()){ System.out.println(key+":"+ret.get(key)); } //deletethekey:foo db.delete("foo"); //closethedbconnection db.close();
评论