Home > Backend Development > PHP Tutorial > php redis 装配及使用

php redis 装配及使用

WBOY
Release: 2016-06-13 10:58:04
Original
1008 people have browsed it

php redis 安装及使用
redis是一个 key-value 存储系统
phpredis是php的一个扩展,效率相当高,有链表排序功能

redis 安装:

    1.下载源码

        官网:http://redis.io/download

        直接地址: http://redis.googlecode.com/files/redis-2.4.17.tar.gz

    2.编译安装

        tar -zxvf redis-2.4.14.tar.gz
        cd redis-2.4.14
        make

    3.启动服务

        redis-server redis.conf (可修改配置:redis.conf)

    4.测试

        redis-cli
        redis 127.0.0.1:6379> (表示客户端成功开启)


需环境:
gcc ( yum install gcc-c++ )
Tcl-8.5.12 (参见:http://www.linuxfromscratch.org/blfs/view/cvs/general/tcl.html)

php redis 模块安装:

    1.下载源码

          发布网站:https://github.com/owlient/phpredis 

        wget https://nodeload.github.com/owlient/phpredis/tarball/master > owlient-phpredis-2.1.1-1-g90ecd17.tar.gz

    2.编译安装

        tar -zxvf owlient-phpredis-2.1.1-1-g90ecd17.tar.gz
        cp owlient-phpredis-90ecd17 /usr/include/php/ext/ (将文件拷贝至php源码目录的ext目录中)
        /usr/bin/phpize (运行phpize,如果不知道在哪里,可以用whereis phpize命令)
        cd /usr/include/php/ext/owlient-phpredis-90ecd17/
        ./configure –with-php-config=/usr/bin/php-config (注意自己的php-config路径)
        make && make install

    3.修改php配置,加载redis.so模块

        vi /etc/php.d/redis.ini 添加一行: extension=redis.so

    4.测试

        phpinfo(8)(查看模块加载信息)

    <?php    //phpinfo(8);    $redis = new Redis();    $redis->connect('127.0.0.1');    $redis->select(1);    $ret = $redis->set('testzzj', 'test');    var_dump($ret);    $allKeys = $redis->keys('*');    print_r($allKeys);
Copy after login

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template