當前位置: 首頁>>代碼示例>>Java>>正文


Java ReadFrom類代碼示例

本文整理匯總了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);
}
 
開發者ID:longkerdandy,項目名稱:mithqtt,代碼行數:20,代碼來源:RedisSyncMasterSlaveStorageImpl.java

示例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);
}
 
開發者ID:longkerdandy,項目名稱:mithqtt,代碼行數:21,代碼來源:RedisSyncSentinelStorageImpl.java

示例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();
    }
 
開發者ID:lettuce-io,項目名稱:lettuce-core,代碼行數:19,代碼來源:ConnectToMasterSlaveUsingElastiCacheCluster.java

示例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);
}
 
開發者ID:12315jack,項目名稱:j1st-mqtt,代碼行數:33,代碼來源:RedisSyncMasterSlaveStorage.java

示例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);
}
 
開發者ID:12315jack,項目名稱:j1st-mqtt,代碼行數:33,代碼來源:RedisSyncClusterStorage.java

示例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);
}
 
開發者ID:12315jack,項目名稱:j1st-mqtt,代碼行數:31,代碼來源:RedisSyncSentinelStorage.java

示例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);
}
 
開發者ID:longkerdandy,項目名稱:mithqtt,代碼行數:29,代碼來源:RedisSyncClusterStorageImpl.java

示例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();
}
 
開發者ID:lettuce-io,項目名稱:lettuce-core,代碼行數:14,代碼來源:ConnectToMasterSlaveUsingRedisSentinel.java

示例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();
        }
    };

}
 
開發者ID:lettuce-io,項目名稱:lettuce-core,代碼行數:15,代碼來源:ReadFromTest.java

示例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);
}
 
開發者ID:lettuce-io,項目名稱:lettuce-core,代碼行數:9,代碼來源:RedisClusterReadFromTest.java

示例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);
}
 
開發者ID:lettuce-io,項目名稱:lettuce-core,代碼行數:9,代碼來源:RedisClusterReadFromTest.java

示例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());
}
 
開發者ID:lettuce-io,項目名稱:lettuce-core,代碼行數:50,代碼來源:MasterSlaveConnectionProvider.java

示例13: getReadFrom

import com.lambdaworks.redis.ReadFrom; //導入依賴的package包/類
public ReadFrom getReadFrom() {
    return readFrom;
}
 
開發者ID:lettuce-io,項目名稱:lettuce-core,代碼行數:4,代碼來源:MasterSlaveConnectionProvider.java

示例14: setReadFrom

import com.lambdaworks.redis.ReadFrom; //導入依賴的package包/類
public void setReadFrom(ReadFrom readFrom) {
    synchronized (stateLock) {
        this.readFrom = readFrom;
    }
}
 
開發者ID:lettuce-io,項目名稱:lettuce-core,代碼行數:6,代碼來源:MasterSlaveConnectionProvider.java

示例15: setReadFrom

import com.lambdaworks.redis.ReadFrom; //導入依賴的package包/類
@Override
public void setReadFrom(ReadFrom readFrom) {
    getChannelWriter().setReadFrom(readFrom);
}
 
開發者ID:lettuce-io,項目名稱:lettuce-core,代碼行數:5,代碼來源:StatefulRedisMasterSlaveConnectionImpl.java


注:本文中的com.lambdaworks.redis.ReadFrom類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。