Skip to content

Instantly share code, notes, and snippets.

@cgmartin
Last active August 29, 2015 13:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cgmartin/9052704 to your computer and use it in GitHub Desktop.
Save cgmartin/9052704 to your computer and use it in GitHub Desktop.
Memcache serialization test (ext/memcache v2.2.7)
*** unsetKey ***
bool(false)
*** emptyKey ***
string(0) ""
*** falseKey ***
string(0) ""
*** trueKey ***
string(1) "1"
*** nullKey ***
NULL
*** numKey ***
string(5) "12345"
*** strNumKey ***
string(5) "12345"
*** floatKey ***
string(7) "12.8239"
*** arrayKey ***
array(2) {
[0] =>
string(3) "foo"
[1] =>
string(3) "bar"
}
*** assocArrayKey ***
array(1) {
'foo' =>
string(3) "bar"
}
*** objKey ***
class stdClass#3 (1) {
public $foo =>
string(3) "bar"
}
Memcache serialization test (ext/memcache v3.0.8)
*** unsetKey ***
bool(false)
*** emptyKey ***
string(0) ""
*** falseKey ***
bool(false)
*** trueKey ***
bool(true)
*** nullKey ***
NULL
*** numKey ***
int(12345)
*** strNumKey ***
string(5) "12345"
*** floatKey ***
double(12.8239)
*** arrayKey ***
array(2) {
[0] =>
string(3) "foo"
[1] =>
string(3) "bar"
}
*** assocArrayKey ***
array(1) {
'foo' =>
string(3) "bar"
}
*** objKey ***
class stdClass#3 (1) {
public $foo =>
string(3) "bar"
}
#!/usr/bin/env php
<?php
echo "Memcache serialization test (ext/memcache v".phpversion('memcache').")\n";
$mc = new Memcache();
$mc->connect('localhost', 11211) or die ("Could not connect");
$typeTests = array(
'unsetKey' => null, // won't be set
'emptyKey' => '',
'falseKey' => false,
'trueKey' => true,
'nullKey' => null,
'numKey' => 12345,
'strNumKey' => '12345',
'floatKey' => 12.8239,
'arrayKey' => array('foo', 'bar'),
'assocArrayKey' => array('foo'=>'bar'),
'objKey' => (object) array('foo'=>'bar'),
);
foreach ($typeTests as $key => $val) {
if ($key !== 'unsetKey') {
$mc->set($key, $val);
}
$readVal = $mc->get($key);
echo "\n*** $key *** \n";
var_dump($readVal);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment