Use Ttserver through the Memcache protocol to connect to the boot instance via Telnet 127.0.0.1 9032 telnet. Below we add a key to Key1 and value to value1 data via Add.
Get data through get key1.
(<key> <flags> <exptime> <bytes>)
Add key1 1 0 6value1storedget key1value key1 0 6value1end |
Writing PHP Scripts
$mem =NewMemcache (); $memConnect("127.0.0.1",9032); $memAdd("Key2","Xifeijian"); Print_r ($memGet("Key2")); Echo "<br/>"; $memAdd("Key3",Array("Value3"="This is Xifeijian")); Echo $memGet("Key3"); ?> |
Post-Execution output: (the PHP script executes directly on the server, assuming that it is more intuitive to visit in the browser.)
)
Issues needing attention in serialization
Suppose you are familiar with the Memcache protocol. Or you've used PHP's memcache to use Ttserver. You may have found the problem at once.
For example, we Key3 is an array, but we get back a serialized string, without its own active deserialization, on the memcached server will be actively deserialized.
Using the above Telnet Demo sample We can see that we set the flag parameter to 1 when we add key1, but when we get back, the flag number returned is 0, in fact, Ttserver does not store the flag parameter. Unified use 0, which causes PHP to be used without its own active deserialization, of course. Let's say you use a compression parameter, which is the same problem.
How to solve the problem, suppose to change the code of Ttserver is inconvenient. We are fully capable of PHP. or our client to control. For example, the value of our unity is serialized after the storage, when taken out of the time we re-serialized. Self-increment problem
//Use Ttserver self-increment $mem =NewMemcache (); $memConnect("127.0.0.1",9032); Var_dump ($memIncrement("INCR")); The result is int (1) ?> |
//Use memcache self-increment $mem =NewMemcache (); $memConnect("127.0.0.1",9023); Var_dump ($memIncrement("INCR")); The result is bool (false) ?> |
We see that the same code was used in Memcache to return a failure (false). We can see this in the PHP manual.memcache::increment ()does notCreate an item if it didn ' t exist. " But the same, the use of Ttserver is successful. Pay special attention to this point.
Tokyo Tyrant (Ttserver) series (iii)-memcache agreement