Use Leopard Redis and leopardredis

Source: Internet
Author: User

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.