当前位置:网站首页>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");
}
}
边栏推荐
- Method of cocos2d-x sprite moving
- Summary of window system operation skills
- Youboxun, the gold donor of the open atom open source foundation, joined hands with partners to help openharmony break the circle!
- 根据给定字符数和字符,打印输出“沙漏”和剩余数
- JS to achieve full screen effect
- 上海交大牵手淘宝成立媒体计算实验室:推动视频超分等关键技术发展
- English语法_不定代词 - 常用短语
- Zhongang Mining: four steps for sustainable and healthy development of fluorite industry
- 7.9-7.17 new features and grammar of learning plan ES6
- CS assurance and research experience in 2021 (IV): pre promotion and exemption of Xijiao soft Research Institute and the third room of Information Technology Institute
猜你喜欢

ECCV 2022 | CMU提出在视觉Transformer上进行递归,不增参数,计算量还少
![[jetson][转载]jetson上安装pycharm](/img/65/ba7f1e7bd1b39cd67018e3f17d465b.png)
[jetson][转载]jetson上安装pycharm

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

leetcode刷题——排序

造型科幻、标配6安全气囊,风行·游艇11.99万起售

Geeer's happiness | is for the white whoring image! Analysis and mining, NDVI, unsupervised classification, etc

vector实现

Where are those test / development programmers in their 30s? a man should be independent at the age of thirty......

Virtual machines use host graphics cards (Hyper-V and wsl2)

上海交大牵手淘宝成立媒体计算实验室:推动视频超分等关键技术发展
随机推荐
高效能7个习惯学习笔记
Reasons for the rise of DDD and its relationship with microservices
函数和数组
读博后降维打击数学建模!
Meituan senior technical expert: DDD's practice in the evolution of tourism e-commerce architecture
电竞入亚后,腾讯要做下一个“NBA赛事捕手”?
这是一份不完整的数据竞赛年鉴!
Node (II)
There is still a chance
[AAAI] attention based spatiotemporal graph convolution network for traffic flow prediction
Where are those test / development programmers in their 30s? a man should be independent at the age of thirty......
Correct posture and landing practice of R & D efficiency measurement (speech ppt sharing version)
什么是卡特兰数?有哪些应用?
2021年CS保研经历(六):系统填报 + 一些感想
This developer, who has been on the list for four consecutive weeks, has lived like a contemporary college student
Comprehensively design an oppe home page -- the bottom of the page
Are you familiar with the redis cluster principle of high paid programmers & interview questions series 122? How to ensure the high availability of redis (Part 2): cluster mechanism and principle, clu
On memory computing integrated chip technology
What is Cartland number? What are the applications?
Examples of specific usage of diagnostic instructions in s7-1200 and s7-1500 (led+devicestates+modulestates)