zoukankan      html  css  js  c++  java
  • memcached命令行、Memcached数据导出和导入、php连接memcache、php的session存储到memcached

    1、memcached命令行

    telnet 127.0.0.1 11211
    set key2 0 30 2
    ab
    STORED
    get key2
    VALUE key2 0 2
    ab
    END

     如:

    set key3 1 100 4
    abcd
    STORED
    get key3
    VALUE key3 1 4
    abcd
    END
    replace key3 1 200 5
    abcdx
    STORED
    get key3
    VALUE key3 1 5
    abcdx
    END
    delete key3
    DELETED
    get key3
    END

    2、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****.tgz
    cd memcache***
    /usr/local/php7fpm/bin/phpize
    ./configure --with-php-config=/usr/local/php7fpm/bin/php-config
    make && 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 -m

    php安装memcached:

    wget -c https://pecl.php.net/get/memcached-3.0.4.tgz
    tar -xvf memcached-3.0.4.tgz
    cd memcached-3.0.4/
    /usr/local/php7fpm/bin/phpize
    ./configure
    若缺libmemcached 需要安装这两个依赖包:yum install libmemcached libmemcached-devel
    ./configure
    make && make install
    echo "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 = memcache
    session.save_path="tcp://192.168.0.9:11211"
    for memcahed:
    session.save_handler = memcached
    session.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.txt
    mv .mem_se.txt /usr/local/apache2/htdocs/session.php

    telnet 127.0.0.1 11211

    for memcahed:

     

  • 相关阅读:
    教为学:Oracle SQL学习之路(三):分析函数之统计
    教为学:Oracle SQL学习之路(二):分析函数之相邻
    教为学:Python学习之路(五):map reduce学习
    教为学:JBPM4.4学习之路(三):流程部署的查询、删除、流程图查看
    教为学:Oracle SQL学习之路(四):分析函数之统计(二)
    教为学:Oracle SQL学习之路(五):分析函数之小结
    教为学:JBPM4学习之路(二):流程部署
    (转载) C/C++中extern关键字详解
    OpenOffice:c++虚函数的实践
    OpenOffice:在sw模块中插入OLE对象,并调整其大小
  • 原文地址:https://www.cnblogs.com/nfyx/p/9491196.html
Copyright © 2011-2022 走看看