Export or import memcached data. Example: Export to file: memcachedump-hlocalhost-p11211-fmem.dump import from file: memcachedump-hlocalhost-p11211-fmem.dump-i problem: Missing item expiration information. If the item expires n seconds after the import, the item will never expire after the import. How can this problem be solved? None?
Export or import memcached data. Example: Export to file: memcachedump-hlocalhost-p11211-fmem.dump import from file: memcachedump-hlocalhost-p11211-fmem.dump-i problem: Missing item expiration information. If the item expires n seconds after the import, the item will never expire after the import. How can this problem be solved? None?
Export or import memcached data.
Example:
Export to file: memcachedump-hlocalhost-p000011-f mem. dump
Import from file: memcachedump-hlocalhost-p000011-f mem. dump-I
Problem: The item expiration information is lost. If the item expires n seconds after the import, the item will never expire after the import.
How can this problem be solved? <无>
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 ('cccccc', $ a, $ B, $ c, $ d);} function unpackDWord ($ s) {$ a = (0 xFFFFFFFF & ord ($ s {0}) <24; $ B = (0 xFFFFFFFF & ord ($ s {1}) <16; $ C = (0 xFFFFFFFF & ord ($ s {2}) <8; $ d = ord ($ s {3 }); return $ a + $ B + $ c + $ d ;} /***** @ param \ Memcache $ mc * @ param type $ file * @ param type $ prefix */function memcachedump_dump ($ mc, $ file, $ prefix) {$ server_slabs = $ mc-> getExtendedStats ('slabs '); foreach ($ server_slabs as $ server =>$ slabs) {foreach ($ slabs as $ slab_id => $ 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 <= 0) {continue;} $ key = fread ($ file, $ kl); if (feof ($ file) {continue ;} $ val = fread ($ file, $ vl); if (empty ($ val) {continue;} $ mc-> set ($ key, $ val );}} /*** interpreted parameters can be interpreted as follows: *-p *-pVALUE *-p value * -- param value *-p = 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 <$ argc; ++ $ I) {$ arg = $ argv [$ I]; if (strpos ($ arg, '=')> 0) {//-p = 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 ;}