java_memcached 本身的api add的数据,get也可以读取数据没问题。用memadmin也可以查询数据。
用memadmin录入数据,memadmin展示也没有问题。但用java_memcached客户端无法获取数据?为什么?
80 [main] ERROR com.danga.MemCached.MemCachedClient - ++++ exception thrown while trying to
get object from cache for key: t
80 [main] ERROR com.danga.MemCached.MemCachedClient - invalid stream header: 74747474
java.io.StreamCorruptedException: invalid stream header: 74747474
at java.io.ObjectInputStream.readStreamHeader(ObjectInputStream.java:782)
at java.io.ObjectInputStream.<init>(ObjectInputStream.java:279)
at com.schooner.MemCached.ObjectTransCoder.decode(Unknown Source)
at com.schooner.MemCached.AscIIClient.get(Unknown Source)
at com.schooner.MemCached.AscIIClient.get(Unknown Source)
at com.schooner.MemCached.AscIIClient.get(Unknown Source)
at com.danga.MemCached.MemCachedClient.get(Unknown Source)
at com.sloth.memcached.MemcachedClient.get(MemcachedClient.java:35)
at com.sloth.memcached.Test.<init>(Test.java:19)
at com.sloth.memcached.Test.main(Test.java:26)
------解决方案--------------------
大家用缓存很少?
------解决方案--------------------
数据放到不同的slabs中不能用get统一读取?
------解决方案--------------------
无源码无真相,不过本人还是觉得 你MemCachedClient 的初始化配置有关
------解决方案--------------------
核心初始化
private MemcachedClientFactory() {
String[] servers = MemcachedClientProperty.MemcachedServers.split(",");
Integer[] weights = null;
String weightsCfg = MemcachedClientProperty.MemcachedWeights;
if(weightsCfg != null){
String[] wcfg = weightsCfg.split(",");
weights = new Integer[wcfg.length];
for (int i = 0; i < weights.length; i++) {
weights[i] = Integer.valueOf(wcfg[i]);
}
}else{
weights = new Integer[servers.length];
for (int i = 0; i < weights.length; i++) {
weights[i] = 1;
}
}
// 获取socke连接池的实例对象
SockIOPool pool = SockIOPool.getInstance();
// 服务器列表和其权重
pool.setServers(servers);
pool.setWeights(weights);