本文整理汇总了Java中redis.clients.jedis.JedisCluster类的典型用法代码示例。如果您正苦于以下问题:Java JedisCluster类的具体用法?Java JedisCluster怎么用?Java JedisCluster使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
JedisCluster类属于redis.clients.jedis包,在下文中一共展示了JedisCluster类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: main
import redis.clients.jedis.JedisCluster; //导入依赖的package包/类
@SuppressWarnings("resource")
public static void main(String[] args) {
Set<HostAndPort> nodes = new HashSet<HostAndPort>();
nodes.add(new HostAndPort("127.0.0.1", 7000));
nodes.add(new HostAndPort("127.0.0.1", 7001));
nodes.add(new HostAndPort("127.0.0.1", 7002));
nodes.add(new HostAndPort("127.0.0.1", 7003));
nodes.add(new HostAndPort("127.0.0.1", 7004));
nodes.add(new HostAndPort("127.0.0.1", 7005));
JedisCluster cluster = new JedisCluster(nodes, 5000);
System.out.println(cluster.get("foo"));
cluster.set("test", "6379");
System.out.println(cluster.get("test"));
Map<String, String> inviteePhone = new HashMap<String, String>();
inviteePhone.put("inviterID", "1001");
inviteePhone.put("status", "0");
cluster.hmset("inviteePhone", inviteePhone);
System.out.println(cluster.hget("inviteePhone", "inviterID"));
System.out.println(cluster.hget("inviteePhone", "status"));
}
示例2: getJedisCluster
import redis.clients.jedis.JedisCluster; //导入依赖的package包/类
/**
* 注意:
* 这里返回的JedisCluster是单例的,并且可以直接注入到其他类中去使用
* @return
*/
@Bean
public JedisCluster getJedisCluster() {
//获取服务器数组(这里要相信自己的输入,所以没有考虑空指针问题)
String[] serverArray = redisProperties.getClusterNodes().split(",");
Set<HostAndPort> nodes = new HashSet<>();
for (String ipPort : serverArray) {
String[] ipPortPair = ipPort.split(":");
nodes.add(new HostAndPort(ipPortPair[0].trim(), Integer.valueOf(ipPortPair[1].trim())));
}
return new JedisCluster(nodes,10000,
1000,1,redisProperties.getPassword() ,
new GenericObjectPoolConfig());
}
示例3: testCalculateConnectionPerSlot
import redis.clients.jedis.JedisCluster; //导入依赖的package包/类
@Test
public void testCalculateConnectionPerSlot() {
Set<HostAndPort> jedisClusterNode = new HashSet<HostAndPort>();
jedisClusterNode.add(new HostAndPort("127.0.0.1", 7379));
JedisCluster jc = new JedisCluster(jedisClusterNode, DEFAULT_TIMEOUT, DEFAULT_TIMEOUT, DEFAULT_REDIRECTIONS, "cluster", DEFAULT_CONFIG);
jc.set("foo", "bar");
jc.set("test", "test");
assertEquals("bar", node3.get("foo"));
assertEquals("test", node2.get("test"));
JedisCluster jc2 = new JedisCluster(new HostAndPort("127.0.0.1", 7379), DEFAULT_TIMEOUT, DEFAULT_TIMEOUT, DEFAULT_REDIRECTIONS, "cluster", DEFAULT_CONFIG);
jc2.set("foo", "bar");
jc2.set("test", "test");
assertEquals("bar", node3.get("foo"));
assertEquals("test", node2.get("test"));
}
示例4: testStableSlotWhenMigratingNodeOrImportingNodeIsNotSpecified
import redis.clients.jedis.JedisCluster; //导入依赖的package包/类
@Test
public void testStableSlotWhenMigratingNodeOrImportingNodeIsNotSpecified()
throws InterruptedException {
Set<HostAndPort> jedisClusterNode = new HashSet<HostAndPort>();
jedisClusterNode.add(new HostAndPort(nodeInfo1.getHost(), nodeInfo1.getPort()));
JedisCluster jc = new JedisCluster(jedisClusterNode, DEFAULT_TIMEOUT, DEFAULT_TIMEOUT, DEFAULT_REDIRECTIONS, "cluster", DEFAULT_CONFIG);
int slot51 = JedisClusterCRC16.getSlot("51");
jc.set("51", "foo");
// node2 is responsible of taking care of slot51 (7186)
node3.clusterSetSlotImporting(slot51, JedisClusterTestUtil.getNodeId(node2.clusterNodes()));
assertEquals("foo", jc.get("51"));
node3.clusterSetSlotStable(slot51);
assertEquals("foo", jc.get("51"));
node2.clusterSetSlotMigrating(slot51, JedisClusterTestUtil.getNodeId(node3.clusterNodes()));
// assertEquals("foo", jc.get("51")); // it leads Max Redirections
node2.clusterSetSlotStable(slot51);
assertEquals("foo", jc.get("51"));
}
示例5: getJedisCluster
import redis.clients.jedis.JedisCluster; //导入依赖的package包/类
@Bean//bean
public JedisCluster getJedisCluster() {
//解析字符串
Set<HostAndPort> nodes = new HashSet<>();
try {
String[] cNodes = clusterNodes.split(",");
for (String cNode : cNodes) {
//192.168.123.1:7001
String[] hp = cNode.split(":");
nodes.add(new HostAndPort(hp[0], Integer.parseInt(hp[1])));
}
return new JedisCluster(nodes);
} catch (ArrayIndexOutOfBoundsException | PatternSyntaxException | NullPointerException e) {
e.printStackTrace();
}
return null;
}
示例6: init
import redis.clients.jedis.JedisCluster; //导入依赖的package包/类
/**
* This method is called by PDI during transformation startup.
*
* @param smi step meta interface implementation, containing the step settings
* @param sdi step data interface implementation, used to store runtime information
*
* @return true if initialization completed successfully, false if there was an error preventing the step from working.
*
*/
public boolean init(StepMetaInterface smi, StepDataInterface sdi) {
// Casting to step-specific implementation classes is safe
RedisOutputStepMeta meta = (RedisOutputStepMeta) smi;
RedisOutputStepData data = (RedisOutputStepData) sdi;
String url = environmentSubstitute(meta.getUrl());
logBasic("creating redis session factory, addresses=" + url);
if (url == null || url.isEmpty()) {
throw new IllegalArgumentException("redis cluster url set configured");
}
String[] redisNodes = url.split(",");
Set<HostAndPort> jedisClusterNodes = new HashSet<>();
try {
for (String redisNode: redisNodes) {
String[] config = redisNode.split(":");
jedisClusterNodes.add(new HostAndPort(config[0], Integer.parseInt(config[1])));
}
} catch (IllegalArgumentException ex) {
throw new IllegalArgumentException("redis cluster url not configured correctly");
}
client = new JedisCluster(jedisClusterNodes, REDIS_TIMEOUT, new GenericObjectPoolConfig());
return super.init(meta, data);
}
示例7: getJedisCluster
import redis.clients.jedis.JedisCluster; //导入依赖的package包/类
@Bean
public JedisCluster getJedisCluster() {
List<String> serverArray = redisProperties.getNodes();
Set<HostAndPort> nodes = new HashSet<>();
for (String ipPort : serverArray) {
String[] ipPortPair = ipPort.split(":");
nodes.add(new HostAndPort(ipPortPair[0].trim(), Integer.valueOf(ipPortPair[1].trim())));
}
JedisPoolConfig config = new JedisPoolConfig();
config.setMaxTotal(500);
config.setMaxIdle(1000 * 60);
config.setMaxWaitMillis(1000 * 10);
config.setTestOnBorrow(true);
return new JedisCluster(nodes, config);
}
示例8: exist
import redis.clients.jedis.JedisCluster; //导入依赖的package包/类
private ScanPage exist(String cluster, ScanPage scanPage) throws Exception {
scanPage.setHasMore(false);
List<D_RedisClusterNode> nodes = clusterNodeService.getAllClusterNodes(cluster);
Set<HostAndPort> masters = new HashSet<HostAndPort>();
nodes.forEach(node->{
masters.add(new HostAndPort(node.getHost(), node.getPort()));
});
JedisCluster jedis = new JedisCluster(masters);
try {
if(jedis.exists(scanPage.getQuery())){
scanPage.setKeys(new HashSet<String>());
scanPage.getKeys().add(scanPage.getQuery());
}
} finally {
jedis.close();
}
return scanPage;
}
示例9: testCluster
import redis.clients.jedis.JedisCluster; //导入依赖的package包/类
/**测试redis集群方案*/
@Test
public void testCluster(){
Set<HostAndPort> jedisClusterNodes = new HashSet<HostAndPort>();
//Jedis Cluster will attempt to discover cluster nodes automatically
jedisClusterNodes.add(new HostAndPort("192.168.12.90", 7001));
JedisCluster jc = new JedisCluster(jedisClusterNodes);
jc.set("foo", "bar");
String value = jc.get("foo");
System.out.println(value);
try {
jc.close();
} catch (Exception e) {
e.printStackTrace();
}
}
示例10: getRedisCluster
import redis.clients.jedis.JedisCluster; //导入依赖的package包/类
@Bean
public JedisCluster getRedisCluster(){
Set<HostAndPort> jedisClusterNode = new HashSet<HostAndPort>();
jedisClusterNode.add(new HostAndPort(environment.getProperty("redis.cluster.nodes1"), Integer.parseInt(environment.getProperty("redis.cluster.port1"))));
jedisClusterNode.add(new HostAndPort(environment.getProperty("redis.cluster.nodes2"), Integer.parseInt(environment.getProperty("redis.cluster.port2"))));
jedisClusterNode.add(new HostAndPort(environment.getProperty("redis.cluster.nodes3"), Integer.parseInt(environment.getProperty("redis.cluster.port3"))));
jedisClusterNode.add(new HostAndPort(environment.getProperty("redis.cluster.nodes4"), Integer.parseInt(environment.getProperty("redis.cluster.port4"))));
jedisClusterNode.add(new HostAndPort(environment.getProperty("redis.cluster.nodes5"), Integer.parseInt(environment.getProperty("redis.cluster.port5"))));
jedisClusterNode.add(new HostAndPort(environment.getProperty("redis.cluster.nodes6"), Integer.parseInt(environment.getProperty("redis.cluster.port6"))));
JedisPoolConfig cfg = new JedisPoolConfig();
cfg.setMaxTotal(Integer.parseInt(environment.getProperty("redis.cluster.config.max-total")));
cfg.setMaxIdle(Integer.parseInt(environment.getProperty("redis.cluster.config.max-idle")));
cfg.setMaxWaitMillis(Integer.parseInt(environment.getProperty("redis.cluster.config.max-waitmillis")));
cfg.setTestOnBorrow(Boolean.parseBoolean(environment.getProperty("redis.cluster.config.onborrow")));
JedisCluster jc = new JedisCluster(jedisClusterNode, Integer.parseInt(environment.getProperty("redis.cluster.timeout")), Integer.parseInt(environment.getProperty("redis.cluster.max-redirections")), cfg);
return jc;
}
示例11: RedisDelayQueue
import redis.clients.jedis.JedisCluster; //导入依赖的package包/类
public RedisDelayQueue(String redisKeyPrefix, String queueName, JedisCluster jedisCluster, int unackTime,
DelayQueueProcessListener delayQueueProcessListener) {
om = new ObjectMapper();
om.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
om.configure(DeserializationFeature.FAIL_ON_IGNORED_PROPERTIES, false);
om.configure(DeserializationFeature.FAIL_ON_NULL_FOR_PRIMITIVES, false);
om.setSerializationInclusion(Include.NON_NULL);
om.setSerializationInclusion(Include.NON_EMPTY);
om.disable(SerializationFeature.INDENT_OUTPUT);
this.redisKeyPrefix = redisKeyPrefix;
this.messageStoreKey = redisKeyPrefix + ".MESSAGE." + queueName;
this.unackTime = unackTime;
this.jedisCluster = jedisCluster;
realQueueName = redisKeyPrefix + ".QUEUE." + queueName;
this.delayQueueProcessListener = delayQueueProcessListener;
}
示例12: stop
import redis.clients.jedis.JedisCluster; //导入依赖的package包/类
@Override
public boolean stop() {
// 清除出集群集合
JedisCluster removeRedisCluster = RedisCluster.removeCache(clusterName);
// 关闭集群链接
try {
removeRedisCluster.close();
} catch (IOException e) {
logger.error(e.getMessage());
}
return false;
}
示例13: init
import redis.clients.jedis.JedisCluster; //导入依赖的package包/类
@PostConstruct
public void init(){
Set<HostAndPort> jedisClusterNodes = new HashSet<HostAndPort>();
String[] split = redisClusterConfig.getJedisClusterNodesIps().split(";");
for(String one:split){
String[] ipPort = one.split(":");
jedisClusterNodes.add(new HostAndPort(ipPort[0], Integer.valueOf(ipPort[1])));
}
GenericObjectPoolConfig poolConfig = new GenericObjectPoolConfig();
poolConfig.setMaxIdle(redisClusterConfig.getMaxIdle());
poolConfig.setMaxTotal(redisClusterConfig.getMaxTotal());
poolConfig.setMaxWaitMillis(redisClusterConfig.getMaxWaitMillis());
// poolConfig.setMinIdle(minIdle);
poolConfig.setTestOnBorrow(redisClusterConfig.isTestOnBorrow());
poolConfig.setTestOnReturn(redisClusterConfig.isTestOnReturn());
jc = new JedisCluster(jedisClusterNodes,60000,10,poolConfig);
}
示例14: setJedisPool
import redis.clients.jedis.JedisCluster; //导入依赖的package包/类
void setJedisPool() {
final String clusters = this.redisConfig.getClusters();
if (StringUtils.isBlank(clusters)) {
throw new IllegalArgumentException("redis.clusters must not be blank");
}
final int connectionTimeout = this.redisConfig.getConnectionTimeout();
final int soTimeout = this.redisConfig.getSoTimeout();
final int maxRedirections = this.redisConfig.getMaxRedirections();
Set<HostAndPort> nodes = new HashSet<HostAndPort>();
for (String str : clusters.split("[,\\s\\t]+")) {
final String[] arr = str.split(":");
nodes.add(new HostAndPort(arr[0], Integer.parseInt(arr[1])));
}
this.jedisCluster = new JedisCluster(nodes, connectionTimeout, soTimeout, maxRedirections, this.poolConfig);
if (logger.isInfoEnabled()) {
logger.info("connect to Redis Cluster {}", clusters);
}
}
示例15: test
import redis.clients.jedis.JedisCluster; //导入依赖的package包/类
@Test
public void test() throws Exception {
Set<HostAndPort> jedisClusterNodes = new HashSet<HostAndPort>();
jedisClusterNodes.add(new HostAndPort(RedisConfig.DEFAULT_HOST, RedisConfig.DEFAULT_PORT));
RedisClusterConnPool pool = new RedisClusterConnPool(jedisClusterNodes);
JedisCluster cluster = pool.getConnection();
Assert.assertNotNull(cluster);
pool.returnConnection(cluster);
pool.invalidateConnection(cluster);
Properties properties = new Properties();
properties.setProperty(RedisConfig.CLUSTER_PROPERTY, RedisConfig.DEFAULT_HOST + ":" + RedisConfig.DEFAULT_PORT);
pool = new RedisClusterConnPool(properties);
cluster = pool.getConnection();
Assert.assertNotNull(cluster);
pool.close();
pool = new RedisClusterConnPool(new PoolConfig(), jedisClusterNodes);
pool.close();
}