当前位置:  开发笔记 > 编程语言 > 正文

Memcached通过python为String设置为null,然后从Java获取

如何解决《Memcached通过python为String设置为null,然后从Java获取》经验,为你挑选了0个好方法。

当我尝试从我在python中设置的memcached中读取一个String时:

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告诉我它不存在,当我尝试获取它时显然会返回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
        }
}

我猜这与跨语言的对象序列化/非序列化有关,但我认为对于简单的字符串我可能没问题 - 以前有人遇到过这种情况吗?

这是我正在使用的库:

http://www.tummy.com/Community/software/python-memcached/

http://github.com/gwhalin/Memcached-Java-Client/downloads

推荐阅读
殉情放开那只小兔子
这个屌丝很懒,什么也没留下!
DevBox开发工具箱 | 专业的在线开发工具网站    京公网安备 11010802040832号  |  京ICP备19059560号-6
Copyright © 1998 - 2020 DevBox.CN. All Rights Reserved devBox.cn 开发工具箱 版权所有