Java Code Examples for com.lambdaworks.redis.RedisClient#create()

The following examples show how to use com.lambdaworks.redis.RedisClient#create() . 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: DoTestLettuceHookProxy.java    From uavstack with Apache License 2.0 6 votes vote down vote up
private static void testAsync() {

        System.out.println("TEST Lettuce async ======================================================");
        RedisClient client = RedisClient.create("redis://localhost:6379/0");
        RedisAsyncConnection<String, String> conn = client.connectAsync();
        conn.set("foo", "bar");

        conn.get("foo");

        conn.lpush("lll", "a");
        conn.lpush("lll", "b");
        conn.lpush("lll", "c");
        conn.lpop("lll");
        conn.lpop("lll");
        conn.lpop("lll");

        conn.hset("mmm", "abc", "123");
        conn.hset("mmm", "def", "456");
        conn.hgetall("mmm");

        conn.del("foo", "lll", "mmm");

        conn.close();
        client.shutdown();
    }
 
Example 2
Source File: RedisLettuceService.java    From samantha with MIT License 6 votes vote down vote up
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");
}
 
Example 3
Source File: RedisSyncSingleStorageImpl.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("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);
}
 
Example 4
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 5
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 6
Source File: DoTestLettuceHookProxy.java    From uavstack with Apache License 2.0 5 votes vote down vote up
private static void testSync() {

        System.out.println("TEST Lettuce sync ======================================================");
        RedisClient redisClient = RedisClient.create("redis://localhost:6379/0");
        RedisConnection<String, String> conn = redisClient.connect();

        System.out.println("Connected to Redis");

        conn.set("foo", "bar");
        String value = conn.get("foo");
        System.out.println(value);

        conn.close();
        redisClient.shutdown();
    }
 
Example 7
Source File: RedisCacheServiceBuilder.java    From registry with Apache License 2.0 5 votes vote down vote up
private Factory<RedisConnection> getRedisConnectionFactory() {
    final ConnectionConfig.RedisConnectionConfig connectionConfig = (ConnectionConfig.RedisConnectionConfig) cacheConfig.getConnectionConfig();

    if (connectionConfig != null) {
        if (connectionConfig.getPool() != null) {
            return new RedisConnectionPoolFactory(RedisClient.create(getRedisUri()), getRedisCodec());
        } else {
            return new RedisConnectionFactory(RedisClient.create(getRedisUri()), getRedisCodec());
        }
    }
    return null;
}
 
Example 8
Source File: RedisCacheTestMain.java    From registry with Apache License 2.0 5 votes vote down vote up
private static void setConnection() {
//        RedisClient redisClient = RedisClient.create(new RedisURI("127.0.0.1", 6379, 10L, TimeUnit.SECONDS));
        RedisClient redisClient = RedisClient.create("redis://127.0.0.1:6379");
//        RedisClient redisClient = RedisClient.create(new RedisURI.Builder.redis("127.0.0.1", 6379).build());
        connection = redisClient.connect();
        connection1 = redisClient.connect();
    }
 
Example 9
Source File: RedisCacheServiceBuilder.java    From streamline with Apache License 2.0 5 votes vote down vote up
private Factory<RedisConnection> getRedisConnectionFactory() {
    final ConnectionConfig.RedisConnectionConfig connectionConfig = (ConnectionConfig.RedisConnectionConfig) cacheConfig.getConnectionConfig();

    if (connectionConfig != null) {
        if (connectionConfig.getPool() != null) {
            return new RedisConnectionPoolFactory(RedisClient.create(getRedisUri()), getRedisCodec());
        } else {
            return new RedisConnectionFactory(RedisClient.create(getRedisUri()), getRedisCodec());
        }
    }
    return null;
}
 
Example 10
Source File: RedisCacheTestMain.java    From streamline with Apache License 2.0 5 votes vote down vote up
private static void setConnection() {
//        RedisClient redisClient = RedisClient.create(new RedisURI("127.0.0.1", 6379, 10L, TimeUnit.SECONDS));
        RedisClient redisClient = RedisClient.create("redis://127.0.0.1:6379");
//        RedisClient redisClient = RedisClient.create(new RedisURI.Builder.redis("127.0.0.1", 6379).build());
        connection = redisClient.connect();
        connection1 = redisClient.connect();
    }
 
Example 11
Source File: Lettuce4InstrumentationTest.java    From apm-agent-java with Apache License 2.0 4 votes vote down vote up
@Before
public void setUpLettuce() {
    client = RedisClient.create("redis://localhost:" + redisPort);
    connection = client.connect();
    reporter.disableDestinationAddressCheck();
}
 
Example 12
Source File: RedisAsyncCommanderProvider.java    From EasyTransaction with Apache License 2.0 4 votes vote down vote up
public RedisAsyncCommanderProvider(String uri){
	RedisClient client = RedisClient.create(uri);
	StatefulRedisConnection<String, byte[]> connect = client.connect(getCodec());
	cmd = connect.async();
}