• 安装Redis并测试


    1.在网站http://redis.io/ 下载Redis2.6.8

    2.解压并安装

     

    [root@server2 admin]# tar xvfredis-2.6.8.tar.gz

    [root@server2admin]# cdredis-2.6.8

    [root@server2redis-2.6.8]# make

     

    [root@server2redis-2.6.8]# make test

    cd src && maketest

    make[1]: Entering directory`/home/admin/redis-2.6.8/src'

    which: no tclsh8.5 in(/home/admin/hbase-0.90.5/bin:/home/admin/hadoop-0.20.2/bin:/opt/jdk1.7.0_07/bin:/usr/lib64/qt-3.3/bin:/usr/local/bin:/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/sbin:/home/admin/bin)

    You need 'tclsh8.5' in orderto run the Redis test

    make[1]: *** [test] Error1

    make[1]: Leaving directory`/home/admin/redis-2.6.8/src'

    make: *** [test] Error2

     

    提示要安装tclsh8.5, 则先安装

    [root@server2redis-2.6.8]# yum installtcl

    然后make test, 通过测试。

    [root@server2redis-2.6.8]# makeinstall

    安装成功

     

    修改redis.conf,设置redis为后台守护进程

    [root@server2redis-2.6.8]# vimredis.conf

     

    # By default Redis does notrun as a daemon. Use 'yes' if you need it.

    # Note that Redis will write apid file in /var/run/redis.pid when daemonized.

    daemonize yes

     

    复制文件

    [root@server2redis-2.6.8]# cp redis.conf /etc/

    [root@server2redis-2.6.8]# cp src/redis-server/usr/local/bin/

     

    3. 启动redis

    [root@server2redis-2.6.8]# redis-server/etc/redis.conf

    查看进程

    [root@server2redis-2.6.8]# psaux | grep redis

    root     5074  0.4  0.7 40452  7284 ?   Ssl 03:07  0:00 redis-server/etc/redis.conf

    root     7405  0.0  0.0103248  836 pts/0 S+ 03:09   0:00 grepredis

     

    4. Telnet登录操作

    [admin@server3~]$ telnetserver2 6379

    Trying192.168.1.202...

    Connected toserver2.

    Escape character is'^]'.

    set bar fffffffffffff

    +OK

    get bar

    $13

    fffffffffffff

     

    5.Java连接Redis

     

    Jedis包导入项目中

    测试代码如下:

     

    packagenosql.redis;

     

    importredis.clients.jedis.Jedis;

    importredis.clients.jedis.JedisPool;

     

     

    public class JedisTest{

     

       public static void main(String[] args) {

           JedisPool pool = new JedisPool("192.168.1.202", 6379);

           Jedis jedis = pool.getResource();

           

           //清空数据

           jedis.flushAll();

     

           //操作String

           jedis.set("site", "dataguru");

           System.out.println(jedis.get("site"));

     

           //操作list

           jedis.lpush("nosql", "hbase");

           jedis.lpush("nosql", "redis");

           jedis.lpush("nosql", "mongodb");

           jedis.lpush("nosql", "couchdb");

           jedis.lpush("nosql", "neo4j");

           System.out.println(jedis.lrange("nosql", 0, -1));

       }

    }

     

    打印结果:

     

    dataguru

    [neo4j, couchdb, mongodb,redis, hbase] 

  • 相关阅读:
    深入RESTful无状态原则
    基于Tomcat7、Java、WebSocket的服务器推送聊天室
    java.lang.NoSuchMethodException: org.apache.catalina.deploy.WebXml addServlet
    POI操作Excel常用方法总结
    第章 子例程引用与闭包
    集团企业数据信息系统建设方案
    集团企业数据信息系统建设方案
    不是更快更强,而是更加自如——2015年终总结
    RESTful_基础知识
    RESTful_基础知识
  • 原文地址:https://www.cnblogs.com/leeeee/p/7276618.html
Copyright © 2020-2023  润新知