本文整理汇总了Java中com.lambdaworks.redis.RedisURI.create方法的典型用法代码示例。如果您正苦于以下问题:Java RedisURI.create方法的具体用法?Java RedisURI.create怎么用?Java RedisURI.create使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.lambdaworks.redis.RedisURI
的用法示例。
在下文中一共展示了RedisURI.create方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: init
import com.lambdaworks.redis.RedisURI; //导入方法依赖的package包/类
@Override
public void init(AbstractConfiguration config) {
if (!config.getString("redis.type").equals("master_slave")) {
throw new IllegalStateException("RedisSyncSingleStorageImpl class can only be used with master slave redis setup, but redis.type value is " + config.getString("redis.type"));
}
List<String> address = parseRedisAddress(config.getString("redis.address"), 6379);
int databaseNumber = config.getInt("redis.database", 0);
String password = StringUtils.isNotEmpty(config.getString("redis.password")) ? config.getString("redis.password") + "@" : "";
// lettuce
RedisURI lettuceURI = RedisURI.create("redis://" + password + address.get(0) + "/" + databaseNumber);
this.lettuceMasterSlave = RedisClient.create(lettuceURI);
this.lettuceMasterSlaveConn = MasterSlave.connect(this.lettuceMasterSlave, new Utf8StringCodec(), lettuceURI);
this.lettuceMasterSlaveConn.setReadFrom(ReadFrom.valueOf(config.getString("redis.read")));
// params
initParams(config);
}
示例2: init
import com.lambdaworks.redis.RedisURI; //导入方法依赖的package包/类
@Override
public void init(AbstractConfiguration config) {
if (!config.getString("redis.type").equals("single")) {
throw new IllegalStateException("RedisSyncSingleStorageImpl class can only be used with single redis setup, but redis.type value is " + config.getString("redis.type"));
}
List<String> address = parseRedisAddress(config.getString("redis.address"), 6379);
int databaseNumber = config.getInt("redis.database", 0);
String password = StringUtils.isNotEmpty(config.getString("redis.password")) ? config.getString("redis.password") + "@" : "";
// lettuce
RedisURI lettuceURI = RedisURI.create("redis://" + password + address.get(0) + "/" + databaseNumber);
this.lettuce = RedisClient.create(lettuceURI);
this.lettuceConn = this.lettuce.connect();
// params
initParams(config);
}
示例3: init
import com.lambdaworks.redis.RedisURI; //导入方法依赖的package包/类
@Override
public void init(AbstractConfiguration config) {
if (!config.getString("redis.type").equals("sentinel")) {
throw new IllegalStateException("RedisSyncSingleStorageImpl class can only be used with sentinel redis setup, but redis.type value is " + config.getString("redis.type"));
}
List<String> address = parseRedisAddress(config.getString("redis.address"), 26379);
int databaseNumber = config.getInt("redis.database", 0);
String password = StringUtils.isNotEmpty(config.getString("redis.password")) ? config.getString("redis.password") + "@" : "";
String masterId = config.getString("redis.master");
// lettuce
RedisURI lettuceURI = RedisURI.create("redis-sentinel://" + password + String.join(",", address) + "/" + databaseNumber + "#" + masterId);
this.lettuceSentinel = RedisClient.create(lettuceURI);
this.lettuceSentinelConn = MasterSlave.connect(this.lettuceSentinel, new Utf8StringCodec(), lettuceURI);
this.lettuceSentinelConn.setReadFrom(ReadFrom.valueOf(config.getString("redis.read")));
// params
initParams(config);
}
示例4: isChangedShouldReturnFalse
import com.lambdaworks.redis.RedisURI; //导入方法依赖的package包/类
@Test
public void isChangedShouldReturnFalse() throws Exception {
RedisMasterSlaveNode master = new RedisMasterSlaveNode("host", 1234, RedisURI.create("host", 111),
RedisInstance.Role.MASTER);
RedisMasterSlaveNode slave = new RedisMasterSlaveNode("host", 234, RedisURI.create("host", 234),
RedisInstance.Role.SLAVE);
RedisMasterSlaveNode newmaster = new RedisMasterSlaveNode("host", 1234, RedisURI.create("host", 555),
RedisInstance.Role.MASTER);
RedisMasterSlaveNode newslave = new RedisMasterSlaveNode("host", 234, RedisURI.create("host", 666),
RedisInstance.Role.SLAVE);
assertThat(MasterSlaveUtils.isChanged(Arrays.asList(master, slave), Arrays.asList(newmaster, newslave))).isFalse();
assertThat(MasterSlaveUtils.isChanged(Arrays.asList(slave, master), Arrays.asList(newmaster, newslave))).isFalse();
assertThat(MasterSlaveUtils.isChanged(Arrays.asList(newmaster, newslave), Arrays.asList(master, slave))).isFalse();
assertThat(MasterSlaveUtils.isChanged(Arrays.asList(newmaster, newslave), Arrays.asList(slave, master))).isFalse();
}
示例5: isChangedShouldReturnTrueBecauseHostWasMigrated
import com.lambdaworks.redis.RedisURI; //导入方法依赖的package包/类
@Test
public void isChangedShouldReturnTrueBecauseHostWasMigrated() throws Exception {
RedisMasterSlaveNode master = new RedisMasterSlaveNode("host", 1234, RedisURI.create("host", 111),
RedisInstance.Role.MASTER);
RedisMasterSlaveNode slave = new RedisMasterSlaveNode("host", 234, RedisURI.create("host", 234),
RedisInstance.Role.SLAVE);
RedisMasterSlaveNode newmaster = new RedisMasterSlaveNode("host", 1234, RedisURI.create("host", 555),
RedisInstance.Role.MASTER);
RedisMasterSlaveNode newslave = new RedisMasterSlaveNode("newhost", 234, RedisURI.create("newhost", 666),
RedisInstance.Role.SLAVE);
assertThat(MasterSlaveUtils.isChanged(Arrays.asList(master, slave), Arrays.asList(newmaster, newslave))).isTrue();
assertThat(MasterSlaveUtils.isChanged(Arrays.asList(slave, master), Arrays.asList(newmaster, newslave))).isTrue();
assertThat(MasterSlaveUtils.isChanged(Arrays.asList(newmaster, newslave), Arrays.asList(master, slave))).isTrue();
assertThat(MasterSlaveUtils.isChanged(Arrays.asList(newslave, newmaster), Arrays.asList(master, slave))).isTrue();
}
示例6: isChangedShouldReturnTrueBecauseRolesSwitched
import com.lambdaworks.redis.RedisURI; //导入方法依赖的package包/类
@Test
public void isChangedShouldReturnTrueBecauseRolesSwitched() throws Exception {
RedisMasterSlaveNode master = new RedisMasterSlaveNode("host", 1234, RedisURI.create("host", 111),
RedisInstance.Role.MASTER);
RedisMasterSlaveNode slave = new RedisMasterSlaveNode("host", 234, RedisURI.create("host", 234),
RedisInstance.Role.MASTER);
RedisMasterSlaveNode newslave = new RedisMasterSlaveNode("host", 1234, RedisURI.create("host", 111),
RedisInstance.Role.SLAVE);
RedisMasterSlaveNode newmaster = new RedisMasterSlaveNode("host", 234, RedisURI.create("host", 234),
RedisInstance.Role.MASTER);
assertThat(MasterSlaveUtils.isChanged(Arrays.asList(master, slave), Arrays.asList(newmaster, newslave))).isTrue();
assertThat(MasterSlaveUtils.isChanged(Arrays.asList(master, slave), Arrays.asList(newslave, newmaster))).isTrue();
}
示例7: shouldReuseKnownUris
import com.lambdaworks.redis.RedisURI; //导入方法依赖的package包/类
@Test
public void shouldReuseKnownUris() throws Exception {
RedisURI localhost = RedisURI.create("localhost", 6479);
RedisURI otherhost = RedisURI.create("127.0.0.2", 7000);
RedisURI host3 = RedisURI.create("127.0.0.3", 7000);
String viewByLocalhost = "1 127.0.0.1:6479 master,myself - 0 1401258245007 2 connected 8000-11999\n"
+ "2 127.0.0.2:7000 master - 111 1401258245007 222 connected 7000 12000 12002-16383\n"
+ "3 127.0.0.3:7000 master - 111 1401258245007 222 connected 7000 12000 12002-16383\n";
String viewByOtherhost = "1 127.0.0.1:6479 master - 0 1401258245007 2 connected 8000-11999\n"
+ "2 127.0.0.2:7000 master,myself - 111 1401258245007 222 connected 7000 12000 12002-16383\n"
+ "3 127.0.0.3:7000 master - 111 1401258245007 222 connected 7000 12000 12002-16383\n";
NodeTopologyView localhostView = new NodeTopologyView(localhost, viewByLocalhost, "", 0);
NodeTopologyView otherhostView = new NodeTopologyView(otherhost, viewByOtherhost, "", 0);
NodeTopologyViews nodeTopologyViews = new NodeTopologyViews(Arrays.asList(localhostView, otherhostView));
Set<RedisURI> clusterNodes = nodeTopologyViews.getClusterNodes();
assertThat(clusterNodes).contains(localhost, otherhost, host3);
}
示例8: shouldCreateTopologyView
import com.lambdaworks.redis.RedisURI; //导入方法依赖的package包/类
@Test
public void shouldCreateTopologyView() throws Exception {
RedisURI redisURI = RedisURI.create("localhost", 6379);
Requests clusterNodesRequests = new Requests();
String clusterNodesOutput = "1 127.0.0.1:7380 master,myself - 0 1401258245007 2 disconnected 8000-11999\n";
clusterNodesRequests.addRequest(redisURI, getCommand(clusterNodesOutput));
Requests clientListRequests = new Requests();
String clientListOutput = "id=2 addr=127.0.0.1:58919 fd=6 name= age=3 idle=0 flags=N db=0 sub=0 psub=0 multi=-1 qbuf=0 qbuf-free=32768 obl=0 oll=0 omem=0 events=r cmd=client\n";
clientListRequests.addRequest(redisURI, getCommand(clientListOutput));
NodeTopologyView nodeTopologyView = NodeTopologyView.from(redisURI, clusterNodesRequests, clientListRequests);
assertThat(nodeTopologyView.isAvailable()).isTrue();
assertThat(nodeTopologyView.getConnectedClients()).isEqualTo(1);
assertThat(nodeTopologyView.getPartitions()).hasSize(1);
assertThat(nodeTopologyView.getClusterNodes()).isEqualTo(clusterNodesOutput);
assertThat(nodeTopologyView.getClientList()).isEqualTo(clientListOutput);
}
示例9: shouldCreateTopologyViewWithoutClientCount
import com.lambdaworks.redis.RedisURI; //导入方法依赖的package包/类
@Test
public void shouldCreateTopologyViewWithoutClientCount() throws Exception {
RedisURI redisURI = RedisURI.create("localhost", 6379);
Requests clusterNodesRequests = new Requests();
String clusterNodesOutput = "1 127.0.0.1:7380 master,myself - 0 1401258245007 2 disconnected 8000-11999\n";
clusterNodesRequests.addRequest(redisURI, getCommand(clusterNodesOutput));
Requests clientListRequests = new Requests();
NodeTopologyView nodeTopologyView = NodeTopologyView.from(redisURI, clusterNodesRequests, clientListRequests);
assertThat(nodeTopologyView.isAvailable()).isFalse();
assertThat(nodeTopologyView.getConnectedClients()).isEqualTo(0);
assertThat(nodeTopologyView.getPartitions()).isEmpty();
assertThat(nodeTopologyView.getClusterNodes()).isNull();
}
示例10: createClusterNodesRequests
import com.lambdaworks.redis.RedisURI; //导入方法依赖的package包/类
protected Requests createClusterNodesRequests(int duration, String nodes) {
RedisURI redisURI = RedisURI.create("redis://localhost:" + duration);
Connections connections = new Connections();
connections.addConnection(redisURI, connection);
Requests requests = connections.requestTopology();
TimedAsyncCommand<String, String, String> command = requests.getRequest(redisURI);
command.getOutput().set(ByteBuffer.wrap(nodes.getBytes()));
command.complete();
command.encodedAtNs = 0;
command.completedAtNs = duration;
return requests;
}
示例11: init
import com.lambdaworks.redis.RedisURI; //导入方法依赖的package包/类
@Override
public void init(AbstractConfiguration config) {
if (!config.getString("redis.type").equals("master_slave")) {
throw new IllegalStateException("RedisSyncSingleStorage class can only be used with master slave redis setup, but redis.type value is " + config.getString("redis.type"));
}
List<String> address = parseRedisAddress(config.getString("redis.address"), 6379);
int databaseNumber = config.getInt("redis.database", 0);
String password = StringUtils.isNotEmpty(config.getString("redis.password")) ? config.getString("redis.password") + "@" : "";
// lettuce
RedisURI lettuceURI = RedisURI.create("redis://" + password + address.get(0) + "/" + databaseNumber);
this.lettuceMasterSlave = RedisClient.create(lettuceURI);
this.lettuceMasterSlaveConn = MasterSlave.connect(this.lettuceMasterSlave, new Utf8StringCodec(), lettuceURI);
this.lettuceMasterSlaveConn.setReadFrom(ReadFrom.valueOf(config.getString("redis.read")));
// redisson
String masterNode = address.get(0);
String[] slaveNodes = address.subList(1, address.size()).toArray(new String[address.size() - 1]);
Config redissonConfig = new Config();
redissonConfig.useMasterSlaveServers()
.setMasterAddress(masterNode)
.setLoadBalancer(new RoundRobinLoadBalancer())
.addSlaveAddress(slaveNodes)
.setReadMode(ReadMode.MASTER)
.setDatabase(databaseNumber)
.setPassword(StringUtils.isNotEmpty(password) ? password : null);
this.redisson = Redisson.create(redissonConfig);
// params
initParams(config);
}
示例12: init
import com.lambdaworks.redis.RedisURI; //导入方法依赖的package包/类
@Override
public void init(AbstractConfiguration config) {
if (!config.getString("redis.type").equals("cluster")) {
throw new IllegalStateException("RedisSyncSingleStorage class can only be used with cluster redis setup, but redis.type value is " + config.getString("redis.type"));
}
List<String> address = parseRedisAddress(config.getString("redis.address"), 6379);
int databaseNumber = config.getInt("redis.database", 0);
String password = StringUtils.isNotEmpty(config.getString("redis.password")) ? config.getString("redis.password") + "@" : "";
// lettuce
RedisURI lettuceURI = RedisURI.create("redis://" + password + address.get(0) + "/" + databaseNumber);
this.lettuceCluster = RedisClusterClient.create(lettuceURI);
this.lettuceCluster.setOptions(new ClusterClientOptions.Builder()
.refreshClusterView(true)
.refreshPeriod(1, TimeUnit.MINUTES)
.build());
this.lettuceClusterConn = this.lettuceCluster.connect();
this.lettuceClusterConn.setReadFrom(ReadFrom.valueOf(config.getString("redis.read")));
// redisson
Config redissonConfig = new Config();
redissonConfig.useClusterServers()
.setScanInterval(60000)
.addNodeAddress(address.toArray(new String[address.size()]))
.setReadMode(ReadMode.MASTER)
.setPassword(StringUtils.isNotEmpty(password) ? password : null);
this.redisson = Redisson.create(redissonConfig);
// params
initParams(config);
}
示例13: init
import com.lambdaworks.redis.RedisURI; //导入方法依赖的package包/类
@Override
public void init(AbstractConfiguration config) {
if (!config.getString("redis.type").equals("sentinel")) {
throw new IllegalStateException("RedisSyncSingleStorage class can only be used with sentinel redis setup, but redis.type value is " + config.getString("redis.type"));
}
List<String> address = parseRedisAddress(config.getString("redis.address"), 26379);
int databaseNumber = config.getInt("redis.database", 0);
String password = StringUtils.isNotEmpty(config.getString("redis.password")) ? config.getString("redis.password") + "@" : "";
String masterId = config.getString("redis.master");
// lettuce
RedisURI lettuceURI = RedisURI.create("redis-sentinel://" + password + String.join(",", address) + "/" + databaseNumber + "#" + masterId);
this.lettuceSentinel = RedisClient.create(lettuceURI);
this.lettuceSentinelConn = MasterSlave.connect(this.lettuceSentinel, new Utf8StringCodec(), lettuceURI);
this.lettuceSentinelConn.setReadFrom(ReadFrom.valueOf(config.getString("redis.read")));
// redisson
Config redissonConfig = new Config();
redissonConfig.useSentinelServers()
.setMasterName(masterId)
.addSentinelAddress(address.toArray(new String[address.size()]))
.setReadMode(ReadMode.MASTER)
.setDatabase(databaseNumber)
.setPassword(StringUtils.isNotEmpty(password) ? password : null);
this.redisson = Redisson.create(redissonConfig);
// params
initParams(config);
}
示例14: testCluster
import com.lambdaworks.redis.RedisURI; //导入方法依赖的package包/类
@Test
public void testCluster() {
if (!RedisLettuceCacheTest.checkOS()) {
return;
}
RedisURI node1 = RedisURI.create("127.0.0.1", 7000);
RedisURI node2 = RedisURI.create("127.0.0.1", 7001);
RedisURI node3 = RedisURI.create("127.0.0.1", 7002);
RedisClusterClient client = RedisClusterClient.create(Arrays.asList(node1, node2, node3));
LettuceConnectionManager m = LettuceConnectionManager.defaultManager();
Assert.assertSame(m.commands(client), m.commands(client));
Assert.assertSame(m.asyncCommands(client), m.asyncCommands(client));
Assert.assertSame(m.reactiveCommands(client), m.reactiveCommands(client));
m.removeAndClose(client);
}
示例15: testCluster
import com.lambdaworks.redis.RedisURI; //导入方法依赖的package包/类
@Test
public void testCluster() throws Exception {
if (!checkOS()) {
return;
}
RedisURI node1 = RedisURI.create("127.0.0.1", 7000);
RedisURI node2 = RedisURI.create("127.0.0.1", 7001);
RedisURI node3 = RedisURI.create("127.0.0.1", 7002);
RedisClusterClient client = RedisClusterClient.create(Arrays.asList(node1, node2, node3));
test(client);
}