[经验] 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方式 ----------------------------------------------------------------------------- ...
 
随机推荐
- 结构体数组排序:1004 成绩排名 【pta】
			
结构体模板 struct STU { string name; //用string可以代替char string num; int s; }; sort是用快速排序实现的,属于不稳定排序,stable ...
 - 微信支付之H5支付
			
HoJe男孩子你要加油阿 前言准备材料H5支付请求的参数返回结果统一下单回调接口用到的工具类886 . 前言 大家好,分享是快乐的,也见证了个人成长历程,文章大多都是工作经验总结以及平时学习积累,基于 ...
 - source insight 编译后出现停止工作解决方法
			
解决方法: 工程的路径不要有中文,都用英文
 - acwing练习
			
220. 最大公约数 给定整数N,求1<=x,y<=N且GCD(x,y)为素数的数对(x,y)有多少对. GCD(x,y)即求x,y的最大公约数. 输入格式 输入一个整数N 输出格式 输出 ...
 - Mac 配置 React Native 环境
			
OSX系统,这里假定你是iOS开发人员 Homebrew 是需要的,只有安装了Homebrew才能继续安装watchman和flow 安装 Node.js 4.0 或者更新的版本. 使用 Homebr ...
 - HDFS的常用命令
			
一.常用命令 二.其他命令
 - 初探three.js几何体-Geometry
			
three.js几何体我们还没有说完,这一节我们说一说THREE.Geometry(),简单几何体都是继承了这个对象,使用它会相对麻烦一些,但是可操作性非常高,今天我们使用它制作一个自定义几何体-五角 ...
 - web渗透(转)
			
某天比较无聊,听一个朋友推荐httpscan这款工具,于是就下载下来试试. 首先对某学校网段开始进行测试. 1 python httpscan.py **.**.**.0/24 测试时发现有个比较 ...
 - sqlmap注入随笔记录
			
web7: 首先看见这道题,猜测flag在某页id上面,或者id是可以注入的. 先就是id爆破,用burpsuite抓了包,做了个0~9999的字典爆破id,发现自己猜测错了 那么就还是sql注入题了 ...
 - P1893山峰瞭望
			
传送门 看完这个题,大家都懂意思吧,然后代码呢,emmmmm #include <bits/stdc++.h> using namespace std; const int maxn = ...