redis 服务器安装

安装:
1.获取redis资源

wget http://download.redis.io/releases/redis-4.0.8.tar.gz

2.解压

tar xzvf redis-4.0.8.tar.gz

3.安装

(1)cd redis-4.0.8

(2)make

(3)cd src

(4)make install PREFIX=/usr/local/redis
到这里的时候,需要安装一个其他组件

[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。

1、先去这里下载:
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

www.beicaiduo.com
原文地址:https://www.cnblogs.com/hoge66/p/12017078.html