浏览代码

ipu-cache-example工程初始化

huangbo 5 年之前
父节点
当前提交
b22c4d21ef

+ 3 - 0
ipu-cache-example/.gitignore

1
/.settings/
2
/target/
3
/.classpath

+ 31 - 0
ipu-cache-example/pom.xml

1
<?xml version="1.0" encoding="UTF-8"?>
2
3
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4
	xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
5
	<modelVersion>4.0.0</modelVersion>
6
7
	<groupId>com.ai.ipu</groupId>
8
	<artifactId>ipu-cache-example</artifactId>
9
	<version>1.0</version>
10
11
	<properties>
12
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
13
        <ipu>3.1-SNAPSHOT</ipu>
14
        <jdk>1.8</jdk>
15
        <junit>4.12</junit>
16
    </properties>
17
18
	<dependencies>
19
		<dependency>
20
            <groupId>com.ai.ipu</groupId>
21
            <artifactId>ipu-cache</artifactId>
22
            <version>${ipu}</version>
23
        </dependency>
24
		<dependency>
25
			<groupId>junit</groupId>
26
			<artifactId>junit</artifactId>
27
			<version>${junit}</version>
28
			<scope>test</scope>
29
		</dependency>
30
	</dependencies>
31
</project>

+ 51 - 0
ipu-cache-example/src/test/java/com/ai/ipu/example/cache/CacheExample.java

1
package com.ai.ipu.example.cache;
2

3
import org.junit.Test;
4

5
import com.ai.ipu.basic.log.ILogger;
6
import com.ai.ipu.basic.log.IpuLoggerFactory;
7
import com.ai.ipu.cache.CacheFactory;
8
import com.ai.ipu.cache.ICache;
9

10
/**
11
 * @author huangbo@asiainfo.com
12
 * @team IPU
13
 * @date 2019年10月10日上午11:22:30
14
 * @desc 缓存使用范例
15
 */
16

17
public class CacheExample {
18
    private static final String REDIS_SINGLE_NO_AUTH = "single_no_auth";
19
    private static final String REDIS_SINGLE = "single";
20
    private static final String REDIS_CLUSTER = "cluster";
21

22
    /**
23
     * 单节点缓存存取,有鉴权
24
     */
25
    @Test
26
    public void testSetAndGet() throws Exception {
27
        ICache cache = CacheFactory.getCache(REDIS_SINGLE);
28
        cache.put("key", "value");
29
        System.out.println("key===" + cache.get("key"));
30
    }
31
    
32
    /**
33
     * 单节点缓存存取,无鉴权
34
     */
35
    @Test
36
    public void testSetAndGetWithNoAuth() throws Exception {
37
        ICache cache = CacheFactory.getCache(REDIS_SINGLE_NO_AUTH);
38
        cache.put("key", "value");
39
        System.out.println("key===" + cache.get("key"));
40
    }
41
    
42
    /**
43
     * 集群缓存存取
44
     */
45
    @Test
46
    public void testSetAndGetByCluster() throws Exception {
47
        ICache cache = CacheFactory.getCache(REDIS_CLUSTER);
48
        cache.put("key", "value");
49
        System.out.println("key===" + cache.get("key"));
50
    }
51
}

+ 29 - 0
ipu-cache-example/src/test/resources/ipu-cache.xml

1
<?xml version = '1.0' encoding = 'UTF-8'?>
2
<caches>
3
	<cache name="single_no_auth" type="redis">
4
		<servers>
5
	        <server ip="47.105.160.21" port="7021" />
6
	    </servers>
7
	</cache>
8
	<cache name="single" type="redis">
9
		<servers>
10
	        <server ip="47.105.160.21" port="7020" />
11
	    </servers>
12
	    <config name="auth" value="ipu"/>
13
	</cache>
14
	<cache name="cluster" type="redis">
15
		<servers>
16
	        <!-- 如果不是cluster,则只使用第一个redis -->
17
	        <server ip="47.105.160.21" port="7022" />
18
	        <server ip="47.105.160.21" port="7023" />
19
	        <server ip="47.105.160.21" port="7024" />
20
	        <server ip="47.105.160.21" port="7025" />
21
	        <server ip="47.105.160.21" port="7026" />
22
	        <server ip="47.105.160.21" port="7027" />
23
	    </servers>
24
		<!-- 客户端类型:Jedis,JedisCluster -->
25
	    <config name="clientType" value="JedisCluster"/>
26
	    <!-- 访问redis的密码 -->
27
	    <config name="auth" value="ipu"/>
28
	</cache>
29
</caches>