OperationBuilder.java 1.4 KB
package com.zhaoonline.redis.template;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.BoundHashOperations;
import org.springframework.data.redis.core.BoundListOperations;
import org.springframework.data.redis.core.BoundSetOperations;
import org.springframework.data.redis.core.BoundValueOperations;
import org.springframework.data.redis.core.RedisTemplate;

public class OperationBuilder<V> {
	private RedisTemplate<String,V>  redisTemplate;
	
	@Autowired
	public OperationBuilder(RedisTemplateFactory factory){
		 redisTemplate=factory.createTemplate();
		 redisTemplate.afterPropertiesSet();
	}
	
	public RedisTemplate<String,V> template(){
		return this.redisTemplate;
	}
	
	public  BoundValueOperations<String, V> builderValueOperations(String key){
		BoundValueOperations<String, V> valeOper  =redisTemplate.boundValueOps(key);
		return valeOper;
	}
	
	public BoundSetOperations<String, V> builderSetOperations(String key){
		BoundSetOperations<String, V> oper  =redisTemplate.boundSetOps(key);
		return oper;
	}
	
	public BoundListOperations<String, V> builderListOperations(String key){
		BoundListOperations<String, V> oper  =redisTemplate.boundListOps(key);
		return oper;
	}
	
	public <HK,KV> BoundHashOperations<String, HK, KV> builderHashOperations(String key){
		BoundHashOperations<String, HK,KV> oper  =redisTemplate.boundHashOps(key);
		return oper;
	}
}