当前位置:网站首页>Docker安装Redis、配置及远程连接
Docker安装Redis、配置及远程连接
2022-07-29 10:01:00 【超级种码】
前言
有关Redis的更多内容请看:键值型数据库之Redis
安装
创建一个Redis网络
docker network create redis
创建数据卷
用于存放持久化数据和配置文件。
cd ~
mkdir -p redis/data
mkdir redis/conf
touch redis/conf/redis.conf
编辑配置文件
进入配置文件:
vim ~/redis/conf/redis.conf
按i进入编辑模式并添加以下最简配置:
protected-mode no
user default on >123456 ~* &* [email protected]
按ESC并输入:wq保存退出。
运行redis容器
docker run --name master-redis \
--net redis \
-p 6379:6379 \
-v ~/redis/data:/data \
-v ~/redis/conf:/usr/local/etc/redis \
-d redis redis-server /usr/local/etc/redis/redis.conf
使用脚手架连接
进入脚手架
docker run -it --net redis --rm redis redis-cli -h master-redis
验证密码
auth default 123456
即可使用。
远程连接(以springBoot为例)
开放端口
不同的系统可能不同,但网上应该都有,这里以centos7为例(如果是云服务器防火墙可能是关闭的):
firewall-cmd --zone=public --add-port=6379/tcp --permanent
引入依赖
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-redis</artifactId>
<version>${redis-version}</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<version>${test-version}</version>
</dependency>
yml配置
spring:
redis:
host: RedisIP
port: 6379
connect-timeout: 5000
username: default
password: 123456
测试类
@SpringBootTest
public class DataRedisTest {
@Resource
private StringRedisTemplate StringredisTemplate;
@Test
public void redisTest(){
StringredisTemplate.opsForValue().set("test","hello");
}
}
边栏推荐
- MySQL logging system: binlog, redo log and undo log
- Youboxun, the gold donor of the open atom open source foundation, joined hands with partners to help openharmony break the circle!
- Correct posture and landing practice of R & D efficiency measurement (speech ppt sharing version)
- Which hero is the most difficult for lol in terms of code?
- Summary of JD internship written examination questions
- Dynamics 365Online 如何自定义商机关闭窗体
- Method of cocos2d-x sprite moving
- 待人宽容大度
- 还是有机会的
- 综合设计一个OPPE主页--页面的底部
猜你喜欢

Leetcode question brushing - sorting

通俗易懂讲解梯度下降法!

vector实现

On memory computing integrated chip technology

Function - (C travel notes)

不堆概念、换个角度聊多线程并发编程

Only simple function test? One article takes you to advanced interface automatic testing technology in 6 steps

i. Mx6ull driver development | 32 - manually write a virtual network card device

What kind of framework is friendly to developers?

Which hero is the most difficult for lol in terms of code?
随机推荐
Several common design methods of test cases [easy to understand]
leetcode刷题——排序
Does neural network sound tall? Take you to train a network from scratch (based on MNIST)
Node (II)
TCP failure model
我的问题解决记录1:类上使用了@Component注解,想要使用这个类中的方法,便不能直接new,而应该使用# @Autowired进行注入,否则会报错(如空指针异常等)
How to customize the opportunity closing form in dynamics 365online
10 suggestions for 10x improvement of application performance
[FPGA tutorial case 19] factorial operation through multiplier
Orbslam2 installation test and summary of various problems
English语法_不定代词 - 常用短语
Window系统操作技巧汇总
QoS quality of service five traffic shaping of QoS boundary behavior
System architect learning
How big is the bandwidth of the Tiktok server for hundreds of millions of people to brush at the same time?
Why does the system we developed have concurrent bugs? What is the root cause of concurrent bugs?
mysql 数据库 期末复习题库
上海交大牵手淘宝成立媒体计算实验室:推动视频超分等关键技术发展
Pytest+allure generate test report
【AAAI】用于交通流预测的基于注意力的时空图卷积网络