【发布时间】:2011-01-13 16:05:14
【问题描述】:
当我尝试从我在 python 中设置的 memcached 中读取字符串时:
import memcache
MC_SERVER = "192.168.1.100"
MC_PORT = "11211"
mc = memcache.Client(['%s:%s' % (MC_SERVER, MC_PORT)], debug=0)
mc.set("test_string", "true")
print mc.get("test_string")
Java 告诉我 is 不存在,当我尝试获取它时显然返回 null:
import com.danga.MemCached.*;
public class Tester {
// create a static client as most installs only need
// a single instance
protected static MemCachedClient mcc = new MemCachedClient(true, false);
// set up connection pool once at class load
static {
// server list and weights
String[] servers =
{
"192.168.1.100:11211"
};
// grab an instance of our connection pool
SockIOPool pool = SockIOPool.getInstance();
// set the servers and the weights
pool.setServers( servers );
// set some TCP settings
// disable nagle
// set the read timeout to 3 secs
// and don't set a connect timeout
pool.setNagle( false );
pool.setSocketTO( 3000 );
pool.setSocketConnectTO( 0 );
// initialize the connection pool
pool.initialize();
}
// from here on down, you can call any of the client calls
public static void main(String[] args) {
//System.out.println( mcc.set( "test_string", "blah!" ) ); // everything is great is value is set by Java
System.out.println( mcc.keyExists( "test_string" ) ); // output is false when value set by python
System.out.println( mcc.get( "test_string" ) ); // output is null when value set by python
}
}
我猜它与跨语言的对象序列化/反序列化有关,但我认为对于简单的字符串我可能没问题 - 以前有人遇到过吗?
这是我正在使用的库:
【问题讨论】:
-
您应该在 memcached 服务器上进行详细日志记录,并确保您认为正在发生的事情实际上正在发生。
-
好建议,但我实际上无权访问这个特定的 memcached 服务器。我尝试了这个其他 java 库,它似乎按预期工作:code.google.com/p/spymemcached 我仍然想知道为什么其他库不工作 - 只是好奇。
-
它可能无法理解返回的值。你可以配置 spymemcached 来模拟 Whalin 的转码器,看看它是否也失败了。
-
@jckdnk111 你是怎么解决的?
-
@Gank,我检查了这个场景,它对我有用。您正在使用哪些库/版本?