Created
July 26, 2016 10:04
-
-
Save wolframite/90b841fb109cf934e459ec74f0086b92 to your computer and use it in GitHub Desktop.
Store an array in memcached and read it back. Using memcached as backend, it's unserialized correctly to an array, Apache Ignite returns a string
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$mc = new Memcached(); | |
$mc->setOption(Memcached::OPT_SERIALIZER, Memcached::SERIALIZER_JSON_ARRAY); | |
$mc->setOption(Memcached::OPT_COMPRESSION, false); | |
$mc->setOption(Memcached::OPT_BINARY_PROTOCOL, true); | |
$mc->addServer('localhost', 11211); | |
$data = ['hello' => 'test']; | |
echo gettype($data) . PHP_EOL; | |
$mc->set('mykey', $data); | |
$data = $mc->get('mykey'); | |
echo gettype($data) . PHP_EOL; |
<?php
$mc = new Memcached();
$mc->setOption(Memcached::OPT_SERIALIZER, Memcached::SERIALIZER_JSON_ARRAY);
$mc->setOption(Memcached::OPT_COMPRESSION, false);
$mc->setOption(Memcached::OPT_BINARY_PROTOCOL, true);
$mc->addServer('10.1.17.102', 11211);
$array = ['hello' => 'test'];
$object = new stdClass();
$object->prop = "value";
$data = [
'integer' => (int) 5,
'double' => (float) 3.5,
'string' => "Hallo",
'array' => $array,
'object' => $object
];
foreach ($data as $type => $item) {
$mc->set($type, $item);
printf('%s :: %s%s', $type, gettype($mc->get($type)), PHP_EOL);
}
Result with memcached:
int :: integer
float :: double
string :: string
array :: array
object :: array
Result with ignite:
integer :: boolean
double :: string
string :: string
array :: string
object :: string
The data is stored correctly, but the flags are ignored completely... It's also strange that it's impossible to store a plain integer...
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
php-memcached stores the data type in the flags, an uncompressed JSON serialized array amliken thexple should have a 6 as flag. As I'm getting back a string, I assume Apache Ignite stores a 0.