Tokyo Tyrant (Ttserver) series (iii)-memcache agreement

Source: Internet
Author: User
Tags php script

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.