redis可以缓存,自然也可以做简单的消息队列,
下面贴代码
1.核心代码:
import java.util.concurrent.TimeUnit;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.ListOperations;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.core.ValueOperations;
import org.springframework.stereotype.Component;
@Component
public class SongsirRedisTemplate<E> {
@Autowired
private RedisTemplate redisTemplate;
// 序列化工具类
@Autowired
private SerializeUtil<E> serialize;
public static ListOperations<String, String> list;
/**
* 根据键值获取value
*/
public E get(String key) {
ValueOperations<String, String> opsForValue = redisTemplate.opsForValue();
return key == null ? null : serialize.unserialize(opsForValue.get(key));
}
/**
* 设置键值对(无超时时间)
*
* @param key
* @param value