Skip to content

Instantly share code, notes, and snippets.

@polonskiy
Last active January 28, 2019 11:16
Show Gist options
  • Save polonskiy/4b99adcf69a16aea5f33 to your computer and use it in GitHub Desktop.
Save polonskiy/4b99adcf69a16aea5f33 to your computer and use it in GitHub Desktop.
dump memcached data

Install

Using curl

$ curl -s https://gist.githubusercontent.com/polonskiy/4b99adcf69a16aea5f33/raw/memcachedump.php > /usr/local/bin/memcachedump && chmod +x /usr/local/bin/memcachedump

Using wget

$ wget -O /usr/local/bin/memcachedump https://gist.githubusercontent.com/polonskiy/4b99adcf69a16aea5f33/raw/memcachedump.php && chmod +x /usr/local/bin/memcachedump
#!/usr/bin/php
<?php
$argv += [1 => 'localhost', 2 => 11211];
$memcached = new Memcached;
$memcached->addServer($argv[1], $argv[2]);
$result = [];
foreach($memcached->getAllKeys() as $k) $result[$k] = $memcached->get($k);
var_export($result);
echo ";\n";
#!/usr/bin/php
<?php
$argv += [1 => 'localhost', 2 => 11211];
$memcached = new Memcached;
$memcached->addServer($argv[1], $argv[2]);
$keys = $memcached->getAllKeys();
$hr = str_repeat('=', exec('tput cols'));
echo "$hr\n";
foreach ($keys as $key) {
$data = $memcached->get($key);
if (is_array($data)) $data = print_r($data, true);
echo "$key\n$data\n$hr\n";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment