我这里是连接的阿里云服务器上的redis
1.阿里云服务器的安全组打开6379端口
2. 修改redis.config配置
注释掉 # bind 127.0.0.1
将 protected-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.140connect-timeout: 5000
测试
@AutowiredStringRedisTemplate stringRedisTemplate;@Testvoid contextLoads() {ValueOperations<String, String> operations = stringRedisTemplate.opsForValue();operations.set("hello","world");String hello = operations.get("hello");System.out.println(hello);}