当前位置:网站首页>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");
}
}
边栏推荐
- Sublime Text3 set different indents for different files
- 汉源高科千兆2光6电导轨式网管型工业级以太网交换机支持X-Ring冗余环网一键环网交换机
- How to integrate Google APIs with Google's application system (3) -- call the restful service of Google discovery API
- [ts]Typescript学习记录坑点合集
- English语法_不定代词 - 常用短语
- Meituan senior technical expert: DDD's practice in the evolution of tourism e-commerce architecture
- Hanyuan high tech Gigabit 2-optical 6-conductor rail managed Industrial Ethernet switch supports X-ring redundant ring network one key ring network switch
- Several common design methods of test cases [easy to understand]
- JS temporary dead zone_ Temporary
- QoS quality of service five traffic shaping of QoS boundary behavior
猜你喜欢

English语法_不定代词 - 常用短语

一文读懂Plato Farm的ePLATO,以及其高溢价缘由

Behind 100000 visits...

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

Science fiction style, standard 6 airbags, popular · yachts from 119900

【AAAI】用于交通流预测的基于注意力的时空图卷积网络

Function - (C travel notes)

What kind of framework is friendly to developers?

Dynamics 365Online 如何自定义商机关闭窗体

Hanyuan high tech Gigabit 2-optical 6-conductor rail managed Industrial Ethernet switch supports X-ring redundant ring network one key ring network switch
随机推荐
TCP failure model
函数——(C游记)
"Focus on machines": Zhu Songchun's team built a two-way value alignment system between people and robots to solve major challenges in the field of human-computer cooperation
After the thunderstorm of two encryption companies: Celsius repayment guarantee collateral, three arrow capital closed and disappeared
Selenium series 5-xpath path expression
Dimensionality reduction and mathematical modeling after reading blog!
Method of cocos2d-x sprite moving
This is an incomplete data competition Yearbook!
[FPGA tutorial case 19] factorial operation through multiplier
Solve problems intelligently
函数和数组
Modulenotfounderror: no module named 'pywt' solution
Orbslam2 installation test and summary of various problems
熊市下PLATO如何通过Elephant Swap,获得溢价收益?
mysql 数据库 期末复习题库
英特尔联合Datawhale,发布学习项目!
Pytest+allure generate test report
The latest translated official pytorch easy introduction tutorial (pytorch version 1.0)
综合设计一个OPPE主页--页面的底部
There is still a chance