我们要使用Java来操作Redis
什么是jedis, jedis是redis官方推荐的Java连接开发工具!使用Java操作redis的中间件,如果你要使用Java操作redis,那么一定要对jedis十分熟悉!
创建一个空项目:
导入对应的jar包:(maven依赖)
<?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>com.zyq</groupId> <artifactId>redis-01-jedis</artifactId> <version>1.0-SNAPSHOT</version> <!--导入jedis的包--> <dependencies> <dependency> <groupId>redis.clients</groupId> <artifactId>jedis</artifactId> <version>3.2.0</version> </dependency> <!--fastjson包--> <!-- https://mvnrepository.com/artifact/com.alibaba/fastjson --> <dependency> <groupId>com.alibaba</groupId> <artifactId>fastjson</artifactId> <version>1.2.73</version> </dependency>
</dependencies> </project>
|
编写测试类查看是否连接成功