简化redis
This commit is contained in:
@@ -1,7 +1,5 @@
|
||||
package com.sunyard.ssp.redis;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.sunyard.ssp.server.Config;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.pool2.impl.GenericObjectPoolConfig;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
@@ -141,10 +139,10 @@ public class JedisClusterConfig extends CachingConfigurerSupport {
|
||||
|
||||
@Bean
|
||||
public JedisPool redisPoolFactory(){
|
||||
JSONObject node = Config.global.messenger.redisCluster.getJSONObject("node");
|
||||
String password = Config.global.messenger.redisCluster.getString("password");
|
||||
String host = node.getString("ip");
|
||||
Integer port = node.getInteger("port");
|
||||
// JSONObject node = Config.global.messenger.redisCluster.getJSONObject("node");
|
||||
// String password = Config.global.messenger.redisCluster.getString("password");
|
||||
// String host = node.getString("ip");
|
||||
// Integer port = node.getInteger("port");
|
||||
|
||||
JedisPoolConfig jedisPoolConfig = new JedisPoolConfig();
|
||||
jedisPoolConfig.setMaxTotal(10);
|
||||
@@ -158,7 +156,7 @@ public class JedisClusterConfig extends CachingConfigurerSupport {
|
||||
jedisPoolConfig.setTestOnBorrow(true);
|
||||
jedisPoolConfig.setTestOnReturn(true);
|
||||
|
||||
JedisPool jedisPool = new JedisPool(jedisPoolConfig, host, port, 10000, password);
|
||||
JedisPool jedisPool = new JedisPool(jedisPoolConfig, host2, port2, 10000, password);
|
||||
return jedisPool;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,72 +1,72 @@
|
||||
package com.sunyard.ssp.redis;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.data.redis.core.ListOperations;
|
||||
import org.springframework.data.redis.core.SetOperations;
|
||||
import org.springframework.data.redis.core.StringRedisTemplate;
|
||||
import org.springframework.data.redis.core.ValueOperations;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
/**
|
||||
* @author:tsz
|
||||
* @date:2020/3/6
|
||||
* @description: redis String 基本操作
|
||||
*/
|
||||
@Component
|
||||
public class RedisOperation {
|
||||
|
||||
@Autowired
|
||||
private StringRedisTemplate redisTemplate;
|
||||
|
||||
/***
|
||||
* 操作普通字符串
|
||||
*/
|
||||
public void StringSet(String key, String value) {
|
||||
ValueOperations<String, String> valueOperations = redisTemplate.opsForValue();
|
||||
valueOperations.set(key, value);
|
||||
}
|
||||
|
||||
/***
|
||||
* 操作列表
|
||||
*/
|
||||
public void ListSet(String key, List<String> values) {
|
||||
ListOperations<String, String> listOperations = redisTemplate.opsForList();
|
||||
values.forEach(value -> listOperations.leftPush(key, value));
|
||||
}
|
||||
|
||||
/***
|
||||
* 操作集合
|
||||
*/
|
||||
public void SetSet(String key, Set<String> values) {
|
||||
SetOperations<String, String> setOperations = redisTemplate.opsForSet();
|
||||
values.forEach(value -> setOperations.add(key, value));
|
||||
}
|
||||
|
||||
/***
|
||||
* 获取字符串
|
||||
*/
|
||||
public String StringGet(String key) {
|
||||
ValueOperations<String, String> valueOperations = redisTemplate.opsForValue();
|
||||
return valueOperations.get(key);
|
||||
}
|
||||
|
||||
/***
|
||||
* 列表弹出元素
|
||||
*/
|
||||
public String ListLeftPop(String key) {
|
||||
ListOperations<String, String> listOperations = redisTemplate.opsForList();
|
||||
return listOperations.leftPop(key, 2, TimeUnit.SECONDS);
|
||||
}
|
||||
|
||||
/***
|
||||
* 集合弹出元素
|
||||
*/
|
||||
public String SetPop(String key) {
|
||||
SetOperations<String, String> setOperations = redisTemplate.opsForSet();
|
||||
return setOperations.pop(key);
|
||||
}
|
||||
}
|
||||
//package com.sunyard.ssp.redis;
|
||||
//
|
||||
//import org.springframework.beans.factory.annotation.Autowired;
|
||||
//import org.springframework.data.redis.core.ListOperations;
|
||||
//import org.springframework.data.redis.core.SetOperations;
|
||||
//import org.springframework.data.redis.core.StringRedisTemplate;
|
||||
//import org.springframework.data.redis.core.ValueOperations;
|
||||
//import org.springframework.stereotype.Component;
|
||||
//
|
||||
//import java.util.List;
|
||||
//import java.util.Set;
|
||||
//import java.util.concurrent.TimeUnit;
|
||||
//
|
||||
///**
|
||||
// * @author:tsz
|
||||
// * @date:2020/3/6
|
||||
// * @description: redis String 基本操作
|
||||
// */
|
||||
//@Component
|
||||
//public class RedisOperation {
|
||||
//
|
||||
// @Autowired
|
||||
// private StringRedisTemplate redisTemplate;
|
||||
//
|
||||
// /***
|
||||
// * 操作普通字符串
|
||||
// */
|
||||
// public void StringSet(String key, String value) {
|
||||
// ValueOperations<String, String> valueOperations = redisTemplate.opsForValue();
|
||||
// valueOperations.set(key, value);
|
||||
// }
|
||||
//
|
||||
// /***
|
||||
// * 操作列表
|
||||
// */
|
||||
// public void ListSet(String key, List<String> values) {
|
||||
// ListOperations<String, String> listOperations = redisTemplate.opsForList();
|
||||
// values.forEach(value -> listOperations.leftPush(key, value));
|
||||
// }
|
||||
//
|
||||
// /***
|
||||
// * 操作集合
|
||||
// */
|
||||
// public void SetSet(String key, Set<String> values) {
|
||||
// SetOperations<String, String> setOperations = redisTemplate.opsForSet();
|
||||
// values.forEach(value -> setOperations.add(key, value));
|
||||
// }
|
||||
//
|
||||
// /***
|
||||
// * 获取字符串
|
||||
// */
|
||||
// public String StringGet(String key) {
|
||||
// ValueOperations<String, String> valueOperations = redisTemplate.opsForValue();
|
||||
// return valueOperations.get(key);
|
||||
// }
|
||||
//
|
||||
// /***
|
||||
// * 列表弹出元素
|
||||
// */
|
||||
// public String ListLeftPop(String key) {
|
||||
// ListOperations<String, String> listOperations = redisTemplate.opsForList();
|
||||
// return listOperations.leftPop(key, 2, TimeUnit.SECONDS);
|
||||
// }
|
||||
//
|
||||
// /***
|
||||
// * 集合弹出元素
|
||||
// */
|
||||
// public String SetPop(String key) {
|
||||
// SetOperations<String, String> setOperations = redisTemplate.opsForSet();
|
||||
// return setOperations.pop(key);
|
||||
// }
|
||||
//}
|
||||
|
||||
Reference in New Issue
Block a user