1. Maven依赖
注:spring-data-redis版本要大于1.7
junit junit 4.12 test org.springframework spring-test 4.3.4.RELEASE test org.springframework spring-context 4.3.4.RELEASE org.springframework.data spring-data-redis 1.7.5.RELEASE redis.clients jedis 2.8.2
2.Spring配置文件
3.Java调用
import org.junit.Assert;import org.junit.Test;import org.junit.runner.RunWith;import org.springframework.beans.factory.annotation.Autowired;import org.springframework.data.redis.core.RedisTemplate;import org.springframework.test.context.ContextConfiguration;import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;@RunWith(SpringJUnit4ClassRunner.class)@ContextConfiguration("classpath:ApplicationContext.xml")public class RedisTest { @Autowired private RedisTemplateredisTemplate; @Test public void testSetValue() { redisTemplate.opsForValue().set("test1", "hello"); Assert.assertEquals("hello", redisTemplate.opsForValue().get("test1")); }}