SpringBoot远程访问redis配置,config文件,防火墙,阿里云安全组等

我这里是连接的阿里云服务器上的redis

1.阿里云服务器的安全组打开6379端口

2. 修改redis.config配置

注释掉 # bind 127.0.0.1protected-mode yes 改为:protected-mode no

3. 防火墙配置开启6379端口访问

在linux中执行: /sbin/iptables -I INPUT -p tcp --dport 6379 -j ACCEPT
redis默认端口号6379是不允许进行远程连接的,在防火墙中设置6379开启远程服务;

4. 重启redis

./src/redis-server redis.config

5.SpringBoot测试

pom

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-redis</artifactId>
        </dependency>

丫妹

  redis:
    host: 39.105.161.140
    connect-timeout: 5000

测试

    @Autowired
    StringRedisTemplate stringRedisTemplate;

    @Test
    void contextLoads() {
        ValueOperations<String, String> operations = stringRedisTemplate.opsForValue();
        operations.set("hello","world");
        String hello = operations.get("hello");
        System.out.println(hello);
    }
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值