我正在使用 aspymemcached 客户端连接到我的 membase 服务器。代码如下:
public static MemcachedClient MemcachedClient(String bucketName){
URI server1 = new URI("http://192.168.100.111:8091/pools");
URI server2 = new URI("http://127.0.0.1:8091/pools");
ArrayList<URI> serverList = new ArrayList<URI>();
serverList.add(server1);
serverList.add(server2);
return new MemcachedClient(serverList, bucketName, "");
}
将对象放入缓存:
public static void makeMembaseCacheEntry(final String key, final int expiryTime, final Object value, final String bucketName) {
MemcachedClient client = getMembaseClient(bucketName);
if (client != null) {
client.set(key, expiryTime, value);
}
从缓存中获取对象:
public static Object getMembaseCacheEntry(String key) {
Object value = null;
try {
MemcachedClient client = getMembaseClient(bucketName);
if (client != null) {
value = client.get(key);
}
} catch (Exception e) {
}
return value;
}
现在我计划将 membase 服务器升级到 couchbase 服务器,因此我必须使用 couchbase 客户端 java API(参考:http ://docs.couchbase.com/developer/java-2.1/java-intro.html )。在 cousebase 客户端中,所有操作都在 JsonObject ref 上执行:
http://docs.couchbase.com/developer/java-2.0/documents-basics.html
那么如何将以上两种方法迁移到couchbase客户端