Redis記憶體緩衝系統入門

來源:互聯網
上載者:User

標籤:

網站:http://redis.io/

key-value cache and store    data structure server

1. 伺服器端 1.1 安裝

下載安裝包:http://redis.io/download

解壓之後make即可。

$ wget http://download.redis.io/releases/redis-3.0.0.tar.gz$ tar xzf redis-3.0.0.tar.gz$ cd redis-3.0.0$ make
1.2 運行方式:
$ src/redis-server

這種啟動方式使用的是預設配置,也可以通過指定設定檔位置進行啟動,如下:

$ src/redis-server redis.conf
1.3 存取權限控制1.3.1 綁定ip的方式

在設定檔中,添加如下:

bind 127.0.0.1 IP1 IP2 ... ...
1.3.2 設定密碼

在設定檔中,添加如下:

requirepass yourpassword
1.4 內建用戶端:
$ src/redis-cliredis> set foo barOKredis> get foo"bar"
1.4.1 授權訪問
$ src/redis-cliredis> auth password redis> set foo barOKredis> get foo"bar"

帶密碼方式的登陸

$ src/redis-cli -a passwordredis> set foo barOKredis> get foo"bar"
2. 用戶端

http://redis.io/clients

支援很多語言的用戶端,這裡介紹java的jedis。

2.1 Jedis源碼

https://github.com/xetorthio/jedis

下載Jedis後,可以編譯產生jar檔案,供後續使用。

  1. 下載tar.gz或者zip檔案,解壓開啟可以看到,jedis採用的是maven構建工程的。
  2. 使用Eclipse的maven項目匯入,在Package Exploer右鍵Import,選擇maven工程。
  3. 右鍵export出jar檔案包。
2.2 Java測試程式

package cn.ac.iscas.test;import redis.clients.jedis.Jedis;import org.junit.Test;/** * @ClassName: MyTest * @Description: TODO * @author:  * @Date: 2015-04-12 19:27:09 */public class MyTest {    public static Jedis jedis = null;    // redis主機IP地址    public static final String HOST = "192.168.1.144";    // redis主機連接埠    public static final Integer PORT = 6379;    public static Jedis getClient() {        if (jedis == null) {            jedis = new Jedis(HOST, PORT);        }        return jedis;    }    @Test    public void test() {        getClient();        jedis.set("key", "123");        System.out.println(jedis.get("key"));        jedis.incr("key");        System.out.println(jedis.get("key"));    }}

Redis記憶體緩衝系統入門

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.