使用Leopard Redis

使用Leopard Redis
学习如何在使用Leopard Redis。
本指南将引导您使用Leopard Redis操作Redis。
How to complete this guide
你可以从头开始并完成每一个步骤,或者您可以绕过你已经熟悉的基本设置步骤。无论哪种方式,你最终都可以得到可工作的代码。
1、配置maven依赖
在dao模块的pom.xml加入
    <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、配置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" <span style='font-weight:bold;color:#ff0000'>xmlns:leopard="http://www.leopard.io/schema/leopard"</span>
	xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
	<span style='font-weight:bold;color:#ff0000'>http://www.leopard.io/schema/leopard http://www.leopard.io/schema/leopard.xsd</span>">

	<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、使用Redis接口
创建site-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;

@Repository
public class UserDaoRedisImpl {

	@Resource
	private Redis redis;

	public User get(long uid) {
		String key = "user:" + uid;
		String json = redis.get(key);
		return Json.toObject(json, User.class);
	}
}
总结
恭喜你!您已经可以在旧项目配置使用Leopard Redis,虽然功能比较简单,你可以在这个基础上扩展出你的业务系统,祝您好运。

猜你喜欢

转载自tanhaichao.iteye.com/blog/2183927
今日推荐