To build a distributed cache system.
(1) More than one memcache server
(2) Distributed algorithm. From which data is stored, the data is obtained from which station.
The algorithm is built-in, without our own intervention, built into the memcache extension inside.
When we use multiple memcache operations, we operate on the same machine.
Steps to Build:
Prepare at least two memcache servers.
localhost:11211
localhost:11210
The storage methods are as follows:
<? PHP $mem New Memcache (); // Link a distributed memcache server//Add a memcache server to the connection pool $mem -addserver (' localhost ', 11211); $mem -addserver (' localhost ', 11210); $mem , set (' Name ', ' Lisi ', 0,3600); $mem , set (' Age ', 23,0,3600); $mem -Set (' Email ', ' [email protected] ', 0,3600
The Read method is as follows:
<? PHP $mem New Memcache (); // Link a distributed memcache server//Add a memcache server to the connection pool $mem -addserver (' localhost ', 11211); $mem -addserver (' localhost ', 11210); Var_dump ($mem,get (' name ')); Var_dump ($mem,get (' age ')); Var_dump ($mem->get (' email '));
When adding data is, the number and order of Memcache servers that connect multiple memcache servers to and from the page to fetch the data should always be, reason: is to use the go-to-touch algorithm
Modulus algorithm: When data is stored and taken out, a value is calculated from key, divided by the number of servers, which determines which server to add data to and fetch data from.
Kill lui lei Dog---memcache no:05 configuration of a distributed memory object cache system