redis之前也用了一段时间,作用大概也类似于:

一:redis作用

   1:用户数据缓存,每次http访问与响应,都会产生数据,而这些数据,是否都会走向数据库存表?

       不妨来一段实例:电商网购平台,首页每日PV 五千万左右,前端产生日志量每日大于400M,是否能够给登录用户账号、个人中心,订单都存表?


      project:使用redis缓存,这是一种web服务器与数据库之前的缓冲区,用以存储用户数据(后端seesion not 前端cookie),能够减少数据库压力,便于快速返回用户查询数据。

   2:做web集群中seesion共享,如若N个tomcat做集群,比如说nginx反向代理到前端做login,当http被load balancer/ Director调度到3th tomcat,可以,但是这个tomcat宕机了,

      那其余正常的tomcat是否能返回正确的server ?seesion能都转移到2th tomcat,redis,那前期部署tomcat集群时候,得引用redis关于seesion共享




             <Valve className="com.radiadesign.catalina.session.RedisSessionHandlerValve" />

            <Manager className="com.radiadesign.catalina.session.RedisSessionManager"

                     host="172.18.11.162"     #这是redis服务器的ip地址

                     port="6379"              #这里是redis的端口

                     database="0"

                     maxInactiveInterval="1800" /> 

            </Context>

               

二:开始一段redis单实例部署,最重要的是基于php做web管理,其实亦可以使用桌面管理工具redis manager desktop,比如运维管理平台,需要集成所有管理界面。

    1、下载redis2.8 redis-2.8.6.tar.gz

      2、编译安装,不通过configure 

         make

         make install

         完成安装过程中提示

         it's good idea to run ‘make test’

            INSTALL install

            INSTALL install

            INSTALL install

            INSTALL install

         make test ---报错  You need tcl 8.5 or newer in order to run the Redis test

         安装 yum -y install tcl

      OK

      3、mkdir -p /opt/redis/bin

         mkdir -p /opt/redis/etc

         mkdir -p /opt/redis/data

         mkdir -p /opt/redis/log

      

         cp /opt/redis-2.8.6/redis.conf /opt/redis/etc

         cd /opt/redis-2.8.6/src

         cp  mkreleasdhdr.sh redis-benchmark redis-check-aof redis-check-dump redis-cli redis-server /opt/redis/bin

         

         修改/opt/redis.conf   ----必要修改daemonize,其余可不做修改,自行记住即可

            daemonize yes  制定redis后台运行



      4、启动redis 

          ./redis-server ../etc/redis.conf


      [root@app redis]# netstat -lntp|grep redis

      tcp        0      0 0.0.0.0:6379                0.0.0.0:*                   LISTEN      28569/./redis-serve 

      tcp        0      0 :::6379                     :::*                        LISTEN      28569/./redis-serve 


      [root@app bin]# redis-cli 

      127.0.0.1:6379> 

      redis客户端启动。

      之后可以使用redis管理工具 RedisDesktopManager 来实现redis缓存的key操作

        

redis命令


      ---------查找key值存在--------

      127.0.0.1:6379> exists Fm_LogList/192767813

      (integer) 1


      ---------查看所有的key--------

      127.0.0.1:6379> keys

      1) "Fm_LogList/192767813"

      2) "Fm_LogList/172756561"

      3) "Fm_LogList/194292175"

      4) "Fm_LogList/191353234"

      5) "Fm_LogList/173947365"

      6) "Fm_LogList/165289481"

      。

      。

      。

      



     --------------------- expire 设置过期时间 expire key time 

     127.0.0.1:6379> EXPIRE tutorialname 60

     1) (integer) 1  

      

     192.168.182.6:0>expire chen 600

     1 

     ------------------------------------------  

     ttl key 查看键的过期时间

     127.0.0.1:6379> ttl Fm_80/UserJinbiLogList/194361483

     (integer) -1

-1, 如果key没有到期超时



     ----------del name 删除key name-----

     127.0.0.1:6379> del Fm_80/UserJinbiLogList/162896690

     (integer) 1

     

     -------------新建一个key,删除一个key-----

     127.0.0.1:6379> set job "andrio"

     OK 

     127.0.0.1:6379> EXISTS job

     (integer) 1

     

     

     ----------ping PONG返回响应是否连接成功---

     127.0.0.1:6379> ping

     PONG

     ----------select 0~15 编号的数据库---------

     127.0.0.1:6379[1]> select 15

     OK

     --------------慎用,以至于不用!!!----------------------.

     

           flushdb 删除当前选择数据库中的所有key

     

           flushall 删除所有数据库中的数据库


     ------------      

     select 0 选择到0数据库 redis默认的数据库是0~15一共16个数据库

     move confirm 1 将当前数据库中的key移动到其他的数据库中,这里就是把confire这个key从当前数据库中移动到1中

     rename key2 key3 重命名key2 为key3

     type key2 返回key的数据类型 

     move confirm 1 将当前数据库中的key移动到其他的数据库中,这里就是把confire这个key从当前数据库中移动到1中

     expire confirm 100 设置confirm这个key100秒过期

     

     ------------------查看有多少个key-----------------------------

     127.0.0.1:6379> DBSIZE

     (integer) 1415502


webphp静态文件,需要部署php

      PHP搭建:

      1、可以分为yum安装与源码安装,但是源码安装存在各种依赖包问题

         #安装php依赖软件

       yum -y install autoconf automake bzip2-devel freetype-devel gcc-c++ libcurl-devel libgcrypt-devel \

       libicu-devel libjpeg-turbo-devel libpng-devel libxml2-devel libxslt-devel ncurses-devel openjpeg-devel \







返回php安装 configure之后进入编译安装  make  然后 make install,即可




                  编辑 /usr/local/apache2/conf/httpd.conf 文件     

                找到AddType  application/x-compress .Z

                   AddType application/x-gzip .gz .tgz

               在后面添加:

                   AddType application/x-httpd-php .php(使Apcche支持PHP)

                   AddType application/x-httpd-php-source .php5   

               找到:

                 <IfModule dir_module>

                 DirectoryIndex index.html

                  </IfModule>

               添加:

                 <IfModule dir_module>

                 DirectoryIndex index.html index.php

                 </IfModule>    

               找到:

               #ServerName www.example.com:80

               修改为:

               ServerName 127.0.0.1:80或者ServerName localhost:80

               记得要去掉前面的“#”






重点,6、php服务器搭建成功了,解决redis web管理问题    来源于    ------- 




  

          

redis window官网管理工具 redis管理页面_java





  


                 [I] [E] [I]

                 

                 Add another key

                 

                 

                 *

                  Filter!

                 

                 

                 type here to filter

                 

                 Keys (2)                                  ----------------所有的key

                 chen

                 wang



--------------------------------look  

       点击 Add another key  新建叫wang的key,value内容写一串。。。。  刷新,keys确实存在 wang




       1) "chen"

       2) "wang"



###############关于 

一:如果说多个redis用于一个项目,可以做redis集群,使用keepalived也可以使用,在php中phpredisadmin配置文件中192.168.182.6改为redis集群VIP即可

二:关于多个项目,完全不在同一业务的redis,怎么破?phpredisadmin给了完整答案

        

redis window官网管理工具 redis管理页面_java_02


很多源码例如nginx都会提供default.conf用以模板化解决提供,多实例。!!!可以添加,这儿不多说

  

redis window官网管理工具 redis管理页面_java_03

--楼主也未配置,可以研究下


---------------完成,乱糟糟的草稿纸,OK


转载于:https://blog.51cto.com/chennailong/1891670