Redis簡介

Redis 是一個開源(BSD許可)的,內(nèi)存中的數(shù)據(jù)結(jié)構(gòu)存儲系統(tǒng),它可以用作數(shù)據(jù)庫、緩存和消息中間件。 它支持多種類型的數(shù)據(jù)結(jié)構(gòu),如 字符串(strings), 散列(hashes), 列表(lists), 集合(sets), 有序集合(sorted sets) 與范圍查詢, bitmaps, hyperloglogs 和地理空間(geospatial) 索引半徑查詢。 Redis 內(nèi)置了 復(fù)制(replication),LUA腳本(Lua scripting), LRU驅(qū)動事件(LRU eviction),事務(wù)(transactions) 和不同級別的 磁盤持久化(persistence), 并通過 Redis哨兵(Sentinel)和自動 分區(qū)(Cluster)提供高可用性(high availability)。
Linux 下安裝
下載地址:http://redis.io/download,下載最新文檔版本。
本教程使用的最新文檔版本為 4.0.1,下載并安裝:
$ wget http://download.redis.io/releases/redis-4.0.1.tar.gz
$ tar -zvxf redis-4.0.1.tar.gz
$ cd redis-4.0.1
$ make
如果遇到gcc:未找到命令錯誤,運(yùn)行如下指令
yum -y install gcc automake autoconf libtool
如果在報(bào)錯 zmalloc.h:50:31: 錯誤:jemalloc/jemalloc.h:沒有那個文件或目錄。原因:分配器allocator, 如果有MALLOC 這個 環(huán)境變量, 會有用這個環(huán)境變量的 去建立Redis。而且libc 并不是默認(rèn)的 分配器, 默認(rèn)的是 jemalloc, 因?yàn)?jemalloc 被證明 有更少的 fragmentation problems 比libc。但是如果你又沒有jemalloc 而只有 libc 當(dāng)然 make 出錯。 所以加這么一個參數(shù),運(yùn)行如下命令:
make MALLOC=libc
安裝完后進(jìn)行安裝檢驗(yàn)
$ make test

如果遇到Redis need tcl 8.5 or newer
$ make test
You need tcl 8.5 or newer in order to run the Redis test
make: *** [test] Error 1
安裝下tcl
$ wget http://downloads.sourceforge.net/tcl/tcl8.6.1-src.tar.gz
$ tar xzvf tcl8.6.1-src.tar.gz
$ cd /tcl8.6.1/unix/
$ ./configure
$ make
$ make install
再次運(yùn)行$ make test
啟動Redis服務(wù)器端
$ cd src
$ ./redis-server

注意這種方式啟動redis 使用的是默認(rèn)配置。也可以通過啟動參數(shù)告訴redis使用指定配置文件使用下面命令啟動。
$ cd src
$ ./redis-server ../redis.conf
遇到如下問題:Linux上的redis出現(xiàn) DENIED Redis is running in protected mode
解決方案:Linux部署的redis 啟動采用該種方式啟動 要不然修改配置文件的內(nèi)容不生效
客戶端連接
$ cd src
$ ./redis-cli
127.0.0.1:6379> set foo helloworld!
OK
127.0.0.1:6379> get foo
"helloworld!"

通過客戶端關(guān)閉服務(wù)端
127.0.0.1:6379> SHUTDOWN或者可以通過
kill -9 PID號關(guān)閉服務(wù)器端

但是Redis不是在后臺運(yùn)行,做如下操作:將redis.conf中的daemonize的值改為yes
