com.lambdaworks.redis.codec.Utf8StringCodec Java Examples

The following examples show how to use com.lambdaworks.redis.codec.Utf8StringCodec. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: RedisSyncSentinelStorageImpl.java    From mithqtt with Apache License 2.0 6 votes vote down vote up
@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);
}
 
Example #2
Source File: RedisSyncMasterSlaveStorageImpl.java    From mithqtt with Apache License 2.0 6 votes vote down vote up
@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);
}
 
Example #3
Source File: ClientTest.java    From spinach with Apache License 2.0 6 votes vote down vote up
@Test
public void connectWithHelloClusterConnectionStrategy() throws Exception {

    DisqueURI disqueURI = DisqueURI.Builder.disque(host, port).build();

    DisqueConnection<String, String> connect = client.connect(new Utf8StringCodec(), disqueURI,
            SocketAddressSupplierFactory.Factories.HELLO_CLUSTER);

    // initial address
    assertThat(connect.sync().info("server")).contains("tcp_port:" + port);
    connect.sync().quit();

    // obtained from cluster, may be the same
    assertThat(connect.sync().info("server")).contains("tcp_port:" + port);
    connect.sync().quit();

    // obtained from cluster, second cluster node
    assertThat(connect.sync().info("server")).contains("tcp_port:" + TestSettings.port(1));

    connect.close();
}
 
Example #4
Source File: RedisCacheServiceBuilder.java    From registry with Apache License 2.0 5 votes vote down vote up
private RedisCodec getRedisCodec() {
    final String codec = cacheConfig.getCacheEntry().getCodec();
    if (codec != null) {
        return new Utf8StringCodec();
    } else {
        try {
            return ReflectionHelper.newInstance(codec);
        } catch (Exception e) {
            throw new RuntimeException("Exception occurred creating codec", e);
        }
    }
}
 
Example #5
Source File: QueueListenerFactoryTest.java    From spinach with Apache License 2.0 5 votes vote down vote up
@Test
public void sharedRedisClient() throws Exception {

    QueueListenerFactory sharedClientListener = QueueListenerFactory.create(client, Schedulers.io(), disqueURI0,
            new Utf8StringCodec(), queue);
    sharedClientListener.getjobs(10, TimeUnit.MILLISECONDS, 1).subscribe(subscriber);

    createJobs(connection0);
    waitForSomeReceivedJobs();

    sharedClientListener.shutdown();
}
 
Example #6
Source File: RedisCacheServiceBuilder.java    From streamline with Apache License 2.0 5 votes vote down vote up
private RedisCodec getRedisCodec() {
    final String codec = cacheConfig.getCacheEntry().getCodec();
    if (codec != null) {
        return new Utf8StringCodec();
    } else {
        try {
            return ReflectionHelper.newInstance(codec);
        } catch (Exception e) {
            throw new RuntimeException("Exception occurred creating codec", e);
        }
    }
}
 
Example #7
Source File: DisqueClient.java    From spinach with Apache License 2.0 2 votes vote down vote up
/**
 * Open a new connection to a Disque server that treats keys and values as UTF-8 strings. This method requires to have the
 * {@link DisqueURI} specified when constructing the client. Command timeouts are applied from the default
 * {@link #setDefaultTimeout(long, TimeUnit)} settings.
 *
 * @return A new connection.
 */
public DisqueConnection<String, String> connect() {
    return connect(new Utf8StringCodec());
}
 
Example #8
Source File: DisqueClient.java    From spinach with Apache License 2.0 2 votes vote down vote up
/**
 * Open a new connection to a Disque server with the supplied {@link DisqueURI} that treats keys and values as UTF-8
 * strings. Command timeouts are applied from the given {@link DisqueURI#getTimeout()} settings.
 *
 * @param disqueURI the disque server to connect to, must not be {@literal null}
 * @return A new connection.
 */
public DisqueConnection<String, String> connect(DisqueURI disqueURI) {
    return connect(new Utf8StringCodec(), disqueURI, SocketAddressSupplierFactory.Factories.ROUND_ROBIN);
}