Redis簡單示例

一、Redis是一個開源的使用ANSI C語言編寫、支持網絡、可基於內存亦可持久化的日誌型、Key-Value數據庫,並提供多種語言的API。
    從2010年3月15日起,Redis的開發工做由VMware主持。從2013年5月開始,Redis的開發由Pivotal贊助。
二、下載 redis-3.2.6.tar.gz,解壓,進入目錄redis-3.2.6,而後make
三、在src目錄下,生成一些二進制可執行文件。以下:
    [root@localhost src]# ll|grep -v "\."
    total 33384
    -rwxrwxrwx 1 root root    8173 Dec  6 16:38 Makefile
    -rwxr-xr-x 1 root root 4560528 Feb 10 09:38 redis-benchmark
    -rwxr-xr-x 1 root root   16880 Feb 10 09:38 redis-check-aof
    -rwxr-xr-x 1 root root 6401156 Feb 10 09:38 redis-check-rdb
    -rwxr-xr-x 1 root root 4661462 Feb 10 09:38 redis-cli
    -rwxr-xr-x 1 root root 6401156 Feb 10 09:38 redis-sentinel
    -rwxr-xr-x 1 root root 6401156 Feb 10 09:38 redis-server
    文件介紹以下:
    ./redis-benchmark   //用於進行redis性能測試的工具
    ./redis-check-dump  //用於修復出問題的dump.rdb文件
    ./redis-cli         //redis的客戶端
    ./redis-server      //redis的服務端
    ./redis-check-aof   //用於修復出問題的AOF文件
    ./redis-sentinel    //用於集羣管理
四、啓動redis服務,以下:
    [root@localhost src]# ./redis-server
    監聽端口是6379,以下:
    [root@localhost ~]# netstat -anp|grep 6379
    tcp        0      0 0.0.0.0:6379                0.0.0.0:*                   LISTEN      3408/redis-server * 
    tcp        0      0 :::6379                     :::*                        LISTEN      3408/redis-server *
五、啓動redis客戶端,以下:
    [root@localhost src]# ./redis-cli --help
    查看幫助信息
六、設置,獲取,刪除,最簡單的例子以下:
    [root@localhost src]# ./redis-cli
    127.0.0.1:6379> get name
    (nil)
    127.0.0.1:6379> set name andy
    OK
    127.0.0.1:6379> get name
    "andy"
    127.0.0.1:6379> del name
    (integer) 1
    127.0.0.1:6379> get name
    (nil)
相關文章
相關標籤/搜索