本文整理汇总了Java中com.lambdaworks.redis.ReadFrom类的典型用法代码示例。如果您正苦于以下问题:Java ReadFrom类的具体用法?Java ReadFrom怎么用?Java ReadFrom使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ReadFrom类属于com.lambdaworks.redis包,在下文中一共展示了ReadFrom类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: init
import com.lambdaworks.redis.ReadFrom; //导入依赖的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.ReadFrom; //导入依赖的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);
}
示例3: main
import com.lambdaworks.redis.ReadFrom; //导入依赖的package包/类
public static void main(String[] args) {
// Syntax: redis://[[email protected]]host[:port][/databaseNumber]
RedisClient redisClient = RedisClient.create();
List<RedisURI> nodes = Arrays.asList(RedisURI.create("redis://host1"),
RedisURI.create("redis://host2"),
RedisURI.create("redis://host3"));
StatefulRedisMasterSlaveConnection<String, String> connection = MasterSlave
.connect(redisClient, new Utf8StringCodec(), nodes);
connection.setReadFrom(ReadFrom.MASTER_PREFERRED);
System.out.println("Connected to Redis");
connection.close();
redisClient.shutdown();
}
示例4: init
import com.lambdaworks.redis.ReadFrom; //导入依赖的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);
}
示例5: init
import com.lambdaworks.redis.ReadFrom; //导入依赖的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);
}
示例6: init
import com.lambdaworks.redis.ReadFrom; //导入依赖的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);
}
示例7: init
import com.lambdaworks.redis.ReadFrom; //导入依赖的package包/类
@Override
public void init(AbstractConfiguration config) {
if (!config.getString("redis.type").equals("cluster")) {
throw new IllegalStateException("RedisSyncSingleStorageImpl 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(ClusterClientOptions.builder()
.topologyRefreshOptions(ClusterTopologyRefreshOptions.builder()
.enablePeriodicRefresh(config.getBoolean("redis.cluster.periodicRefreshEnabled", ClusterTopologyRefreshOptions.DEFAULT_PERIODIC_REFRESH_ENABLED))
.refreshPeriod(config.getLong("redis.cluster.refreshPeriod", ClusterTopologyRefreshOptions.DEFAULT_REFRESH_PERIOD), TimeUnit.SECONDS)
.closeStaleConnections(config.getBoolean("redis.cluster.closeStaleConnections", ClusterTopologyRefreshOptions.DEFAULT_CLOSE_STALE_CONNECTIONS))
.build())
.validateClusterNodeMembership(config.getBoolean("redis.cluster.validateClusterNodeMembership", ClusterClientOptions.DEFAULT_VALIDATE_CLUSTER_MEMBERSHIP))
.maxRedirects(config.getInt("redis.cluster.refreshPeriod", ClusterClientOptions.DEFAULT_MAX_REDIRECTS))
.build());
this.lettuceClusterConn = this.lettuceCluster.connect();
this.lettuceClusterConn.setReadFrom(ReadFrom.valueOf(config.getString("redis.read")));
// params
initParams(config);
}
示例8: main
import com.lambdaworks.redis.ReadFrom; //导入依赖的package包/类
public static void main(String[] args) {
// Syntax: redis-sentinel://[[email protected]]host[:port][,host2[:port2]][/databaseNumber]#sentinelMasterId
RedisClient redisClient = RedisClient.create();
StatefulRedisMasterSlaveConnection<String, String> connection = MasterSlave.connect(redisClient, new Utf8StringCodec(),
RedisURI.create("redis-sentinel://localhost:26379,localhost:26380/0#mymaster"));
connection.setReadFrom(ReadFrom.MASTER_PREFERRED);
System.out.println("Connected to Redis");
connection.close();
redisClient.shutdown();
}
示例9: getNodes
import com.lambdaworks.redis.ReadFrom; //导入依赖的package包/类
private ReadFrom.Nodes getNodes() {
return new ReadFrom.Nodes() {
@Override
public List<RedisNodeDescription> getNodes() {
return (List) sut.getPartitions();
}
@Override
public Iterator<RedisNodeDescription> iterator() {
return getNodes().iterator();
}
};
}
示例10: readWriteMaster
import com.lambdaworks.redis.ReadFrom; //导入依赖的package包/类
@Test
public void readWriteMaster() {
connection.setReadFrom(ReadFrom.MASTER);
sync.set(key, value);
assertThat(sync.get(key)).isEqualTo(value);
}
示例11: readWriteMasterPreferred
import com.lambdaworks.redis.ReadFrom; //导入依赖的package包/类
@Test
public void readWriteMasterPreferred() {
connection.setReadFrom(ReadFrom.MASTER_PREFERRED);
sync.set(key, value);
assertThat(sync.get(key)).isEqualTo(value);
}
示例12: getConnection
import com.lambdaworks.redis.ReadFrom; //导入依赖的package包/类
/**
* Retrieve a {@link StatefulRedisConnection} by the intent.
* {@link com.lambdaworks.redis.masterslave.MasterSlaveConnectionProvider.Intent#WRITE} intentions use the master
* connection, {@link com.lambdaworks.redis.masterslave.MasterSlaveConnectionProvider.Intent#READ} intentions lookup one or
* more read candidates using the {@link ReadFrom} setting.
*
* @param intent command intent
* @return the connection.
*/
public StatefulRedisConnection<K, V> getConnection(Intent intent) {
if (debugEnabled) {
logger.debug("getConnection(" + intent + ")");
}
if (readFrom != null && intent == Intent.READ) {
List<RedisNodeDescription> selection = readFrom.select(new ReadFrom.Nodes() {
@Override
public List<RedisNodeDescription> getNodes() {
return knownNodes;
}
@Override
public Iterator<RedisNodeDescription> iterator() {
return knownNodes.iterator();
}
});
if (selection.isEmpty()) {
throw new RedisException(String.format("Cannot determine a node to read (Known nodes: %s) with setting %s",
knownNodes, readFrom));
}
try {
for (RedisNodeDescription redisNodeDescription : selection) {
StatefulRedisConnection<K, V> readerCandidate = getConnection(redisNodeDescription);
if (!readerCandidate.isOpen()) {
continue;
}
return readerCandidate;
}
return getConnection(selection.get(0));
} catch (RuntimeException e) {
throw new RedisException(e);
}
}
return getConnection(getMaster());
}
示例13: getReadFrom
import com.lambdaworks.redis.ReadFrom; //导入依赖的package包/类
public ReadFrom getReadFrom() {
return readFrom;
}
示例14: setReadFrom
import com.lambdaworks.redis.ReadFrom; //导入依赖的package包/类
public void setReadFrom(ReadFrom readFrom) {
synchronized (stateLock) {
this.readFrom = readFrom;
}
}
示例15: setReadFrom
import com.lambdaworks.redis.ReadFrom; //导入依赖的package包/类
@Override
public void setReadFrom(ReadFrom readFrom) {
getChannelWriter().setReadFrom(readFrom);
}