Memcached, становящиеся пустыми для Строкового набора с Python и затем, добираются от Java

Когда я пытаюсь считать Строку из memcached, который я установил в Python:

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 говорит мне, не существует и очевидно возвращает пустой указатель, когда я пытаюсь получить его:

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

8
задан jckdnk111 5 February 2010 в 19:37
поделиться

1 ответ

Разве в Java не используется юникод? Если это так, я подозреваю, что python пишет в memcache, используя набор символов ASCII / latin 1. В результате ключи выглядят совсем иначе («test_string» и «t \ 00e \ 00s \ 00t \ 00_ \ 00s \ 00t \ 00r \ 00i \ 00n \ 00g \ 00»).

Попробуйте использовать это и посмотрите, что произойдет.

import memcache

MC_SERVER = "192.168.1.100"
MC_PORT = "11211"

mc = memcache.Client(['%s:%s' % (MC_SERVER, MC_PORT)], debug=0)
mc.set(u"test_string", u"true")
print mc.get(u"test_string")
1
ответ дан 5 December 2019 в 18:59
поделиться
Другие вопросы по тегам:

Похожие вопросы: