1、memcached命令行
telnet 127.0.0.1 11211
set key2 0 30 2abSTOREDget key2VALUE key2 0 2abEND
如:
set key3 1 100 4
abcdSTOREDget key3VALUE key3 1 4abcdENDreplace key3 1 200 5abcdxSTOREDget key3VALUE key3 1 5abcdxENDdelete key3DELETEDget key3END2、memcached数据导出和导入
查看状态:
然后导出:
导入:
memcached-tool 127.0.0.1:11211 dump
注意,在导入的时候,会有过期时间,所以,在导入的时候,要调时间值,否则导入后,就没有数据
3、php连接memcache
先安装php的memcache扩展
cd /usr/local/src/ wget -c http://pecl.php.net/get/memcache-2.2.7.tgz (php5最新稳定版)wget -c http://pecl.php.net/get/memcache-3.0.8.tgz (php5最新开发版)wget -c https://github.com/websupport-sk/pecl-memcache/archive/php7.zip (php7可用版)解压:tar zxf memcache****.tgzcd memcache***/usr/local/php7fpm/bin/phpize./configure --with-php-config=/usr/local/php7fpm/bin/php-configmake && make install安装完后会有类似这样的提示:Installing shared extensions: /usr/local/php7fpm/lib/php/extensions/no-debug-non-zts-20170718/然后修改php.ini添加一行echo "extension=memcache.so" >>/usr/local/php7fpm/etc/php.ini检查/usr/local/php7fpm/bin/php-fpm -mphp安装memcached:
wget -c https://pecl.php.net/get/memcached-3.0.4.tgz
tar -xvf memcached-3.0.4.tgzcd memcached-3.0.4//usr/local/php7fpm/bin/phpize./configure若缺libmemcached 需要安装这两个依赖包:yum install libmemcached libmemcached-devel./configuremake && make installecho "extension=memcached.so" >>/usr/local/php7fpm/etc/php.ini/etc/init.d/php7fpm restart具体相关:
测试:url www.apelearn.com/study_v2/.memcache.txt > 1.php 2>/dev/null
/usr/local/php7fpm/bin/php 1.php
4、php的session存储到memcached
编辑php.ini添加两行
for memcache:session.save_handler = memcachesession.save_path="tcp://192.168.0.9:11211"for memcahed:session.save_handler = memcachedsession.save_path = "localhost:11211" 或 session.save_path = "127.0.0.1:11211"或者httpd.conf中对应的虚拟主机中添加
for memcache:php_value session.save_handler "memcache"php_value session.save_path"tcp://192.168.0.9:11211"
或者php-fpm.conf对应的pool中添加
for memcache:
php_value[session.save_handler]=memcache
php_value[session.save_path]="tcp://192.168.0.9:11211"for memcahed:
php_value[session.save_handler] = memcached
php_value[session.save_path] = "127.0.0.1:11211" 或 php_value[session.save_path] = "localhost:11211"测试:
wget http://study.lishiming.net/.mem_se.txtmv .mem_se.txt /usr/local/apache2/htdocs/session.phptelnet 127.0.0.1 11211for memcahed: