本文整理匯總了Java中redis.clients.jedis.JedisShardInfo類的典型用法代碼示例。如果您正苦於以下問題:Java JedisShardInfo類的具體用法?Java JedisShardInfo怎麽用?Java JedisShardInfo使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
JedisShardInfo類屬於redis.clients.jedis包,在下文中一共展示了JedisShardInfo類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: connectWithShardInfoAndCustomHostnameVerifier
import redis.clients.jedis.JedisShardInfo; //導入依賴的package包/類
/**
* Tests opening an SSL/TLS connection to redis with a custom hostname
* verifier.
*/
@Test
public void connectWithShardInfoAndCustomHostnameVerifier() {
final URI uri = URI.create("rediss://localhost:6390");
final SSLSocketFactory sslSocketFactory = (SSLSocketFactory) SSLSocketFactory.getDefault();
final SSLParameters sslParameters = new SSLParameters();
HostnameVerifier hostnameVerifier = new BasicHostnameVerifier();
JedisShardInfo shardInfo = new JedisShardInfo(uri, sslSocketFactory, sslParameters, hostnameVerifier);
shardInfo.setPassword("foobared");
Jedis jedis = new Jedis(shardInfo);
jedis.get("foo");
jedis.disconnect();
jedis.close();
}
示例2: connectWithShardInfoAndCustomSocketFactory
import redis.clients.jedis.JedisShardInfo; //導入依賴的package包/類
/**
* Tests opening an SSL/TLS connection to redis with a custom socket factory.
*/
@Test
public void connectWithShardInfoAndCustomSocketFactory() throws Exception {
final URI uri = URI.create("rediss://localhost:6390");
final SSLSocketFactory sslSocketFactory = createTrustStoreSslSocketFactory();
final SSLParameters sslParameters = new SSLParameters();
HostnameVerifier hostnameVerifier = new BasicHostnameVerifier();
JedisShardInfo shardInfo = new JedisShardInfo(uri, sslSocketFactory, sslParameters, hostnameVerifier);
shardInfo.setPassword("foobared");
Jedis jedis = new Jedis(shardInfo);
jedis.get("foo");
jedis.disconnect();
jedis.close();
}
示例3: connectWithShardInfoAndCustomHostnameVerifierByIpAddress
import redis.clients.jedis.JedisShardInfo; //導入依賴的package包/類
/**
* Tests opening an SSL/TLS connection to redis with a custom hostname
* verifier. This test should fail because "127.0.0.1" does not match the
* certificate subject common name and there are no subject alternative names
* in the certificate.
*/
@Test
public void connectWithShardInfoAndCustomHostnameVerifierByIpAddress() {
final URI uri = URI.create("rediss://127.0.0.1:6390");
final SSLSocketFactory sslSocketFactory = (SSLSocketFactory) SSLSocketFactory.getDefault();
final SSLParameters sslParameters = new SSLParameters();
HostnameVerifier hostnameVerifier = new BasicHostnameVerifier();
JedisShardInfo shardInfo = new JedisShardInfo(uri, sslSocketFactory, sslParameters, hostnameVerifier);
shardInfo.setPassword("foobared");
Jedis jedis = new Jedis(shardInfo);
try {
jedis.get("foo");
Assert.fail("The code did not throw the expected JedisConnectionException.");
} catch (JedisConnectionException e) {
Assert.assertEquals("The JedisConnectionException does not contain the expected message.",
"The connection to '127.0.0.1' failed ssl/tls hostname verification.", e.getMessage());
}
try {
jedis.close();
} catch (Throwable e1) {
// Expected.
}
}
示例4: testMasterSlaveShardingConsistency
import redis.clients.jedis.JedisShardInfo; //導入依賴的package包/類
@Test
public void testMasterSlaveShardingConsistency() {
List<JedisShardInfo> shards = new ArrayList<JedisShardInfo>(3);
shards.add(new JedisShardInfo("localhost", Protocol.DEFAULT_PORT));
shards.add(new JedisShardInfo("localhost", Protocol.DEFAULT_PORT + 1));
shards.add(new JedisShardInfo("localhost", Protocol.DEFAULT_PORT + 2));
Sharded<Jedis, JedisShardInfo> sharded = new Sharded<Jedis, JedisShardInfo>(shards,
Hashing.MURMUR_HASH);
List<JedisShardInfo> otherShards = new ArrayList<JedisShardInfo>(3);
otherShards.add(new JedisShardInfo("otherhost", Protocol.DEFAULT_PORT));
otherShards.add(new JedisShardInfo("otherhost", Protocol.DEFAULT_PORT + 1));
otherShards.add(new JedisShardInfo("otherhost", Protocol.DEFAULT_PORT + 2));
Sharded<Jedis, JedisShardInfo> sharded2 = new Sharded<Jedis, JedisShardInfo>(otherShards,
Hashing.MURMUR_HASH);
for (int i = 0; i < 1000; i++) {
JedisShardInfo jedisShardInfo = sharded.getShardInfo(Integer.toString(i));
JedisShardInfo jedisShardInfo2 = sharded2.getShardInfo(Integer.toString(i));
assertEquals(shards.indexOf(jedisShardInfo), otherShards.indexOf(jedisShardInfo2));
}
}
示例5: testMasterSlaveShardingConsistencyWithShardNaming
import redis.clients.jedis.JedisShardInfo; //導入依賴的package包/類
@Test
public void testMasterSlaveShardingConsistencyWithShardNaming() {
List<JedisShardInfo> shards = new ArrayList<JedisShardInfo>(3);
shards.add(new JedisShardInfo("localhost", Protocol.DEFAULT_PORT, "HOST1:1234"));
shards.add(new JedisShardInfo("localhost", Protocol.DEFAULT_PORT + 1, "HOST2:1234"));
shards.add(new JedisShardInfo("localhost", Protocol.DEFAULT_PORT + 2, "HOST3:1234"));
Sharded<Jedis, JedisShardInfo> sharded = new Sharded<Jedis, JedisShardInfo>(shards,
Hashing.MURMUR_HASH);
List<JedisShardInfo> otherShards = new ArrayList<JedisShardInfo>(3);
otherShards.add(new JedisShardInfo("otherhost", Protocol.DEFAULT_PORT, "HOST2:1234"));
otherShards.add(new JedisShardInfo("otherhost", Protocol.DEFAULT_PORT + 1, "HOST3:1234"));
otherShards.add(new JedisShardInfo("otherhost", Protocol.DEFAULT_PORT + 2, "HOST1:1234"));
Sharded<Jedis, JedisShardInfo> sharded2 = new Sharded<Jedis, JedisShardInfo>(otherShards,
Hashing.MURMUR_HASH);
for (int i = 0; i < 1000; i++) {
JedisShardInfo jedisShardInfo = sharded.getShardInfo(Integer.toString(i));
JedisShardInfo jedisShardInfo2 = sharded2.getShardInfo(Integer.toString(i));
assertEquals(jedisShardInfo.getName(), jedisShardInfo2.getName());
}
}
示例6: checkCloseable
import redis.clients.jedis.JedisShardInfo; //導入依賴的package包/類
@Test
public void checkCloseable() {
List<JedisShardInfo> shards = new ArrayList<JedisShardInfo>();
shards.add(new JedisShardInfo(redis1.getHost(), redis1.getPort()));
shards.add(new JedisShardInfo(redis2.getHost(), redis2.getPort()));
shards.get(0).setPassword("foobared");
shards.get(1).setPassword("foobared");
ShardedJedis jedisShard = new ShardedJedis(shards);
try {
jedisShard.set("shard_closeable", "true");
} finally {
jedisShard.close();
}
for (Jedis jedis : jedisShard.getAllShards()) {
assertTrue(!jedis.isConnected());
}
}
示例7: checkResourceIsCloseable
import redis.clients.jedis.JedisShardInfo; //導入依賴的package包/類
@Test
public void checkResourceIsCloseable() throws URISyntaxException {
GenericObjectPoolConfig config = new GenericObjectPoolConfig();
config.setMaxTotal(1);
config.setBlockWhenExhausted(false);
List<JedisShardInfo> shards = new ArrayList<JedisShardInfo>();
shards.add(new JedisShardInfo(new URI("redis://:[email protected]:6380")));
shards.add(new JedisShardInfo(new URI("redis://:[email protected]:6379")));
ShardedJedisPool pool = new ShardedJedisPool(config, shards);
ShardedJedis jedis = pool.getResource();
try {
jedis.set("hello", "jedis");
} finally {
jedis.close();
}
ShardedJedis jedis2 = pool.getResource();
try {
assertEquals(jedis, jedis2);
} finally {
jedis2.close();
}
}
示例8: getJedisPool
import redis.clients.jedis.JedisShardInfo; //導入依賴的package包/類
@Bean(name="monitorJedisPool")
public ShardedJedisPool getJedisPool() {
try {
List<JedisShardInfo> shardList = new ArrayList<>();
String hostStr = env.getProperty("spring.redis.shard.monitor.hostList");
int timeOut = Integer.parseInt(env.getProperty("spring.redis.shard.monitor.timeOut"));
if(!StringUtils.isEmpty(hostStr)){
String[] hosts = hostStr.split(",");
for(int i = 0; i < hosts.length; i++){
String[] temp = hosts[i].split(":");
JedisShardInfo info = new JedisShardInfo(temp[0], Integer.valueOf(temp[1]), timeOut);
shardList.add(info);
}
}
if(shardList.size() == 0){
//無法加載redis
throw new IOException();
}
return new ShardedJedisPool(getJedisPoolConfig(), shardList);
} catch (Exception e) {
throw new RuntimeException("無法加載資源文件!");
}
}
示例9: afterPropertiesSet
import redis.clients.jedis.JedisShardInfo; //導入依賴的package包/類
@Override
public void afterPropertiesSet() throws Exception {
final JedisPoolConfig config = JedisPoolConfigFactory.createJedisPoolConfig();
final Set<JedisShardInfo> shardInfos = new HashSet<JedisShardInfo>();
final HostInfo[] hostInfos = HostInfoFactory.split(hosts);
for (final HostInfo hostInfo : hostInfos) {
shardInfos.add(hostInfo.createJedisShardInfo());
}
if (redisService == null) {
final ShardedJedisPool jedisPool = new ShardedJedisPool(config, new ArrayList<JedisShardInfo>(shardInfos));
redisService = new RedisServiceImpl(jedisPool);
}
final RedisServiceProxy redisServiceProxy = new RedisServiceProxy();
this.redisService = redisServiceProxy.bind(redisService);
}
示例10: JU_Puts
import redis.clients.jedis.JedisShardInfo; //導入依賴的package包/類
public JU_Puts()
{
// ���÷ֲ�ʽ��Ⱥ����
List<JedisShardInfo> v_JSIs = new ArrayList<JedisShardInfo>();
v_JSIs.add(new JedisShardInfo("192.168.105.105" ,6379)); // ��Ⱥ1�е���������
// v_JSIs.add(new JedisShardInfo("192.168.105.109" ,6379)); // ��Ⱥ2�е���������
// ��������
for (JedisShardInfo v_Shard : v_JSIs)
{
v_Shard.setPassword("redis");
}
redis = new Redis(v_JSIs);
redis.setRunMode(RunMode.$Backup);
}
示例11: initialShardedPool
import redis.clients.jedis.JedisShardInfo; //導入依賴的package包/類
/**
* 初始化切片池
*/
private void initialShardedPool()
{
// 池基本配置
JedisPoolConfig config = new JedisPoolConfig();
config.setMaxActive(20);
config.setMaxIdle(5);
config.setMaxWait(1000l);
config.setTestOnBorrow(false);
// slave鏈接
List<JedisShardInfo> shards = new ArrayList<JedisShardInfo>();
shards.add(new JedisShardInfo("127.0.0.1", 6379, "master"));
// 構造池
shardedJedisPool = new ShardedJedisPool(config, shards);
}
示例12: startUp
import redis.clients.jedis.JedisShardInfo; //導入依賴的package包/類
@Before
public void startUp() {
shards = new ArrayList<JedisShardInfo>();
shards.add(new JedisShardInfo(redis1.getHost(), redis1.getPort()));
shards.add(new JedisShardInfo(redis2.getHost(), redis2.getPort()));
shards.get(0).setPassword("foobared");
shards.get(1).setPassword("foobared");
Jedis j = new Jedis(shards.get(0));
j.connect();
j.flushAll();
j.disconnect();
j = new Jedis(shards.get(1));
j.connect();
j.flushAll();
j.disconnect();
}
示例13: setUp
import redis.clients.jedis.JedisShardInfo; //導入依賴的package包/類
@Before
public void setUp() throws Exception {
Jedis jedis = new Jedis(redis1.getHost(), redis1.getPort());
jedis.auth("foobared");
jedis.flushAll();
jedis.disconnect();
jedis = new Jedis(redis2.getHost(), redis2.getPort());
jedis.auth("foobared");
jedis.flushAll();
jedis.disconnect();
JedisShardInfo shardInfo1 = new JedisShardInfo(redis1.getHost(), redis1.getPort());
JedisShardInfo shardInfo2 = new JedisShardInfo(redis2.getHost(), redis2.getPort());
shardInfo1.setPassword("foobared");
shardInfo2.setPassword("foobared");
List<JedisShardInfo> shards = new ArrayList<JedisShardInfo>();
shards.add(shardInfo1);
shards.add(shardInfo2);
this.jedis = new ShardedJedis(shards);
}
示例14: testSyncWithNoCommandQueued
import redis.clients.jedis.JedisShardInfo; //導入依賴的package包/類
@Test
public void testSyncWithNoCommandQueued() {
JedisShardInfo shardInfo1 = new JedisShardInfo(redis1.getHost(), redis1.getPort());
JedisShardInfo shardInfo2 = new JedisShardInfo(redis2.getHost(), redis2.getPort());
shardInfo1.setPassword("foobared");
shardInfo2.setPassword("foobared");
List<JedisShardInfo> shards = new ArrayList<JedisShardInfo>();
shards.add(shardInfo1);
shards.add(shardInfo2);
ShardedJedis jedis2 = new ShardedJedis(shards);
ShardedJedisPipeline pipeline = jedis2.pipelined();
pipeline.sync();
jedis2.close();
jedis2 = new ShardedJedis(shards);
pipeline = jedis2.pipelined();
List<Object> resp = pipeline.syncAndReturnAll();
assertTrue(resp.isEmpty());
jedis2.close();
}
示例15: createJedisManager
import redis.clients.jedis.JedisShardInfo; //導入依賴的package包/類
/**
*
* @return
*/
public static JedisManager createJedisManager() {
Config conf = Config.newInstance();
// 池基本配置
JedisPoolConfig config = new JedisPoolConfig();
config.setMaxIdle(conf.getInt("redis.maxIdle"));
config.setMinIdle(conf.getInt("redis.minIdle"));
config.setMaxWaitMillis(conf.getLong("redis.maxWaitMillis"));
config.setTestOnBorrow(conf.getBoolean("redis.testOnBorrow"));
List<JedisShardInfo> shards = new ArrayList<JedisShardInfo>();
// slave鏈接
shards.add(new JedisShardInfo(conf.getString("redis.slave.host"), conf
.getInt("redis.slave.port"), conf.getInt("redis.timeout")));
// master鏈接
shards.add(new JedisShardInfo(conf.getString("redis.master.host"), conf
.getInt("redis.master.port"), conf.getInt("redis.timeout")));
// 構造池
ShardedJedisPool shardedJedisPool = new ShardedJedisPool(config, shards);
return new JedisManager(shardedJedisPool);
}