开发环境:

---------- 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的更多相关文章

  1. 远程连接Linux上的MongoDB服务

    1.Linux环境上安装好MongoDB,并配置好环境变量 2.启动MongoDB 注:mongod /opt/michael/mongodb/mongodb-linux-x86_64-4.0.5/d ...

  2. RedisDesktopManager远程连接Linux系统的Redis服务

    linux下安装redis :https://www.runoob.com/redis/redis-install.html 进入 src 运行redis   : ./redis-server 打开另 ...

  3. Java中Jedis连接Linux上的Redis出现connect time out(解决方案)

    我的代码: /** * * <p>Title: testJedis</p> * <p>Description: 测试单机版的redis连接(每连接一次构建一个对象) ...

  4. 关于Jedis连接Linux上的redis出现 DENIED Redis is running in protected mode问题的解决方案

    redis 添加了requirepass 123456后还是报错,原来是重新启动的时候./redis-cli  没有指定配置文件. https://blog.csdn.net/a532672728/a ...

  5. 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 ...

  6. java连接CentOS7上的redis

    这篇博客写得挺全的: https://blog.csdn.net/achenyuan/article/details/78521831?locationNum=3&fps=1 我也是跟着这篇博 ...

  7. 解决redis远程连接不上的问题

    解决redis远程连接不上的问题 redis现在的版本开启redis-server后,redis-cli只能访问到127.0.0.1,因为在配置文件中固定了ip,因此需要修改redis.conf(有的 ...

  8. Linux(1)- 服务器核心知识、Linux入门、VMware与centeos安装、远程连接linux、linux基本命令使用

    一.服务器核心知识 1.电脑和电脑的硬件组成 现在的人们几乎无时无刻不在使用着电脑!不管是桌上型电脑(桌机).笔记型电脑(笔电).平板电脑,还是智慧型手机等等,这些东西都算是电脑.虽然接触这么多,但是 ...

  9. Windows远程连接Linux

    目录 xrdp方式 vnc方式 xrdp方式 ----------------------------------------------------------------------------- ...

随机推荐

  1. December 31st, Week 53rd Tuesday, 2019

    Nothing comes from nothing. 天下没有免费的午餐. Nothing comes from nothing, and in some cases, even something ...

  2. UITextField的内存泄漏问题

    背景: 项目中使用了Facebook的FBRetainCycleDetector框架检测内存泄漏问题. 登录VC的view中放置了一个UITextField对象. 产品的要求是当进入登录界面的时候,让 ...

  3. 安卓基础(AndroidViewModel)

    今天学习了AndroidViewModel,但是我根据视频上讲解,根据所讲用例,在添加依赖得时候一直报错,后来我请教大佬,他告诉我说是,因为网络得问题,国外得一些依赖有可能下不下来,所以可以下载阿里云 ...

  4. Vue——项目中接口返回值为函数回调,回调函数定义方法(Vue的方法给原生调用)

    在接口调用中,有时会返回给我们一个函数回调,来自动执行我们在前端定义好的某个函数(多出现于通过回调的方式传递某个数值).在原生项目中,我们只要提供一下这个方法就好了,通过函数回调会自动执行.问题就出现 ...

  5. 基于SILVACO ATLAS的a-IGZO薄膜晶体管二维器件仿真(03)

    今天逛ResearchGate的时候发现了一个不错的Atlas入门教程:Step by step with ATLAS Silvaco点击链接免费下载.. Atlas代码结构 当然可能有一点太基础了. ...

  6. 强化学习-Q-learning学习笔记

    Q学习动作探索策略中的ep-greepy,以ep的概率进行随机探索,以1-ep的概率以最大值策略进行开发,因为设定的迭代次数比较多,所以肯定存在一定的次数去搜索不同的动作. 1)Python版本 b站 ...

  7. 探索 Python + HyperLPR 进行车牌识别

    概要 HyperLRP是一个开源的.基于深度学习高性能中文车牌识别库,由北京智云视图科技有限公司开发,支持PHP.C/C++.Python语言,Windows/Mac/Linux/Android/IO ...

  8. 【代码审计】VAuditDemo 重装漏洞

    一.源码安装漏洞介绍 一般在PHP源码程序都有一个初始安装的功能,如果相关代码没有对参数进行严格过滤,可能会导致攻击者访问安装页面(install.php)或构造数据包,对网站进行重新安装,从而危害网 ...

  9. 【代码总结】PHP面向对象之接口与多态性应用

    概述: PHP之支持单继承,也就是说每个类智能继承一个父类.当声明的新类继承抽象类实现模板以后就不能再有其他问题,为了解决这个问题,PHP引用了接口 ------------------------- ...

  10. Codeforces Round #620 (Div. 2) B. Longest Palindrome

    Returning back to problem solving, Gildong is now studying about palindromes. He learned that a pali ...