Redis测试Java接口

创建Java测试类

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
package cn.xieth;

import org.junit.Test;

import redis.clients.jedis.Jedis;

public class TestRedis {

@Test
public void testRedis() {

Jedis jedis = new Jedis("192.168.200.128", 6379);
Long pno = jedis.incr("pno");
System.out.println(pno);
jedis.close();

}

}

Spring管理Redis

redis.xml

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:mvc="http://www.springframework.org/schema/mvc"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:task="http://www.springframework.org/schema/task"
xmlns:dubbo="http://code.alibabatech.com/schema/dubbo"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-4.0.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc-4.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-4.0.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-4.0.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-4.0.xsd
http://www.springframework.org/schema/task
http://www.springframework.org/schema/task/spring-task-4.0.xsd
http://code.alibabatech.com/schema/dubbo
http://code.alibabatech.com/schema/dubbo/dubbo.xsd">

<!-- Redis -->
<bean id="jedis" class="redis.clients.jedis.Jedis">
<constructor-arg value="192.168.200.128" index="0" type="java.lang.String"/>
<constructor-arg value="6379" index="1" />
</bean>

</beans>

使用Spring管理后

image