Skip to content

Instantly share code, notes, and snippets.

@wolframite
Created July 26, 2016 10:04
Show Gist options
  • Save wolframite/90b841fb109cf934e459ec74f0086b92 to your computer and use it in GitHub Desktop.
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
<?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;
@wolframite
Copy link
Author

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.

@wolframite
Copy link
Author

<?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