开发环境:

---------- 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. 91云服务器网络带宽测试,IO测试、全国ping测试

    91yun服务器测试一键包介绍 一键包主要是为了让大家快速对服务器的基本状况有一个了解.考虑到天朝的网络出口问题,所以这个一键包更加偏向网络的测试. 影响测试耗时主要是下载,整个测试如果是能跑满100 ...

  2. 获取度量数据:创建服务账户获取访问token

    kubectl create clusterrolebinding kubelet-api-test --clusterrole=system:kubelet-api-admin --servicea ...

  3. MySQLroot密码的恢复方法

    MySQLroot密码的恢复方法 有可能你的系统没有 safe_MySQLd 程序(比如我现在用的 ubuntu操作系统, apt-get安装的MySQL) , 下面方法可以恢复 1.停止MySQLd ...

  4. 计算机二级-C语言-程序填空题-190115记录-fprintf()函数和fscanf()函数的使用。

    //给定程序,函数fun的功能是:将自然数1~10以及它们的平方根写到名为myflie3.txt的文本文件中,然后再顺序读出显示在屏幕上. //重难点:fprintf()函数和fscanf()函数的使 ...

  5. python两个_多个字典合并相加

    这只是符合比较正常的需求和场景. #一.适用合并两个字典(key不能相同否则会被覆盖),简单,好用. A = {'a': 11, 'b': 22} B = {'c': 48, 'd': 13} #up ...

  6. composer基本命令

    安装:https://getcomposer.org/download/ { "require":{ // "厂商/类库":"版本号", & ...

  7. Android Studio 使用入门及问题汇总

    声明:转载自http://blog.csdn.net/wei_chong_chong/article/details/56280383 之前一直用eclipse+adt做Android开发.曾经尝试使 ...

  8. Tomcat热部署与热加载!

    所谓的热部署与热加载就是两个值:(reloadable='true'与autoDeloy='true')

  9. Windows平台VC++ 6.0 下的网络编程学习 - 简单的测试winsock.h头文件

    最近学习数据结构和算法学得有点累了(貌似也没那么累...)...找了本网络编程翻了翻当做打一个小基础吧,打算一边继续学习数据结构一边也看看网络编程相关的... 简单的第一次尝试,就大致梳理一下看书+自 ...

  10. 浅谈Java三大特性之继承

    前言 简单用伪代码去介绍一些 父类与子类的构造函数问题 others 前言 类的继承性是面向对象语言的基本特性,多态性前提是继承性.Java 支持继承性和多态性.——Java从小白到大牛 继承:三大特 ...