DB-redis-install
docker swarm 安装 redis
创建redis挂载目录
/dockerdata/v-redis
并在该目录
vim redis.conf
新建配置文件,配置文件添加如下内容1
requirepass <登陆密码,最好64位以上>
编辑
vim stack-redis.yml
,内容如下1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16version: '3'
services:
redis:
image: redis
restart: always
ports:
- 14007:6379
command: "redis-server /data/redis.conf"
volumes:
- "/dockerdata/v-redis:/data"
deploy:
replicas: 1
restart_policy:
condition: on-failure
placement:
constraints: [node.hostname == xuanps]运行启动
docker stack deploy -c stack-redis.yml redis
测试命令
1
2
3
4
5
6#本地直接redis-cli不需要任何参数
redis-cli -h host -p port -a password
#进入redis,用改名了进行密码登陆
AUTH "password"
#查询所有key
keys *
springboot 连接redis
添加
pom.xml
依赖1
2
3
4<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-redis</artifactId>
</dependency>编辑
application.yml
添加redis连接信息1
2
3
4
5
6spring:
redis:
database: 0
host: 112.74.51.136
port: 14007
password: <你的密码>编写测试类
1
2
3
4
5
6
7
8
StringRedisTemplate stringRedisTemplate;
public void testredis(){
stringRedisTemplate.opsForValue().set("testconnect","hello world");
String test= stringRedisTemplate.opsForValue().get("testconnect");
log.info(test);
}