Ubuntu環境下的Redis 配置與C++使用入門,ubunturedis

來源:互聯網
上載者:User

Ubuntu環境下的Redis 配置與C++使用入門,ubunturedis

  Redis是一個高效能的key-value資料庫。 Redisedis的出現,很大程度補償了memcached這類key/value儲存的不足,在部分場合可以對關聯式資料庫起到很好的補充作用。它提供了Java,C/C++,C#,PHP,JavaScript,Perl,Object-C,Python,Ruby,Erlang等用戶端,使用很方便。

    本文將通過介紹Ubuntu環境下的Redis 配置,介紹C++入門使用的方式,協助讀者快速上手Redis。

安裝配置
擷取源碼、解壓、進入源碼目錄,編譯

$ wget http://download.redis.io/releases/redis-2.8.13.tar.gz$ tar xzf redis-2.8.13.tar.gz$ cd redis-2.8.13$ make


測試、安裝

$ make-test$ sudo make install

make命令執行完成後,會在 src 目錄下產生本個可執行檔,分別是redis-server、redis-cli、redis-benchmark、redis-stat,它們的作用如下:

redis-server         :Redis伺服器的daemon啟動程式
redis-cli                :Redis命令列操作工具。當然,你也可以用telnet根據其純文字協議來操作
redis-benchmark  :Redis效能測試工具,測試Redis在你的系統及你的配置下的讀寫效能
redis-stat              :Redis狀態偵查工具,可以檢測Redis目前狀態參數及延遲狀況。

Run Redis with:

$ src/redis-server

You can interact with Redis using the built-in client:

$ src/redis-cliredis> set foo barOKredis> get foo"bar"


C++配置與入門使用 配置

on Ubuntu:

$ apt-get install libhiredis-dev

On OSX run:

$ brew install hiredis

on other platforms:

$ git clone https://github.com/antirez/hiredis.git && cd hiredis && make && sudo make install && sudo ldc

否則,由於缺少hiredis依賴關係,可能出現錯誤:

error: hiredis/hiredis.h: No such file or directory

入門使用

redisTest.cpp

#include <stdio.h>#include <hiredis/hiredis.h>int main(){    redisContext* conn = redisConnect("127.0.0.1",6379);    if(conn->err){        printf("connection error:%s\n",conn->errstr);    }      redisReply* reply = (redisReply*)redisCommand(conn,"set foo 1234");    freeReplyObject(reply);    reply = (redisReply*)redisCommand(conn,"get foo");    printf("%s\n",reply->str);    freeReplyObject(reply);    redisFree(conn);    return 0;}


編譯命令

g++ redisTest.cpp -o redisTest -I./deps/hiredis/ -L./deps/hiredis/ -lhiredis





ubuntu 配置c編程環境

sudo apt-get install build-essential

build-essential是c語言的開發包,包含了gcc make gdb和libc函數庫 很多工具
 
新手大俠協助,ubuntu下eclipse配置c 、c++開發環境 建立C檔案時 出錯,

建議用Visual Stdio 或者Visual C++軟體編寫C/C++,我們基本都用這兩個。
你那裡的報錯也許是沒配置好,或者C檔案的存放地址和串連不相匹配,建議重新選擇Location,不要太深了,在放在根目錄的檔案夾下,就三層,看到你放置在第五層,調試起來就麻煩多了。
 

相關文章

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.