一:介绍

1.Jedis的官网

  

  

2.使用

  这个可以从上面的连接进入github。

  https://github.com/xetorthio/jedis

3.使用方式

  或者使用jar包,不过这里我使用官网推荐的maven管理方式。

  

二:验证是否可以连接主机

1..先写一个小程序测试一下

 package top.it;

 import org.junit.Test;
import redis.clients.jedis.Jedis; public class JedisDemo1 {
@Test
public void test(){
//设置ip与端口
Jedis jedis=new Jedis("192.168.140.121",6379);
jedis.set("age","18");
String age=jedis.get("age");
System.out.println("age="+age);
jedis.close();
}
}

2.程序报错

  

3.cmd下

  telnet 192.168.140.121 6379

  

4.解决方式

  在配置文件中注释。

  

5.又出现的下一个问题

  redis.clients.jedis.exceptions.JedisDataException: DENIED Redis is running in protected mode because protected mode is enabled, no bind address was specified, no authentication password is requested to clients. In this mode connections are only accepted from the loopback interface. If you want to connect from external computers to Redis you may adopt one of the following solutions: 1) Just disable protected mode sending the command 'CONFIG SET protected-mode no' from the loopback interface by connecting to Redis from the same host the server is running, however MAKE SURE Redis is not publicly accessible from internet if you do so. Use CONFIG REWRITE to make this change permanent. 2) Alternatively you can just disable the protected mode by editing the Redis configuration file, and setting the protected mode option to 'no', and then restarting the server. 3) If you started the server manually just for testing, restart it with the '--protected-mode no' option. 4) Setup a bind address or an authentication password. NOTE: You only need to do one of the above things in order for the server to start accepting connections from the outside.

  

6.解决方式

  

7.效果

  

三:验证项目

1.pom文件

 <?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion> <groupId>top.redis.it</groupId>
<artifactId>redisTest</artifactId>
<version>1.0-SNAPSHOT</version> <dependencies>
<dependency>
<groupId>redis.clients</groupId>
<artifactId>jedis</artifactId>
<version>2.9.0</version>
<type>jar</type>
<scope>compile</scope>
</dependency>
</dependencies> </project>

2.出现了2个jar

  

3.程序一

 package top.it;

 import org.junit.Test;
import redis.clients.jedis.Jedis; public class JedisDemo1 {
@Test
public void test(){
//设置ip与端口
Jedis jedis=new Jedis("192.168.140.121",6379);
jedis.set("age","18");
String age=jedis.get("age");
System.out.println("age="+age);
jedis.close();
}
}

4.程序二----连接池

     @Test
public void test2(){
//设置ip与端口
JedisPoolConfig jedisPoolConfig=new JedisPoolConfig();
jedisPoolConfig.setMaxTotal(30);
jedisPoolConfig.setMaxIdle(10);
JedisPool jedisPool=new JedisPool(jedisPoolConfig,"192.168.140.121",6379);
Jedis jedis=null;
try {
jedis=jedisPool.getResource();
jedis.set("address","Beijing");
System.out.println("address:"+jedis.get("address"));
}catch (Exception e){
e.printStackTrace();
}finally {
if (jedis!=null){
jedis.close();
}
if (jedisPool!=null){
jedisPool.close();
}
} }

5.效果

  

  

Jedis入门的更多相关文章

  1. linux系统下安装jdk,mysql,tomcat 和redis 和jedis入门案例

    Day47笔记Linux+redis入门 Day47   知识讲解:Jedis 1.Linux上jdk,mysql,tomcat安装(看着文档安装) 准备工作: 因为JDK,TOMCAT,MYSQL的 ...

  2. jedis入门实例

    在使用传统的关系数据库,我们都需要依赖一个所谓的实现了jdbc规范的驱动程序来连接数据库,这些驱动程序由各大数据库厂商提供.这些驱动就是jar包,里面就是封装了对数据库的通信协议,我们通过简单的调用就 ...

  3. jedis入门一

    一.下载Jedis的依赖包jedis-2.1.0.jar,然后将其添加到classpath下面. 1. 定义连接:Redis暂时不要设置登录密码 Jedis jedis = new Jedis(&qu ...

  4. 峰Redis学习(2)Jedis 入门实例

    参考博客:http://blog.java1234.com/blog/articles/314.html 第一节:使用Jedis 连接Redis 新建maven项目: pom.xml: <pro ...

  5. jedis入门教程

    1 jedis介绍 2 java连接Redis 1 导入jar包 2 连接实例 @Test //获得单一的jedis对象操作数据库 public void test1(){ //1.获得连接对象 设置 ...

  6. Redis学习笔记(4)—— Jedis入门

    一.Jedis介绍 Redis不仅是使用命令来操作,现在基本上主流的语言都有客户端支持,比如Java.C.C#.C++.php.Node.js.Go等. 在官方网站里列的一些Java客户端,有jedi ...

  7. Mac上的redis安装与jedis入门

    Redis 是一个开源(BSD许可)的,内存中的数据结构存储系统,它可以用作数据库.缓存和消息中间件 安装与配置 (1) https://redis.io/download下载redis stable ...

  8. Redis安装部署、Jedis的使用

    一.NoSQL概述 为什么需要NoSQL High performance -高并发读写 Huge Storage - 海量数据的高效率存储和访问 High Scalability && ...

  9. 【原】实战-Java如何使用Redis

    实战-Java如何使用Redis Redis的Client支持的语言非常丰富,如下: ActionScript Bash C C# C++ Clojure Common Lisp Crystal D ...

随机推荐

  1. js设置div透明度

    原生js设置透明度 为了兼容IE与其他浏览器对透明度的设置,我们需要对以上两种样式分别进行设置: 复制代码代码如下: var alpha = 30; //透明度值变量 var oDiv = docum ...

  2. 第5月第6天 NSOperation isConcurrent category同名覆盖

    1. @implementation AFURLConnectionOperation ... - (BOOL)isConcurrent { return YES; } NSOperation调用st ...

  3. linux space/mark设置

    参考链接: http://blog.csdn.net/zhaozh2000/article/details/6460223 串口数据的发送: 数据的发送: 数据位+检验位+停止位, 进行数据的发送.( ...

  4. mysql 案例 ~ pt-archiver 归档工具的使用

    一 简介:今天咱们来聊聊pt-archiver的使用 二 相关参数 相关参数1   --statistics 结束的时候给出统计信息:开始的时间点,结束的时间点,查询的行数,归档的行数,删除的行数,以 ...

  5. Python 入门基础20 --面向对象_继承、组合

    今日内容 组合:自定义类的对象作为类的属性 继承:父类与子类.多继承 1.组合 将自定义类的对象作为类的属性 class Teacher: def __init__(self, name): self ...

  6. SpringBoot集成SpringCloud

    (1).新建一个普通Maven项目,用于存放一些公共服务接口及公共的Bean等. 项目结构: 公共Bean: package cn.coreqi.entities; import java.io.Se ...

  7. Cython的简单使用

    Cython是一个快速生成Python扩展模块的工具,从语法层面上来讲是Python语法和C语言语法的混血,当Python性能遇到瓶颈时,Cython直接将C的原生速度植入Python程序,这样使Py ...

  8. freeRTOS中文实用教程4--资源管理互斥

    1.前言 访问一个被多任务共享,或是被任务与中断共享的资源时,需要采用”互斥”技术以保证数据在任何时候都保持一致性.这样做的目的是要确保任务从开始访问资源就具有排它性,直至这个资源又恢复到完整状态 F ...

  9. AWTK(Toolkit AnyWhere): 为嵌入式、手机和桌面开发的通用GUI【转】

    转自:https://blog.csdn.net/absurd/article/details/80958279 AWTK = Toolkit AnyWhere AWTK是吸取了FTK和CanTK的精 ...

  10. 关于MySQL 8.0的几个重点【转】

    转自 关于MySQL .0的几个重点,都在这里 https://mp.weixin.qq.com/s/QUpk9uuS2JTli1GT6HuORA 一.关于MySQL Server的改进 1.1 re ...