背景
那现在就有2个问题
1. 2个扩展,在存储读取数组时有异常情况
2. 2个扩展,在存储读取int整形时有异常情况
验证
<?php echo "========== test string ============\n"; $mc = new memcache; $mc->addServer('10.199.189.129', 11511); $key = 'testString'; $mc->set($key, 'test success'); var_dump($mc->get($key)); $mc2 = new memcached; $mc2->addServer('10.199.189.129', 11511); var_dump($mc2->get($key)); echo "========== test array ============\n"; $key2 = 'testArray'; $mc->set($key2, [1,2,3]); var_dump($mc->get($key2)); var_dump($mc2->get($key2));
➜ ~ php /apps/dat/test.php ========== test string ============ string(12) "test success" string(12) "test success" ========== test array ============ array(3) { [0]=> int(1) [1]=> int(2) [2]=> int(3) } int(0)
猜测原因
<?php echo "========== test array ============\n"; $mc = new memcache; $mc->addServer('10.199.189.129', 11511); $mc2 = new memcached; $mc2->addServer('10.199.189.129', 11511); $key2 = 'testArray1'; $key3 = 'testArray2'; $mc->set($key2, [1,2,3]); $mc2->set($key3, [1,2,3]); var_dump($mc->get($key2)); var_dump($mc2->get($key3));
➜ ~ php /apps/dat/test.php ========== test array ============ array(3) { [0]=> int(1) [1]=> int(2) [2]=> int(3) } array(3) { [0]=> int(1) [1]=> int(2) [2]=> int(3) }
➜ ~ telnet 10.199.189.129 11511 Trying 10.199.189.129... Connected to 10.199.189.129 Escape character is '^]'. get testArray1 VALUE testArray1 1 30 a:3:{i:0;i:1;i:1;i:2;i:2;i:3;} END get testArray2 VALUE testArray2 4 30 a:3:{i:0;i:1;i:1;i:2;i:2;i:3;} END
阅读两个扩展的源码
memcache
#define MMC_SERIALIZED 1 #define MMC_COMPRESSED 2
memcached
#define MEMC_VAL_IS_STRING 0 #define MEMC_VAL_IS_LONG 1 #define MEMC_VAL_IS_DOUBLE 2 #define MEMC_VAL_IS_BOOL 3 #define MEMC_VAL_IS_SERIALIZED 4 #define MEMC_VAL_IS_IGBINARY 5 #define MEMC_VAL_IS_JSON 6 #define MEMC_VAL_IS_MSGPACK 7
<?php $mc = new memcache; $mc->addServer('10.199.189.129', 11511); $mc->set('123',1); var_dump($mc->get('123'));
string(1) "1"
<?php $mc = new memcached; $mc->addServer('10.199.189.129', 11511); $mc->set('123',1); var_dump($mc->get('123'));
int(1)
结论
《本文》有 0 条评论