memcache 和memcached的关系
memcache是客户端,memcached是服务器端,memcached一般以守护进程运行。
memcached安装
- 下载libevent源码,编译安装libevent
tar zxvf libevent.tar.gz
cd libevent-1.2
./configure --prefix=/usr
make
make install
- 下载memcached源码,编译安装memcached
cd /tmp
tar zxvf memcached.tar.gz
cd memcached
./configure --with-libevent=/usr
make
make install
memcahce类方法
Memcache {
bool add ( string $key , mixed $var [, int $flag [, int $expire ]] )
bool addServer ( string $host [, int $port = 11211 [, bool $persistent [, in
t $weight [, int $timeout [, int $retry_interval [, bool $status [, callback
$failure_callback [, int $timeoutms ]]]]]]]] )
bool close ( void )
bool connect ( string $host [, int $port [, int $timeout ]] )
int decrement ( string $key [, int $value = 1 ] )
bool delete ( string $key [, int $timeout = 0 ] )
bool flush ( void )
string get ( string $key [, int &$flags ] )
array getExtendedStats ([ string $type [, int $slabid [, int $limit = 100 ]]]
)
int getServerStatus ( string $host [, int $port = 11211 ] )
array getStats ([ string $type [, int $slabid [, int $limit = 100 ]]] )
string getVersion ( void )
int increment ( string $key [, int $value = 1 ] )
mixed pconnect ( string $host [, int $port [, int $timeout ]] )
bool replace ( string $key , mixed $var [, int $flag [, int $expire ]] )
bool set ( string $key , mixed $var [, int $flag [, int $expire ]] )
bool setCompressThreshold ( int $threshold [, float $min_savings ] )
bool setServerParams ( string $host [, int $port = 11211 [, int $timeout [,
int $retry_interval = false [, bool $status [, callback $failure_callback ]]]]
] )
}
memcache配置
memcache.allow_failover boolean
是否在发生错误时(对用户)透明的转移到其他服务器
memcache.max_failover_attempts integer
定义在写入和获取数据时最多尝试的服务器次数(即:故障转移最大尝试数),仅和memcache.allow_failover 结合使用。
memcache.chunk_size integer
数据传输块大小,这个值越小网络 I/O 次数越多,如果发现莫名的速度降低, 可以尝试将此值调至
32768。
memcache.default_port string
在尝试连接 memcache 的时候如果没有单独指定端口默认使用的 TCP 端口号。
memcache.hash_strategy string
控制 key 到服务器的映射(分布式)策略。
memcache.hash_function string
控制在 key-server 映射时使用哪个 hash 函数 crc32 标明使用标准 CRC32 进行 hash,fnv 则说明
使用 FNV-1a。
session.save_handler string
当值为 memcache 时标记使用 memcache 作为 session 处理器。
session.save_path string
定义一个逗号分割的用于 session 存储的服务器 url 列表,例如: "tcp://host1:11211,
tcp://host2:11211".
每个 url 可以包含参数,这些参数于方法 Memcache::addServer()的参数相同。比如:
"tcp://host1:11211?persistent=1&weight=1&timeout=1&retry_interval=15"
网友评论