note 68581 deleted from function.memcache-set by bobby

From: Date: Fri, 08 Dec 2006 15:50:46 +0000
Subject: note 68581 deleted from function.memcache-set by bobby
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-120437@lists.php.net to get a copy of this message
Note Submitter: mars at joyinter dot com ---- Something's really weird between Memcached API between PHP and java(com.danga.MemCached) first, when PHPAPI set a pair of key and value,java can't read it: PHP code: <?php /* OO API */ $memcache_obj = new Memcache; /* connect to memcached server */ $memcache_obj->connect('192.168.0.200', 11211); /* set value of item with key 'var_key', using on-the-fly compression expire time is 50 seconds */ $memcache_obj->set('var_key', 'some really big variable'); ?> Java code: try { SockIOPool pool = SockIOPool.getInstance(); pool.setServers(new String[]{"192.168.0.200:11211"}); pool.initialize(); client = new MemCachedClient(); System.out.println("value="+client.get("var_key")); } catch (Exception e) { e.printStackTrace(); } The result turns out to be : value=null but when use javacode: System.out.println(client.replace("var_key", "xxx")); System.out.println("value="+client.get("var_key")); The result: true xxx It indicates java actually read the key!? On the other hand, when Java set a pair of key and value, php read it, the value will have an extra char at the front of actual value: Java Code: try { SockIOPool pool = SockIOPool.getInstance(); pool.setServers(new String[]{"192.168.0.200:11211"}); pool.initialize(); client = new MemCachedClient(); client.set("somekey", "somevalue"); } catch (Exception e) { e.printStackTrace(); } PHP Code: <?php /* OO API */ $memcache_obj = new Memcache; $memcache_obj->connect('192.168.0.200', 11211); $value = $memcache_obj->get('somekey'); echo "value=$value\r\nFirst char's ASCII value is ".ord($value[0]); ?> value=somevalue First char's ASCII value is 6 Is anybody able to explain that?

« previous php.notes (#120437) next »