Memcache, as a data middle layer, is often used for data exchange.
For example, within a system we specify the following user status information, each user only need to survive 52 bytes.
Key state#id such as "state#10888"
Value: (binary data)
User ID Uint32
Type user Types Uint8:
State user Status Uint8:
Server IP Uint32
Last Online time Uint64
Length of Session ID Uint16
Session ID Char[32]
A total of 52 bytes
So how to get the above data in PHP by Memcache?
If the stored data has binary 0, will the string be truncated?
No, actually!
Test the following
$mem = new Memcache ();
$mem->connect (' 192.168.0.69 ', 11211);
$memstr = $mem->get (' state#105709 ');
Var_dump ($MEMSTR);
will get the following output. You can see that the memstr is exactly 53 bytes. SessionID has a terminator.
String (53) "頊 including f> r!8jwfmsik41kbdkmlqc7m7qowicq8nzz7"
Further, we export the data to a file and use Winhex to view the status of the data
File_put_contents ('./dd.txt ', $memstr);
With Winhex dd.txt you will see hex data.
ed9c01000001c0a800463ef60a520000000100386a57466d73494b34316b42446b6d6c7143376d37516f57494351386e7a7a3700
So I can take the data by byte, mainly using the Ord function to get the byte ASCII code.
$type = Ord ($memstr {4});
$state = Ord ($memstr {5});
$ip = Ord ($memstr {6}). Ord ($memstr {7}). '. '. Ord ($memstr {8}). '. '. Ord ($memstr {9});
$ses _long = Ord ($memstr {) *16+ord ($memstr {18});
Timestamp requires only 4 bytes, 8 bytes Allocated
$lastactive = Ord ($memstr {*16777216+ord}) *65536+ord ($memstr {one}) *256+ord ($memstr {10});
$sessionid = substr ($memstr, $ses _long);
http://www.bkjia.com/PHPjc/477168.html www.bkjia.com true http://www.bkjia.com/PHPjc/477168.html techarticle Memcache, as a data middle layer, is often used for data exchange. For example, within a system we specify the following user status information, each user only need to survive 52 bytes. ...