安裝:
1.獲取redis資源html
wget http://download.redis.io/releases/redis-4.0.8.tar.gzjava
2.解壓web
tar xzvf redis-4.0.8.tar.gzredis
3.安裝spring
(1)cd redis-4.0.8api
(2)makespringboot
(3)cd src服務器
(4)make install PREFIX=/usr/local/redis
到這裏的時候,須要安裝一個其餘組件app
[root@localhost src]# make test
You need tcl 8.5 or newer in order to run the Redis test
make: *** [test] Error 1
在這裏發現有錯誤
TCL(Tool Command Language)工具腳本語言,是Linux內的一種語言包。,這裏須要先安裝tcl。spring-boot
一、先去這裏下載:
wget http://downloads.sourceforge.net/tcl/tcl8.6.1-src.tar.gz
tar xzvf tcl8.6.1-src.tar.gz
安裝 Tcl
爲編譯 Tcl 作準備:
cd 到tcl文件夾裏
[root@localhost Desktop]# cd tcl8.6.1/
cd unix
[root@localhost tcl8.6.1]# cd unix/
./configure
[root@localhost unix]# ./configure
編譯軟件包:
[root@localhost unix]# make
安裝軟件包:
[root@localhost unix]# make install
這個時候在命令行就能夠輸入tclsh進入tcl解釋器
tcl就能夠使用了。
繼續安裝redis==========》
make install PREFIX=/usr/local/redis
沒什麼反應,提示先make test;
執行 make test
no problem.
[root@iZbp1davrpkdfc7ms990k0Z redis-4.0.8]# cp redis.conf /etc [root@iZbp1davrpkdfc7ms990k0Z redis-4.0.8]# vi /etc/redis.conf
修改其中的:將daemonize no 改爲daemonize yes 配置爲後臺啓動;
啓動:[root@iZbp1davrpkdfc7ms990k0Z redis-4.0.8]# /usr/local/bin/redis-server /etc/redis.conf
測試:
[root@iZbp1davrpkdfc7ms990k0Z redis-4.0.8]# redis-cli 127.0.0.1:6379> set foo bar OK 127.0.0.1:6379> get foo "bar" 127.0.0.1:6379> quit [root@iZbp1davrpkdfc7ms990k0Z redis-4.0.8]#
設置開機啓動:vi /etc/rc.local
添加一句:/usr/local/bin/redis-server /etc/redis.conf
---》設置密碼:
vi /etc/redis.conf
添加一句:requirepass 123456
重啓:redis-cli
shutdown
須要輸入密碼的時候,這樣寫:127.0.0.1:6379> auth "123456"
一些操做:
[root@iZbp1davrpkdfc7ms990k0Z ~]# /usr/local/bin/redis-server /etc/redis.conf 4104:C 10 Dec 15:34:24.142 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo 4104:C 10 Dec 15:34:24.143 # Redis version=4.0.8, bits=64, commit=00000000, modified=0, pid=4104, just started 4104:C 10 Dec 15:34:24.143 # Configuration loaded [root@iZbp1davrpkdfc7ms990k0Z ~]# set platform:info "simple information" [root@iZbp1davrpkdfc7ms990k0Z ~]# redis-cli 127.0.0.1:6379> set platform:info "simple information" (error) NOAUTH Authentication required. 127.0.0.1:6379> auth "123456" OK 127.0.0.1:6379> set platform:info "simple information" OK 127.0.0.1:6379> get platform:info "simple information" 127.0.0.1:6379> keys platform:* 1) "platform:info" 127.0.0.1:6379> exists platform:info (integer) 1 127.0.0.1:6379> expire platform 10 (integer) 0 127.0.0.1:6379> ttl platform (integer) -2 127.0.0.1:6379> expire platform:info 10 (integer) 1 127.0.0.1:6379> ttl platform:info (integer) -2 127.0.0.1:6379> get platform:info (nil) 127.0.0.1:6379>
與springboot整合
pom:
<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-data-redis</artifactId> </dependency>
配置文件:
redis: database: 0 timeout: 10000 # 鏈接超時時間(毫秒) password: 111222Hoge host: 41.91.231.61 port: 6379 maxRedirections: 5
controller:
package com.bcd.cloud.pf.bcdtaokerestapi.controller; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.data.redis.core.StringRedisTemplate; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.ResponseBody; /** * OrderRestController class * * @author keriezhang * @date 2016/10/31 */ @Controller @RequestMapping("/strredis") public class RedisStringController { @Autowired private StringRedisTemplate redisTemplate; @RequestMapping("/setget.html") @ResponseBody public String env(){ redisTemplate.opsForValue().set("testenv","input redis."); String str=redisTemplate.opsForValue().get("testenv"); return str; } }
服務器上redis.conf 修改:
修改 protected-mode yes 改成:protected-mode no
註釋掉 #bind 127.0.0.1
SCM裏的啓動: /usr/local/redis/bin/redis-server /etc/redis.conf