Redis系列七:Java客户端Jedis的入门

Redis系列七:Java客户端Jedis的入门 在Redis官网中提供了各种语言的客户端地址https://redis.io/docs/clients/在maven项目中导入依赖在test中使用测试代码package com.itheima; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import redis.clients.jedis.Jedis; public class JedisTest { private Jedis jedis; BeforeEach public void init() { // 创建jedis对象 jedis new Jedis(192.168.80.134, 6379); // 设置密码 jedis.auth(123321); // 选择数据库 jedis.select(0); } Test public void testString() { // 添加数据 String result jedis.set(username, 安检机); System.out.println(result); // 获取数据 String username jedis.get(username); System.out.println(username); } AfterEach public void destroy() { if (jedis ! null) { jedis.close(); } } }执行一下这里出现了异常为什么呢以后每次出现异常我都会教大家读一下java.lang.NoSuchMethodError是一个非常容易出现的问题版本不一致特别是大家快速创建maven工程的时候最容易出现我这里就是忽略了系统自带的junit版本不一致。我们修改一下project xmlnshttp://maven.apache.org/POM/4.0.0 xmlns:xsihttp://www.w3.org/2001/XMLSchema-instance xsi:schemaLocationhttp://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd modelVersion4.0.0/modelVersion groupIdcom.itheima/groupId artifactIduntitled/artifactId version1.0-SNAPSHOT/version packagingjar/packaging nameuntitled/name urlhttp://maven.apache.org/url properties project.build.sourceEncodingUTF-8/project.build.sourceEncoding /properties dependencies dependency groupIdorg.junit.jupiter/groupId artifactIdjunit-jupiter/artifactId version5.9.3/version !-- 使用具体稳定版本 -- scopetest/scope /dependency dependency groupIdredis.clients/groupId artifactIdjedis/artifactId version3.7.0/version /dependency /dependencies /project这次再执行结果便出来了。