本文整理汇总了Java中com.lambdaworks.redis.RedisURI类的典型用法代码示例。如果您正苦于以下问题:Java RedisURI类的具体用法?Java RedisURI怎么用?Java RedisURI使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
RedisURI类属于com.lambdaworks.redis包,在下文中一共展示了RedisURI类的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: connect
import com.lambdaworks.redis.RedisURI; //导入依赖的package包/类
/**
* Connects to the Redis server.
* @param configuration The configuration object.
* @throws Exception If an error occurs.
*/
public void connect(Configuration configuration) throws Exception {
if(sync != null) {
return;
}
RedisURI.Builder uri = RedisURI.Builder.redis(configuration.getRedisHost(), configuration.getRedisPort())
.withDatabase(configuration.getRedisIndex());
if(!configuration.getRedisAuth().isEmpty()) {
uri.withPassword(configuration.getRedisAuth());
}
RedisClient client = RedisClient.create(uri.build());
StatefulRedisConnection<String, String> connection = client.connect();
sync = connection.sync();
for(Category category : Category.values()) {
logger.info("Registered the category {} with the type {}.", category, category.getEntry().getType());
category.getEntry().setCategory(category);
}
}
示例3: startUp
import com.lambdaworks.redis.RedisURI; //导入依赖的package包/类
private void startUp() {
logger.info("Starting RedisLettuceService");
{
logger.debug("Redis settings:");
logger.debug("* host={}", cfgHost);
logger.debug("* port={}", cfgPort);
logger.debug("* db={}", cfgDb);
}
RedisURI redisURI = new RedisURI();
redisURI.setHost(cfgHost);
redisURI.setPort(cfgPort);
redisURI.setDatabase(cfgDb);
client = RedisClient.create(redisURI);
connection = client.connect();
asyncConnection = client.connect();
syncCommands = connection.sync();
asyncCommands = asyncConnection.async();
asyncConnection.setAutoFlushCommands(false);
logger.info("Connected to a redis client");
}
示例4: findRedisConnection
import com.lambdaworks.redis.RedisURI; //导入依赖的package包/类
private static RedisClient findRedisConnection(String host, int port) {
ClientResources clientResources = DefaultClientResources.builder()//
.reconnectDelay(Delay.constant(10, TimeUnit.SECONDS))//
.build();
RedisURI redisUri = new RedisURI(host, port, 2, TimeUnit.SECONDS);
ClientOptions clientOptions = ClientOptions.builder() //
.disconnectedBehavior(DisconnectedBehavior.REJECT_COMMANDS)//
.build();
RedisClient redis = RedisClient.create(clientResources, redisUri);
redis.setOptions(clientOptions);
return redis;
}
示例5: createRedisClient
import com.lambdaworks.redis.RedisURI; //导入依赖的package包/类
private RedisClient createRedisClient(String host, int port) {
RedisURI redisUri = new RedisURI(host, port, 2, TimeUnit.SECONDS);
SocketOptions socketOptions = SocketOptions.builder()
.connectTimeout(XPipeConsoleConstant.SOCKET_TIMEOUT, TimeUnit.SECONDS)
.build();
ClientOptions clientOptions = ClientOptions.builder() //
.socketOptions(socketOptions)
.disconnectedBehavior(ClientOptions.DisconnectedBehavior.REJECT_COMMANDS)//
.build();
DefaultClientResources clientResources = DefaultClientResources.builder()//
.reconnectDelay(Delay.constant(1, TimeUnit.SECONDS))//
.build();
RedisClient redis = RedisClient.create(clientResources, redisUri);
redis.setOptions(clientOptions);
return redis;
}
示例6: 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);
}
示例7: 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);
}
示例8: apply
import com.lambdaworks.redis.RedisURI; //导入依赖的package包/类
@Override
public StatefulRedisConnection<K, V> apply(ConnectionKey key) {
RedisURI.Builder builder = RedisURI.Builder
.redis(key.host, key.port)
.withSsl(initialRedisUri.isSsl())
.withVerifyPeer(initialRedisUri.isVerifyPeer())
.withStartTls(initialRedisUri.isStartTls());
if (initialRedisUri.getPassword() != null && initialRedisUri.getPassword().length != 0) {
builder.withPassword(initialRedisUri.getPassword());
}
if (initialRedisUri.getClientName() != null) {
builder.withClientName(initialRedisUri.getClientName());
}
builder.withDatabase(initialRedisUri.getDatabase());
StatefulRedisConnection<K, V> connection = redisClient.connect(redisCodec, builder.build());
synchronized (stateLock) {
connection.setAutoFlushCommands(autoFlushCommands);
}
return connection;
}
示例9: connect
import com.lambdaworks.redis.RedisURI; //导入依赖的package包/类
/**
* Open a new connection to a Redis Master-Slave server/servers using the supplied {@link RedisURI} and the supplied
* {@link RedisCodec codec} to encode/decode keys.
* <p>
* This {@link MasterSlave} performs auto-discovery of nodes if the URI is a Redis Sentinel URI. Master/Slave URIs will be
* treated as static topology and no additional hosts are discovered in such case. Redis Standalone Master/Slave will
* discover the roles of the supplied {@link RedisURI URIs} and issue commands to the appropriate node.
* </p>
*
* @param redisClient the Redis client
* @param codec Use this codec to encode/decode keys and values, must not be {@literal null}
* @param redisURIs the Redis server to connect to, must not be {@literal null}
* @param <K> Key type
* @param <V> Value type
* @return A new connection
*/
public static <K, V> StatefulRedisMasterSlaveConnection<K, V> connect(RedisClient redisClient, RedisCodec<K, V> codec,
Iterable<RedisURI> redisURIs) {
LettuceAssert.notNull(redisClient, "RedisClient must not be null");
LettuceAssert.notNull(codec, "RedisCodec must not be null");
LettuceAssert.notNull(redisURIs, "RedisURIs must not be null");
List<RedisURI> uriList = LettuceLists.newList(redisURIs);
LettuceAssert.isTrue(!uriList.isEmpty(), "RedisURIs must not be empty");
if (isSentinel(uriList.get(0))) {
return connectSentinel(redisClient, codec, uriList.get(0));
} else {
return connectStaticMasterSlave(redisClient, codec, uriList);
}
}
示例10: RedisMasterSlaveNode
import com.lambdaworks.redis.RedisURI; //导入依赖的package包/类
RedisMasterSlaveNode(String host, int port, RedisURI seed, Role role) {
RedisURI.Builder builder = RedisURI.Builder
.redis(host, port)
.withSsl(seed.isSsl())
.withVerifyPeer(seed.isVerifyPeer())
.withStartTls(seed.isStartTls());
if (seed.getPassword() != null && seed.getPassword().length != 0) {
builder.withPassword(new String(seed.getPassword()));
}
if (seed.getClientName() != null) {
builder.withClientName(seed.getClientName());
}
builder.withDatabase(seed.getDatabase());
this.redisURI = builder.build();
this.role = role;
}
示例11: requestPing
import com.lambdaworks.redis.RedisURI; //导入依赖的package包/类
public Requests requestPing() {
Requests requests = new Requests();
for (Map.Entry<RedisURI, StatefulRedisConnection<String, String>> entry : connections.entrySet()) {
CommandArgs<String, String> args = new CommandArgs<>(StringCodec.ASCII).add(CommandKeyword.NODES);
Command<String, String, String> command = new Command<>(CommandType.PING, new StatusOutput<>(StringCodec.ASCII),
args);
TimedAsyncCommand<String, String, String> timedCommand = new TimedAsyncCommand<>(command);
entry.getValue().dispatch(timedCommand);
requests.addRequest(entry.getKey(), timedCommand);
}
return requests;
}
示例12: shouldNotFailOnDuplicateSeedNodes
import com.lambdaworks.redis.RedisURI; //导入依赖的package包/类
@Test
public void shouldNotFailOnDuplicateSeedNodes() throws Exception {
List<RedisURI> seed = Arrays.asList(RedisURI.create("127.0.0.1", 7380), RedisURI.create("127.0.0.1", 7381),
RedisURI.create("127.0.0.1", 7381));
when(nodeConnectionFactory.connectToNodeAsync(any(RedisCodec.class), eq(new InetSocketAddress("127.0.0.1", 7380))))
.thenReturn(completedFuture((StatefulRedisConnection) connection1));
when(nodeConnectionFactory.connectToNodeAsync(any(RedisCodec.class), eq(new InetSocketAddress("127.0.0.1", 7381))))
.thenReturn(completedFuture((StatefulRedisConnection) connection2));
sut.loadViews(seed, true);
verify(nodeConnectionFactory).connectToNodeAsync(any(RedisCodec.class), eq(new InetSocketAddress("127.0.0.1", 7380)));
verify(nodeConnectionFactory).connectToNodeAsync(any(RedisCodec.class), eq(new InetSocketAddress("127.0.0.1", 7381)));
}
示例13: 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;
}
示例14: requestTopology
import com.lambdaworks.redis.RedisURI; //导入依赖的package包/类
public Requests requestTopology() {
Requests requests = new Requests();
for (Map.Entry<RedisURI, StatefulRedisConnection<String, String>> entry : connections.entrySet()) {
CommandArgs<String, String> args = new CommandArgs<>(StringCodec.UTF8).add(CommandKeyword.NODES);
Command<String, String, String> command = new Command<>(CommandType.CLUSTER, new StatusOutput<>(StringCodec.UTF8),
args);
TimedAsyncCommand<String, String, String> timedCommand = new TimedAsyncCommand<>(command);
entry.getValue().dispatch(timedCommand);
requests.addRequest(entry.getKey(), timedCommand);
}
return requests;
}
示例15: requestClients
import com.lambdaworks.redis.RedisURI; //导入依赖的package包/类
public Requests requestClients() {
Requests requests = new Requests();
for (Map.Entry<RedisURI, StatefulRedisConnection<String, String>> entry : connections.entrySet()) {
CommandArgs<String, String> args = new CommandArgs<>(StringCodec.UTF8).add(CommandKeyword.LIST);
Command<String, String, String> command = new Command<>(CommandType.CLIENT, new StatusOutput<>(StringCodec.UTF8),
args);
TimedAsyncCommand<String, String, String> timedCommand = new TimedAsyncCommand<>(command);
entry.getValue().dispatch(timedCommand);
requests.addRequest(entry.getKey(), timedCommand);
}
return requests;
}