发表时间:2010-03-17
最后修改:2010-03-17
memcached 在压缩数据,在get 时出现objectoutstream 报错,解决办法,关闭 memcached 压缩
public class Memcached {
private static MemCachedClient client = new MemCachedClient();
static {
String[] servers = {"192.168.0.1:11211"};
Integer[] weights = {new Integer(1)};
SockIOPool pool = SockIOPool.getInstance();
pool.setServers( servers );
pool.setWeights( weights );
pool.setHashingAlg(SockIOPool.NEW_COMPAT_HASH);
pool.initialize();
client.setCompressEnable(false);
}
public static Object get(String key) {
return client.get(key);
}
public static boolean set(String key, Object value) {
if (value == null)
return false;
return client.set(key, value);
}
public static boolean remove(String key) {
return client.delete(key);
}
public static boolean set(String key, Object value, java.util.Date expire) {
if (value == null)
return false;
return client.set(key, value, expire);
}
public static boolean set(String key, Object value, int calendar,int time) {
if (value == null)
return false;
Calendar expire = Calendar.getInstance();
expire.add(calendar, time);
return client.set(key, value, expire.getTime());
}
}