1. 程式人生 > >redis實戰

redis實戰

conn ces div github system -m row cli color

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實戰