Use Leopard Redis and leopardredis
Use Leopard Redis to learn how to use Leopard Redis.
This guide will guide you through using Leopard Redis to operate Redis.
How to complete this guide
You can start from scratch and complete each step, or you can bypass the basic setup steps you are already familiar. Either way, you can finally get the code that can work.
1. Configure maven dependency
Add pom. xml in dao Module
<dependencies> [...] <dependency> <groupId>io.leopard</groupId> <artifactId>leopard-data</artifactId> <version>0.0.1-SNAPSHOT</version> </dependency> [...] </dependencies> <repositories> <repository> <id>leopard-snapshots</id> <name>Leopard Snapshots</name> <url>http://leopard.io/nexus/content/repositories/snapshots/</url> </repository> </repositories>
2. Configure spring
site-dao/src/main/resources/applicationContext-dao.xml
<?xml version="1.0" encoding="UTF-8"?><beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:leopard="http://www.leopard.io/schema/leopard"xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsdhttp://www.leopard.io/schema/leopard http://www.leopard.io/schema/leopard.xsd"><leopard:component-scan base-package="io.leopard.site" /><leopard:jdbc id="jdbc" host="112.126.75.27" database="example" user="example" password="leopard" /><leopard:redis id="redis" server="112.126.75.27:6311" /></beans>
3. Use the Redis Interface
Createsite-dao/src/main/java/io/leopard/site/dao/redis/UserDaoRedisImpl.java
package io.leopard.site.dao.redis;import io.leopard.burrow.lang.Json;import io.leopard.data4j.redis.Redis;import io.leopard.site.model.User;import javax.annotation.Resource;import org.springframework.stereotype.Repository;@Repositorypublic class UserDaoRedisImpl {@Resourceprivate Redis redis;public User get(long uid) {String key = "user:" + uid;String json = redis.get(key);return Json.toObject(json, User.class);}}Summary
Congratulations! You can use Leopard Redis in the old project configuration. Although the function is relatively simple, you can expand your business system on this basis. Good luck.