导出或导入memcached的数据。 示例: 导出到文件:memcachedump-hlocalhost-p11211-fmem.dump 从文件导入:memcachedump-hlocalhost-p11211-fmem.dump-i 问题:丢失了item的过期信息。如果item在导入之后n秒过期,则导入后变成了永久不过期。 如何解决? 无 ?
导出或导入 memcached 的数据。
示例:
导出到文件:memcachedump -hlocalhost -p11211 -f mem.dump
从文件导入:memcachedump -hlocalhost -p11211 -f mem.dump -i
问题:丢失了item的过期信息。如果item在导入之后n秒过期,则导入后变成了永久不过期。
如何解决? connect($host, $port, $timeout)) { $pool[{$host}:{$port}] = $mc; } else { return null; } } return $pool[{$host}:{$port}];}function pack2dword($n) { $a = (0xff000000 & $n) >> 24; $b = (0x00ff0000 & $n) >> 16; $c = (0x0000ff00 & $n) >> 8; $d = 0x000000ff & $n; return pack('cccc', $a, $b, $c, $d);}function unpackdword($s) { $a = (0xffffffff & ord($s{0})) << 24; $b = (0xffffffff & ord($s{1})) < $slab_meta) { if (!is_int($slab_id)) { continue; } $dump = $mc->getextendedstats('cachedump', (int)$slab_id, (int)$slab_meta['used_chunks']); foreach ($dump as $server => $entries) { if (!$entries) { continue; } foreach ($entries as $key => $meta) { if ($prefix && ($prefix !== substr($key, 0, strlen($prefix)))) { continue; } $val = $mc->get($key); if (empty($val)) { continue; } $kl = pack2dword(strlen($key)); $vl = pack2dword((int)$meta[0]); fwrite($file, {$kl}{$vl}{$key}{$val}); } } } }}/** * * @param \memcache $mc * @param type $file */function memcachedump_import($mc, $file) { while (!feof($file)) { $ks = fread($file, 4); if (feof($file) || !isset($ks{3})) { continue; } $vs = fread($file, 4); if (feof($file) || !isset($vs{3})) { continue; } $kl = unpackdword($ks); $vl = unpackdword($vs); if (($kl <= 0) || ($vl set($key, $val); }}/** * 解释参数,可以解释以下类型: * -p * -pvalue * -p value * --param value * -p=value * --param=value * param=value * @param array $argv * @return array */function args_parse($argv) { if (!is_array($argv) || empty($argv)) { return array(); } $argc = count($argv); $ret = array(); for ($i = 0; $i 0) { // -p=value --param=value param=value list($arg_name, $arg_value) = explode('=', ltrim($arg, '-'), 2); $ret[$arg_name] = $arg_value; continue; } if ($arg{0} !== '-') { continue; } if (($arg{1} !== '-') && isset($arg{2})) {// -pvalue $ret[$arg{1}] = substr($arg, 2); continue; } else if (isset($argv[$i + 1]) && ($argv[$i + 1]{0} !== '-') && (false === strpos($arg, '='))) { $ret[ltrim($arg, '-')] = $argv[$i + 1]; ++$i; } else { $ret[ltrim($arg, '-')] = true; } } return $ret;}