-- from? http://redis.io/ ?
?
redis ?是一個(gè)基于內(nèi)存的高性能key-value數(shù)據(jù)庫,數(shù)據(jù)都保存在內(nèi)存中定期刷新到磁盤,以極高的讀寫效率而備受關(guān)注。他的特點(diǎn)是支持各種數(shù)據(jù)結(jié)構(gòu),stirng,hashes, list,set,和sorted setsclient端對(duì)于不同數(shù)據(jù)結(jié)構(gòu)是使用不同的命令
?
這里說一下redis的安裝
虛擬機(jī)環(huán)境: ?centos ?
?
1 wget ?make 安裝
wget? http://download.redis.io/redis-stable.tar.gz
tar xvzf redis-stable.tar.gz
cd redis-stable
make
?
注 : ? 這里記錄一下我安裝過程中出現(xiàn)的問題 : ?
make: Warning: File `Makefile' has modification time 5.4e+06 s in the future
cd src && make all
make[1]: Entering directory `/redis/redis-2.4.7/src'
make[1]: Warning: File `Makefile' has modification time 5.4e+06 s in the future
MAKE hiredis
make[2]: Entering directory `/redis/redis-2.4.7/deps/hiredis'
make[2]: Warning: File `Makefile' has modification time 5.4e+06 s in the future
cc -c -std=c99 -pedantic -O3 -fPIC -Wall -W -Wstrict-prototypes -Wwrite-strings??? -g -ggdb? net.c
make[2]: cc: Command not found
make[2]: *** [net.o] Error 127
make[2]: Leaving directory `/redis/redis-2.4.7/deps/hiredis'
make[1]: *** [dependencies] Error 2
make[1]: Leaving directory `/redis/redis-2.4.7/src'
make: *** [all] Error 2
?
?
第一個(gè)問題
make: Warning: File `Makefile' has modification time 5.4e+06 s in the future
系統(tǒng)時(shí)間調(diào)整錯(cuò)了,調(diào)過來就好了
?
第二個(gè)問題:
make[2]: Entering directory `/redis/redis-2.4.7/deps/hiredis'
cc -c -std=c99 -pedantic -O3 -fPIC -Wall -W -Wstrict-prototypes -Wwrite-strings??? -g -ggdb? net.c
make[2]: cc: Command not found
沒安裝 gcc ,
yum install gcc-c++
?
第三個(gè)問題:
make 的時(shí)候顯示
make[1]: Entering directory `/redis/redis-2.4.7/src'
which: no tclsh8.5 in (/usr/kerberos/sbin:/usr/kerberos/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin)
You need 'tclsh8.5' in order to run the Redis test
沒安裝 tcl
按照官網(wǎng)
http://www.linuxfromscratch.org/blfs/view/cvs/general/tcl.html
?上的安裝
?
安裝完成之后, make 成功!
?
安裝成功之后會(huì)在 src 文件夾內(nèi)有redis-server和redis-cli兩個(gè)命令
建議將其放到 bin 下
sudo cp redis-server /usr/local/bin/
sudo cp redis-cli /usr/local/bin/
?
?
好了,現(xiàn)在 redis 就安裝成功了
?
2 測試redis安裝情況?
我只在一臺(tái)虛擬機(jī)上安裝了 redis ,所以這臺(tái)虛擬機(jī)既是服務(wù)器,又是客戶端
測試:
?
1? 使用 secureRt 打開一個(gè)會(huì)話,redis-server,讓其作為服務(wù)器運(yùn)行
[19282] 19 Feb 23:52:57 - 1 clients connected (0 slaves), 726248 bytes in use
[19282] 19 Feb 23:53:02 - DB 0: 1 keys (0 volatile) in 4 slots HT.
[19282] 19 Feb 23:53:02 - 1 clients connected (0 slaves), 726248 bytes in use
[19282] 19 Feb 23:53:07 - DB 0: 1 keys (0 volatile) in 4 slots HT.
[19282] 19 Feb 23:53:07 - 1 clients connected (0 slaves), 726248 bytes in use
?
2? 打開另一個(gè)會(huì)話:
ast login: Tue Feb 19 22:49:49 2013 from 192.168.1.103
?
set key 和 get key 都正確
redis 搭建測試通過 ?
?
參考文章:
http://redis.io/topics/quickstart ?
http://hi.baidu.com/thinkinginlamp/blog/item/3358c93d174e35ce9f3d62bf.html ?
持久化 ?
redis 支持 RDB 和 AOF 兩種持久化方式
?
The RDB persistence performs point-in-time snapshots of your dataset at specified intervals.
RDB 是一種即時(shí)快照的存儲(chǔ)方式,定時(shí)對(duì)數(shù)據(jù)庫進(jìn)行 snap shot
RDB 優(yōu)點(diǎn):
1 RDB 對(duì)于數(shù)據(jù)備份非常容易。你可以設(shè)置 1 天或者 30 天對(duì)數(shù)據(jù)進(jìn)行一次備份,這樣當(dāng)發(fā)生數(shù)據(jù)災(zāi)難的時(shí)候能很容易恢復(fù)
2? 由于 RDB 對(duì)數(shù)據(jù)備份時(shí) redis 只做備份操作,所以備份最大化的使用了 redis 的性能,同時(shí)也導(dǎo)致了對(duì)于大的數(shù)據(jù)集, RDB 備份快于 AOF
?
RDB 缺點(diǎn):
1? 如果你的需求只是要知道兩個(gè)時(shí)間段中 redis 的變化, RDB 是弱于 AOF 的
2? 由于 RDB 經(jīng)常使用子進(jìn)程 fork() 進(jìn)行數(shù)據(jù)備份,所以如果當(dāng)數(shù)據(jù)比較大的時(shí)候,數(shù)據(jù)備份會(huì)比較耗時(shí)
?
AOF 優(yōu)點(diǎn):
1? 你必須有一個(gè) AOF 的 f sync 的策略:
或者是不進(jìn)行 fsync , ? 或者每秒 fsync 一次,或者每次 query 查詢的時(shí)候 fsync
2 AOF 只記錄修改 log ,當(dāng)存儲(chǔ)的時(shí)候由于某種原因?qū)? log 失誤了,使用 redis -check-aof 能很好的修復(fù)
3? 當(dāng) redis 數(shù)據(jù)太大的時(shí)候, AOF 可以很好被重寫到新的 redis 上
?
AOF 缺點(diǎn):
1 AOF 通常比 RDB 大
2 AOF 比 RDB 慢
?
?--------------------------
流水線
?
redis 是客戶端和服務(wù)器端的通信交互 TCP 協(xié)議
?
當(dāng)客戶端發(fā)送請(qǐng)求,服務(wù)器端接受請(qǐng)求并發(fā)送回復(fù),客戶端接收回復(fù),這個(gè)過程叫做 RTT (Round Trip Time)
比如如果 RTT 時(shí)間是 250 微秒,既是服務(wù)器端每秒能處理 10 萬個(gè)請(qǐng)求,那么,我們只能認(rèn)為 redis 每秒處理 4 個(gè)請(qǐng)求
?
server 不需要等待 client 接收了消息之后再處理新 request 的技術(shù)叫做 pipe lining (流水線)。這個(gè)技術(shù)早在幾十年前就應(yīng)用在了各種協(xié)議上(比如 pop3 ), redis 也很早使用了這個(gè)技術(shù)。
?
實(shí)驗(yàn):
$ (echo -en "PING\r\nPING\r\nPING\r\n"; sleep 1) | nc localhost 6379
當(dāng)調(diào)用這個(gè)例子的時(shí)候:
server 一次返回:
+PONG
+PONG
+PONG
?
而不是返回一次 PONG ,過了 RTT 時(shí)間再返回 PONG ,這個(gè)例子就說明了 redis 使用 pipe lining
?
注: nc 命令說明請(qǐng)看:
http://www.cnblogs.com/faraway/archive/2008/08/30/1280070.html ?
?
?
---------------------------------
訂閱?
?
? redis 支持訂閱( sub scribe )
當(dāng)一個(gè) client 訂閱一個(gè)或多個(gè)變量,其他客戶端修改了變量并 publish 之后,這個(gè)客戶端會(huì)收到消息
?
例子:
Client 1:
SUBSCRIBE first second
?
Client2:
PUBLISH second Hello
?
client1 顯示:
message
second
Hello2
?
?
redis 還支持模式訂閱( psubscribe 命令)
PSUBSCRIBE f*
?
PHP
?
公告
姓名:葉劍峰
園名:軒脈刃
英文名:nick ye
?
?
?
開開心心做事
?
夫茍其挫而不退矣,則小逆之后,必有小順。大逆之后,必有大順。
?
?
?
|
|||||||||
日 | 一 | 二 | 三 | 四 | 五 | 六 | |||
---|---|---|---|---|---|---|---|---|---|
29 | 30 | 31 | 1 | 2 | 3 | 4 | |||
5 | 6 | 7 | 8 | 9 | 10 | 11 | |||
12 | 13 | 14 | 15 | 16 | 17 | 18 | |||
19 | 20 | 21 | 22 | 23 | 24 | 25 | |||
26 | 27 | 28 | 29 | 1 | 2 | 3 | |||
4 | 5 | 6 | 7 | 8 | 9 | 10 |
搜索
我的標(biāo)簽
隨筆分類
隨筆檔案
最新評(píng)論
- 1. Re:redis搭建實(shí)戰(zhàn)記錄
- lz 貌似e文不錯(cuò),redis的文檔官方?jīng)]提供中文版的吧!
- --lhy
- 2. Re:MySQL體系結(jié)構(gòu)
- 值得一看!
- --鄒雙平
- 3. Re:MySQL體系結(jié)構(gòu)
- 不錯(cuò)
- --遺忘海岸
- 4. Re:MySQL體系結(jié)構(gòu)
- 一樓和俺是同姓
- --BillGan
- 5. Re:MySQL體系結(jié)構(gòu)
- 寫的不錯(cuò),收藏。
- --甘南
閱讀排行榜
評(píng)論排行榜
---------------------------------
參考文檔:
---------------------------------
作者:yjf512(軒脈刃)
出處:http://www.cnblogs.com/yjf512/
本文版權(quán)歸yjf512和cnBlog共有,歡迎轉(zhuǎn)載,但未經(jīng)作者同意必須保留此段聲明?
更多文章、技術(shù)交流、商務(wù)合作、聯(lián)系博主
微信掃碼或搜索:z360901061

微信掃一掃加我為好友
QQ號(hào)聯(lián)系: 360901061
您的支持是博主寫作最大的動(dòng)力,如果您喜歡我的文章,感覺我的文章對(duì)您有幫助,請(qǐng)用微信掃描下面二維碼支持博主2元、5元、10元、20元等您想捐的金額吧,狠狠點(diǎn)擊下面給點(diǎn)支持吧,站長非常感激您!手機(jī)微信長按不能支付解決辦法:請(qǐng)將微信支付二維碼保存到相冊(cè),切換到微信,然后點(diǎn)擊微信右上角掃一掃功能,選擇支付二維碼完成支付。
【本文對(duì)您有幫助就好】元
