• Redis平台-整合PHP


    1.Redis的相关介绍:

    定义:

    redis是一个key-value存储系统。和Memcached类似,它支持存储的value类型相对更多,包括string(字符串)、list(链表)、set(集合)、zset(sorted set --有序集合)和hash(哈希类型)。这些数据类型都支持push/pop、add/remove及取交集并集和差集及更丰富的操作,而且这些操作都是原子性的。在此基础上,redis支持各种不同方式的排序。与memcached一样,为了保证效率,数据都是缓存在内存中。区别的是redis会周期性的把更新的数据写入磁盘或者把修改操作写入追加的记录文件,并且在此基础上实现了master-slave(主从)同步。
    Redis 是一个高性能的key-value数据库。 redis的出现,很大程度补偿了memcached这类key/value存储的不足,在部 分场合可以对关系数据库起到很好的补充作用。它提供了Java,C/C++,C#,PHP,JavaScript,Perl,Object-C,Python,Ruby,Erlang等客户端,使用很方便。 [1] 
    Redis支持主从同步。数据可以从主服务器向任意数量的从服务器上同步,从服务器可以是关联其他从服务器的主服务器。这使得Redis可执行单层树复制。存盘可以有意无意的对数据进行写操作。由于完全实现了发布/订阅机制,使得从数据库在任何地方同步树时,可订阅一个频道并接收主服务器完整的消息发布记录。同步对读取操作的可扩展性和数据冗余很有帮助。
     
    性能:
    官方的bench-mark数据: [1] 
    测试完成了50个并发执行100000个请求。
    设置和获取的值是一个256字节字符串。
    Linux box是运行Linux 2.6,这是X3320 Xeon 2.5 ghz。
    文本执行使用loopback接口(127.0.0.1)。
    结果:读的速度是110000次/s,写的速度是81000次/s 。
     
    2.源码安装Redis服务:
    yum install gcc-c++ -y
    #下载redis源码包
    wget http://download.redis.io/releases/redis-5.0.7.tar.gz
    tar xf redis-5.0.7.tar.gz
    cd redis-5.0.7
    #redis服务无需进行预编译,但需改一下文件的安装路径
    Vim src/Makefile    添加:PREFIX?=/usr/local/redis
    make && make install
    #或者直接安装:
    make PREFIX=/usr/local/redis install 
    #复制redis.conf配置文件到/usr/local/redis
    [root@localhost redis-5.0.7]#cp redis.conf /usr/local/redis
    
    #配置redis启动脚本
    [root@localhost redis-5.0.7]# ./utils/install_server.sh 
    Welcome to the redis service installer
    This script will help you easily set up a running redis server
    
    Please select the redis port for this instance: [6379] 
    Selecting default: 6379
    Please select the redis config file name [/etc/redis/6379.conf] /usr/local/redis/6379.conf
    Please select the redis log file name [/var/log/redis_6379.log] /usr/local/redis/6379.log 
    Please select the data directory for this instance [/var/lib/redis/6379] /usr/local/redis/6379
    Please select the redis executable path [] /usr/local/redis/bin/redis-server
    Selected config:
    Port           : 6379
    Config file    : /usr/local/redis/6379.conf
    Log file       : /usr/local/redis/6379.log
    Data dir       : /usr/local/redis/6379
    Executable     : /usr/local/redis/bin/redis-server
    Cli Executable : /usr/local/redis/bin/redis-cli
    Is this ok? Then press ENTER to go on or Ctrl-C to abort.
    Copied /tmp/6379.conf => /etc/init.d/redis_6379
    Installing service...
    Successfully added to chkconfig!
    Successfully added to runlevels 345!
    Starting Redis server...
    Installation successful!
    [root@localhost redis-5.0.7]# 
    
    #设置环境变量
    echo "export PATH="/usr/local/redis/bin:PATH"" >>/etc/profile.d/redis.sh
    source /etc/profile.d/redis.sh

    3.php整合redis连接驱动

    下载4.2.0.tar.gz源码包并且解压 /安装
    # 源码方式安装php,整合redis: 
    wget https://github.com/phpredis/phpredis/archive/4.2.0.tar.gz 
    tar xf 4.2.0.tar.gz 
    cd phpredis-4.2.0/ 
    /usr/local/php/bin/phpize
    
    ./configure  --with-php-config=/usr/local/php/bin/php-config  --enable-redis 
    make && make install
    
    #编辑php.ini配置文件,添加redis模块: 
    extension=redis.so     (在854行上下添加)
    
    # yum方式安装php,整合redis: 
    安装php7.0 
    yum install https://rpms.remirepo.net/enterprise/remi-release-7.rpm -y 
    yum install yum-utils -y 
    yum-config-manager --enable remi-php70 
    yum install php php-fpm php-mysql php-redis -y
    
    #PS: 以上两种方式,采取其中一种即可

     

     

     

     测试redis模块是否添加成功:

    #创建info.php文件测试
    vim  /usr/local/nginx/html/wordpress/info.php
    <?php        
    phpinfo(); 
    ?>

    webj界面访问:

    #查看php是否成功连接Redis
    /usr/local/php/bin/php -m  

  • 相关阅读:
    Git哲学与使用
    save
    http://www.onvif.org/onvif/ver20/util/operationIndex.html
    图标
    C#高性能大容量SOCKET并发(一):IOCP完成端口例子介绍(转)
    一种基于PTP 协议的局域网高精度时钟同步方法(转)
    WPF中的数据模板(DataTemplate)(转)
    WPF中的ControlTemplate(控件模板)(转)
    也来说说C#异步委托(转)
    C#委托的介绍(delegate、Action、Func、predicate)(转)
  • 原文地址:https://www.cnblogs.com/fengyuanfei/p/13830654.html
Copyright © 2020-2023  润新知