如何使用spring数据(redis)将RedisTemplate注入到XXOperations(HashOperations等)中
我正在使用Spring Data Redis,但官方文档让我感到困惑:如何使用spring数据(redis)将RedisTemplate注入到XXOperations(HashOperations等)中,spring,inject,jedis,spring-data-redis,Spring,Inject,Jedis,Spring Data Redis,我正在使用Spring Data Redis,但官方文档让我感到困惑: <!-- redis template definition --> <bean id="redisTemplate" class="org.springframework.data.redis.core.RedisTemplate" p:connection-factory-ref="jedisConnectionFactory"/> 但是Redi
<!-- redis template definition -->
<bean id="redisTemplate"
class="org.springframework.data.redis.core.RedisTemplate"
p:connection-factory-ref="jedisConnectionFactory"/>
但是RedisTemplate没有扩展ListOperations:
- public class RedisTemplate<K, V> extends RedisAccessor implements RedisOperations<K, V>, BeanClassLoaderAware
- public class RedisAccessor implements InitializingBean
-公共类RedisTemplate扩展RedisAccessor实现RedisOperations,BeanClassLoaderWare
-公共类重新访问器实现InitializingBean
我想知道如何将redisplate注入xxx操作中
我的SpringDataRedis版本是1.8.1.0版本
绝地版本是2.9.0看看这个类
列表操作编辑器
class ListOperationsEditor extends PropertyEditorSupport {
public void setValue(Object value) {
if (value instanceof RedisOperations) {
super.setValue(((RedisOperations) value).opsForList());
} else {
throw new java.lang.IllegalArgumentException("Editor supports only conversion of type " + RedisOperations.class);
}
}
}
使用PropertyEdit或Support转换类型(RedisTemplate->ListOperations)这是否回答了您的问题?
class ListOperationsEditor extends PropertyEditorSupport {
public void setValue(Object value) {
if (value instanceof RedisOperations) {
super.setValue(((RedisOperations) value).opsForList());
} else {
throw new java.lang.IllegalArgumentException("Editor supports only conversion of type " + RedisOperations.class);
}
}