[经验] SpringBoot 远程连接 Linux 上的 Redis
开发环境:
---------- springboot 2.X
---------- Linux Ubuntu 18.0.04
关于怎么在 Ubuntu 上安装 Linux , 网上的教程一大堆, 这里就不水了, 只要是能像下面那样玩, 那就说明 Ubuntu 上的 redis 安装成功了

(一) Java 服务器部分的开发
1. 在 springboot 的配置文件里配置 redis 连接相关的配置:
在 pom.xml 中添加 redis 依赖
<!-- redis -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-redis</artifactId>
</dependency>
在 application.perporties 里添加配置属性
################## redis 缓存配置 ##################
# Redis数据库索引
spring.redis.database=0
# Redis服务器地址
spring.redis.host= 虚拟机的IP地址
# Redis服务器连接端口
spring.redis.port=6379
# Redis服务器连接密码
spring.redis.password= redis的连接密码
# 连接池最大连接数
spring.redis.jedis.pool.max-active=8
# 连接池最大阻塞等待时间
spring.redis.jedis.pool.max-wait=-1
# 连接池中的最大空闲连接
spring.redis.jedis.pool.max-idle=8
# 连接池中的最小空闲连接
spring.redis.jedis.pool.min-idle=0
# 连接超时时间(毫秒)
spring.redis.timeout=100
2. 添加一个 redis 连接对象
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Component; /*
*@Description //TODO 远程访问redis服务器测试类$
*@Author 吾王剑锋所指 吾等心之所向
*@Date 2019/9/7 10:39
*/
@Component
public class RedisClientTest {
private StringRedisTemplate template; @Autowired
public RedisClientTest(StringRedisTemplate template) {
this.template = template;
} public StringRedisTemplate getTemplate() {
return template;
}
}
3. 找到 springboot 里的测试类,,,,,,话说这个测试类我之前都不怎么使用, 都是自己写测试用例...........................
import cn.gzserver.cache.RedisClientTest;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.test.context.junit4.SpringRunner; /**
* 服务器测试类
* @author avicii
* @date 2019-09-07
* */
@RunWith(SpringRunner.class)
@SpringBootTest
public class ApplicationTests { @Autowired
private RedisClientTest redisCli; @Test
public void contextLoads() {
StringRedisTemplate redis = redisCli.getTemplate();
redis.opsForValue().set("name", "Jack");
String firstName = redis.opsForValue().get("name");
System.out.println(firstName);
redis.opsForValue().set("name", "Rose");
String secondName = redis.opsForValue().get("name");
System.out.println(secondName);
} }
然后启动
如果不出意外的话, 你就会得到这样的一个错误
org.springframework.data.redis.RedisConnectionFailureException:
Unable to connect to Redis;
nested exception is io.lettuce.core.RedisConnectionException:
Unable to connect to 192.168.***.***:6379
但是去检查 Ubuntu 的接口开放情况, 又会发现

6379 这个端口是正常开放的, 那问题的原因出在哪呢
emmmm.....等下再回来补上,,,,我先去试试我的想法 ~逃)
[经验] SpringBoot 远程连接 Linux 上的 Redis的更多相关文章
- 远程连接Linux上的MongoDB服务
1.Linux环境上安装好MongoDB,并配置好环境变量 2.启动MongoDB 注:mongod /opt/michael/mongodb/mongodb-linux-x86_64-4.0.5/d ...
- RedisDesktopManager远程连接Linux系统的Redis服务
linux下安装redis :https://www.runoob.com/redis/redis-install.html 进入 src 运行redis : ./redis-server 打开另 ...
- Java中Jedis连接Linux上的Redis出现connect time out(解决方案)
我的代码: /** * * <p>Title: testJedis</p> * <p>Description: 测试单机版的redis连接(每连接一次构建一个对象) ...
- 关于Jedis连接Linux上的redis出现 DENIED Redis is running in protected mode问题的解决方案
redis 添加了requirepass 123456后还是报错,原来是重新启动的时候./redis-cli 没有指定配置文件. https://blog.csdn.net/a532672728/a ...
- IDEA通过Jedis操作Linux上的Redis;Failed to connect to any host resolved for DNS name问题
testPing.java public class testPing { public static void main(String[] args) { Jedis jedis = new Jed ...
- java连接CentOS7上的redis
这篇博客写得挺全的: https://blog.csdn.net/achenyuan/article/details/78521831?locationNum=3&fps=1 我也是跟着这篇博 ...
- 解决redis远程连接不上的问题
解决redis远程连接不上的问题 redis现在的版本开启redis-server后,redis-cli只能访问到127.0.0.1,因为在配置文件中固定了ip,因此需要修改redis.conf(有的 ...
- Linux(1)- 服务器核心知识、Linux入门、VMware与centeos安装、远程连接linux、linux基本命令使用
一.服务器核心知识 1.电脑和电脑的硬件组成 现在的人们几乎无时无刻不在使用着电脑!不管是桌上型电脑(桌机).笔记型电脑(笔电).平板电脑,还是智慧型手机等等,这些东西都算是电脑.虽然接触这么多,但是 ...
- Windows远程连接Linux
目录 xrdp方式 vnc方式 xrdp方式 ----------------------------------------------------------------------------- ...
随机推荐
- window下载并且安装kafka
安装zookeeper kafka运行需要有jdk+zookeeper环境才能够使用,jdk的安装和环境变量的配置就不介绍了,这里需要先安装zookeeper.可以从官网上下载 https://www ...
- js把树形数据转成扁平数据
我就直接上代码了都是实际项目里面用到的 1.假设这个json就已经是树型结构数据了(如果不知道怎么实现树型结构数据请看我另一篇博客) var compressedArr=afcommon.treeDa ...
- 传奇脚本:#AutoRun NPC SEC 参数说明
传奇脚本:#AutoRun NPC SEC 参数说明 SEC:按秒运行MIN:按分运行HOUR:按小时运行DAY:按天运行RunOnDay:按每天什么时候运行RUNONWEEK:按星期几及时间运行机器 ...
- next_permutation的使用-Hdu1027
Ignatius and the Princess II Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K ( ...
- 兵贵神速!掌握这10个Python技巧,让你代码工作如鱼得水
主题 Python 1000个读者心中有1000个哈姆雷特,要问1000个程序员“什么才是最好的语言”,Java.Python.PHP.C++ 也都有自己的位置.但要问编程语言流行指数之王非,那真的非 ...
- 嵌入式大赛PPT
题目:基于SLAM的移动机器人设计 嵌入式PPT应具有的几个部分 1.有哪些硬件 1)小车 2)STM32F429开发板 3)树莓派3b+开发板 4)4g通信模块 5)GPS模块 6)Kinect摄像 ...
- 20141110的alltosun面试
今天周一,是校招的第一天,心情有点紧张,不过可以和很多同学一起去,是我紧张的心情变得稍微安静些.面试进行的时候,是学长2哥面的我,总体感觉自己的表现很糟糕,在公共场合发表言论或者演讲,一直是我的一个弱 ...
- java 事务解释。
面试的时候,面试人员总喜欢问在spring中, 1. 如果一个主线程上有一个事务,在事务中开启了一个线程.子线程跑出异常,对主线程有没有影响,或者主线程产生异常对子线程有没有影响. 这个时候,你只要记 ...
- idea 导入svn中java WEB项目
1.打开idea 2.填写svn路径 3.指定本地路径 4.选择1.8 format 5.添加jdk 6.配置tomcat启动项目 File -- Project Structure
- python3.8的PySimpleGUI学习的温度转换(℃转℉)
一.代码1: #导出模块 import PySimpleGUI as sg #总体布局,sg.InputText(),默认size=(45,1). layout = [ [sg.Text('Celci ...