Jedis入门
一:介绍
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入门的更多相关文章
- linux系统下安装jdk,mysql,tomcat 和redis 和jedis入门案例
Day47笔记Linux+redis入门 Day47 知识讲解:Jedis 1.Linux上jdk,mysql,tomcat安装(看着文档安装) 准备工作: 因为JDK,TOMCAT,MYSQL的 ...
- jedis入门实例
在使用传统的关系数据库,我们都需要依赖一个所谓的实现了jdbc规范的驱动程序来连接数据库,这些驱动程序由各大数据库厂商提供.这些驱动就是jar包,里面就是封装了对数据库的通信协议,我们通过简单的调用就 ...
- jedis入门一
一.下载Jedis的依赖包jedis-2.1.0.jar,然后将其添加到classpath下面. 1. 定义连接:Redis暂时不要设置登录密码 Jedis jedis = new Jedis(&qu ...
- 峰Redis学习(2)Jedis 入门实例
参考博客:http://blog.java1234.com/blog/articles/314.html 第一节:使用Jedis 连接Redis 新建maven项目: pom.xml: <pro ...
- jedis入门教程
1 jedis介绍 2 java连接Redis 1 导入jar包 2 连接实例 @Test //获得单一的jedis对象操作数据库 public void test1(){ //1.获得连接对象 设置 ...
- Redis学习笔记(4)—— Jedis入门
一.Jedis介绍 Redis不仅是使用命令来操作,现在基本上主流的语言都有客户端支持,比如Java.C.C#.C++.php.Node.js.Go等. 在官方网站里列的一些Java客户端,有jedi ...
- Mac上的redis安装与jedis入门
Redis 是一个开源(BSD许可)的,内存中的数据结构存储系统,它可以用作数据库.缓存和消息中间件 安装与配置 (1) https://redis.io/download下载redis stable ...
- Redis安装部署、Jedis的使用
一.NoSQL概述 为什么需要NoSQL High performance -高并发读写 Huge Storage - 海量数据的高效率存储和访问 High Scalability && ...
- 【原】实战-Java如何使用Redis
实战-Java如何使用Redis Redis的Client支持的语言非常丰富,如下: ActionScript Bash C C# C++ Clojure Common Lisp Crystal D ...
随机推荐
- 八、IIC 接口
8.1 IIC接口介绍 8.1.1 IIC 总线的概念 I2C总线是由Philips公司开发的一种简单.双向二线制同步串行总线.它只需要两根线即可在连接于总线上的器件之间传送信息. 主器件用于启动总线 ...
- Elaticsearch 集群
elasticsearch开源的搜索引擎: ElasticSearch 个基于Lucene的搜索服务器:可以使用多节点的备份:集群设置: (类似是个数据库型.有索引有什么的).(lucene apa ...
- Window上,启动Tomcat服务之后,关闭启动窗口,服务器也随之关闭
在Window环境上,启动Tomcat服务器之后,随手关闭启动窗口,服务器也随之关闭了. 现在想要的效果是,当关闭启动窗口后,服务器仍然运行. 1. 开始:运行cmd,进入doc命令行 tomcat安 ...
- js 判断身份证好是否合法
function cidInfo(sId){ var info="" //if(!/^\d{17}(\d|x)$/i.test(sId))return false; sId=sId ...
- 第一次安卓android studio安装,常见问题。
出处:纸月 托了很久终于开始学习安卓了,之前看课本教程<第一行代码>用的是eclipse,但后来它不支持了就决定用android studio,第一次安装就出现了一些小的问题 第一个是关于 ...
- springMVC入门(一)
1. SpringMVC入门 1.1SpringMVC是什么 Spring web mvc和Struts2都属于表现层的框架,它是Spring框架的一部分,我们可以从Spring的整体结构中看得出 ...
- Java泛型方法与泛型类的使用------------(五)
泛型的本质就是将数据类型也参数化, 普通方法的输入参数的值是可以变的,但是类型(比如: String)是不能变的,它使得了在面对不同类型的输入参数的时候我们要重载方法才行. 泛型就是将这个数据类型也搞 ...
- sql 查询名字中有_的员工
select * from emp where ename like '%\_%' escape '\' ;\可以换作任意的字符 select * from emp where ename like ...
- DockerFile解析
⒈是什么? DockerFile是用来构建Docker镜像的构建文件,是由一系列命令和参数构成的脚本文件. ⒉步骤 ①手动编写一个符合规范的DockerFile文件(编写) ②使用docker bui ...
- ARMV8 datasheet学习笔记4:AArch64系统级体系结构之存储模型
1.前言 关于存储系统体系架构,可以概述如下: 存储系统体系结构的形式 VMSA 存储属性 2. 存储系统体系结构 2.1. 地址空间 指令地址空间溢出 指令地址计算((address_of ...