Commit 09604223 by 111-PC\111

[+]pulsar消费服务

1 parent 44f0d754
package cn.com.glsx.consumer.redis;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.data.redis.core.HashOperations;
import org.springframework.data.redis.core.ListOperations;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.core.SetOperations;
import org.springframework.data.redis.core.ValueOperations;
import org.springframework.stereotype.Component;
import javax.annotation.Resource;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.TimeUnit;
/**
*
* redis 操作工具类
*/
@Component
public class RedisService {
@Resource(name = "redisTemplate")
protected RedisTemplate<Object,Object> redisTemplate;
protected Log logger = LogFactory.getLog(getClass());
public void set(String key, Object value) {
ValueOperations valueOperations = redisTemplate.opsForValue();
valueOperations.set(key, value);
}
public Object get(String key) {
return redisTemplate.opsForValue().get(key);
}
public void setList(String key, List<?> value) {
ListOperations listOperations = redisTemplate.opsForList();
listOperations.leftPush(key, value);
}
public void setOutTime(String key, Object value,long timeout, TimeUnit unit) {
ValueOperations valueOperations = redisTemplate.opsForValue();
valueOperations.set(key, value,timeout,unit);
}
public Object getList(String key) {
return redisTemplate.opsForList().leftPop(key);
}
public void setSet(String key, Set<?> value) {
SetOperations setOperations = redisTemplate.opsForSet();
setOperations.add(key, value);
}
public Object getSet(String key) {
return redisTemplate.opsForSet().members(key);
}
public void setHash(String key, Map<String, ?> value) {
HashOperations hashOperations = redisTemplate.opsForHash();
hashOperations.putAll(key, value);
}
public Object getHash(String key) {
return redisTemplate.opsForHash().entries(key);
}
public void delete(String key) {
redisTemplate.delete(key);
}
}
\ No newline at end of file
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!