码迷,mamicode.com
首页 > 其他好文 > 详细

redis实战

时间:2018-06-19 17:12:53      阅读:187      评论:0      收藏:0      [点我收藏+]

标签:++   安装   lin   mysql   download   print   and   cli   pre   

1、linux 系统下安装

  $ wget http://download.redis.io/releases/redis-3.2.6.tar.gz 

  tarxzfredis?3.2.6.tar.gztarxzfredis?3.2.6.tar.gz

  cd redis-3.2.6 

  $ make

  

启动服务器:

 ```
    $ src/redis-server
 ```

 启动客户端

 ```
 $ src/redis-cli
 ```

mac下安装:

 ```
brew install redis

启动:

redis-server
redis-cli 

在java应用中使用redis—jedis

  前提是redis 已经安装,并且已经开启服务。

  jedis 下载地址 https://github.com/xetorthio/jedis

 

    public static void main(String[] args){

        Jedis jedis = new Jedis("localhost");
        System.out.println("Connection to server sucessfully");
        //check whether server is running or not
        System.out.println("Server is running: "+jedis.ping());
        jedis.lpush("forezp-list", "Redis");
        jedis.lpush("forezp-list", "Mongodb");
        jedis.lpush("forezp-list", "Mysql");
        // Get the stored data and print it
        List<String> list = jedis.lrange("forezp-list", 0 ,5);
        for(int i=0; i<list.size(); i++) {
            System.out.println("Stored string in redis:: "+list.get(i));
        }

    }

 

 

  

redis实战

标签:++   安装   lin   mysql   download   print   and   cli   pre   

原文地址:https://www.cnblogs.com/AttackLion/p/9199337.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!