package com.tp.soft.redis;import javax.annotation.Resource;import org.springframework.beans.factory.annotation.Autowired;import org.springframework.data.redis.connection.jedis.JedisConnectionFactory;public class RedisCacheTransfer { @Autowired public void setJedisConnectionFactory(JedisConnectionFactory jedisConnectionFactory) { RedisCacheAn.setJedisConnectionFactory(jedisConnectionFactory); }}
spring-redis注入
二级缓存引入类
package com.tp.soft.redis;import java.util.concurrent.locks.ReadWriteLock;import java.util.concurrent.locks.ReentrantReadWriteLock;import org.apache.ibatis.cache.Cache;import org.springframework.beans.factory.annotation.Autowired;import org.springframework.data.redis.connection.jedis.JedisConnection;import org.springframework.data.redis.connection.jedis.JedisConnectionFactory;import org.springframework.data.redis.serializer.JdkSerializationRedisSerializer;import org.springframework.data.redis.serializer.RedisSerializer;/* * 使用第三方缓存服务器,处理二级缓存 */public class RedisCacheAn implements Cache { private final ReadWriteLock readWriteLock = new ReentrantReadWriteLock(); private String id; private static JedisConnectionFactory jedisConnectionFactory; public RedisCacheAn(final String id) { if (id == null) { throw new IllegalArgumentException("Cache instances require an ID"); } this.id = id; } public String getId() { return this.id; } public void putObject(Object key, Object value) { JedisConnection conn = null; try{ conn = jedisConnectionFactory.getConnection(); RedisSerializer