开发环境:

---------- 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. Windows 下 Hbuilder 真机调试(Android,iphone)

    概述:主要讲讲自己在使用 HBuilder 真机调试功能时遇到的问题,以及如何解决.Android 相对没有遇到什么大问题,在电脑安装如360手机助手就可以正常使用了,主要问题是在 iphone 上( ...

  2. centos7下Maven Java selenium3环境搭建

    centos7下Maven Java selenium3环境搭建 一.Jdk安装 我这里用的是open-jdk. [adawang@localhost src]$ sudo yum search op ...

  3. python 中对list去重

    本文去重的前提是要保证顺序不变,本文给出了多种实现方法,需要的朋友可以参考下 1.直观方法 最简单的思路就是: ids = [1,2,3,3,4,2,3,4,5,6,1] news_ids = [] ...

  4. Python - 运行流程图, call graph, 调用图

    解决方案 pycallgraph(感觉直接用pycallgraph grahviz命令生成的图并不是我想要的) 如何去阅读并学习一些优秀的开源框架的源码? - mailto1587的回答 - 知乎 h ...

  5. win10安装 .net3.5失败解决方法

    #开始 最近需要学习Sql Server 但是发现SQL Server2008r2 版本的安装程序基于.net 电脑没有安装.net3.5 #解决过程 可笑的是我在用离线安装包安装.net3.5的时候 ...

  6. 图片识别OCR:

    使用Python制作一个简易的OCR图片文字识别工具:键盘上的PrtScr按键+画图工具+百度AI图片识别(账户,调用接口)+python 常见的OCR工具: 1. Microsoft Onenote ...

  7. POJ 1274 The Perfect Stall(二分图 && 匈牙利 && 最小点覆盖)

    嗯... 题目链接:http://poj.org/problem?id=1274 一道很经典的匈牙利算法的题目: 将每只奶牛看成二分图中左边的点,将牛圈看成二分图中右边的点,如果奶牛看上某个牛圈,就将 ...

  8. C语言-实现矩阵的转置-随机函数产生随机数并赋予数组中-190222

    //编写程序,实现矩阵的转置(行列互换). #include <stdio.h> #include <conio.h> #include <stdlib.h> ][ ...

  9. mysql 单表批量备份sh文件

    #!/bin/bashDBS=$(mysql -u root -padmin -e 'use database; show tables;' | awk '{ print $1 }');for tab ...

  10. 喵星之旅-狂奔的兔子-redis安装

    一.前置条件 服务器版本CentOS-8-x86_64-1905-dvd1,在此版本上安装最新版redis.centos7以上版本都可以,不建议6以前的版本. 二.下载redis,并上传到服务器 登录 ...