package cn.com.sunjiesh.thirdservice.wechat.dao;

import java.util.concurrent.TimeUnit;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Repository;

@Repository
public class RedisWechatMessageDao {

	private static final Logger LOGGER = LoggerFactory.getLogger(RedisWechatMessageDao.class);
	
	@Autowired
	private StringRedisTemplate stringRedisTemplate;
	
	public void save(String key,String value){
		stringRedisTemplate.opsForValue().set(key, value);
		LOGGER.debug(key+" in redis is "+stringRedisTemplate.opsForValue().get(key));
	}
	
	public void save(String key,String value,long timeout){
		stringRedisTemplate.opsForValue().set(key, value,timeout,TimeUnit.HOURS);
		LOGGER.debug(key+" in redis is "+stringRedisTemplate.opsForValue().get(key));
	}
	
	public String get(String key){
		return stringRedisTemplate.opsForValue().get(key);
	}
}

@@ -202,16 +202,264 @@
 owired;%0A
+import org.springframework.dao.DataAccessException;%0Aimport org.springframework.data.redis.connection.RedisConnection;%0Aimport org.springframework.data.redis.connection.StringRedisConnection;%0Aimport org.springframework.data.redis.core.RedisCallback;%0A
 import o
@@ -835,37 +835,254 @@
 disTemplate.
-opsForValue()
+execute(new RedisCallback%3CLong%3E()%7B%0A%0A%09%09%09@Override%0A%09%09%09public Long doInRedis(RedisConnection connection) throws DataAccessException %7B%0A%09%09%09%09StringRedisConnection jedis = (StringRedisConnection)connection;%0A%09%09%09%09jedis.select(0);%0A%09%09%09%09jedis
 .set(key, va
@@ -1087,16 +1087,18 @@
 value);%0A
+%09%09
 %09%09LOGGER
@@ -1161,32 +1161,67 @@
 ue().get(key));%0A
+%09%09%09%09return null;%0A%09%09%09%7D%0A%09%09%09%0A%09%09%7D);%0A%09%09%0A
 %09%7D%0A%09%0A%09public voi
@@ -1292,62 +1292,296 @@
 ate.
-opsForValue().set(key, value,timeout,TimeUnit.HOURS
+execute(new RedisCallback%3CLong%3E()%7B%0A%0A%09%09%09@Override%0A%09%09%09public Long doInRedis(RedisConnection connection) throws DataAccessException %7B%0A%09%09%09%09StringRedisConnection jedis = (StringRedisConnection)connection;%0A%09%09%09%09jedis.select(0);%0A%09%09%09%09jedis.set(key, value);%0A%09%09%09%09jedis.expire(key, timeout*60*60
 );%0A
+%09%09
 %09%09LO
@@ -1656,16 +1656,51 @@
 (key));%0A
+%09%09%09%09return null;%0A%09%09%09%7D%0A%09%09%09%0A%09%09%7D);%0A%09%09%0A
 %09%7D%0A%09%0A%09pu

update RedisWechatMessageDao