com.lambdaworks.redis.RedisClient Java Examples

The following examples show how to use com.lambdaworks.redis.RedisClient. 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: RedisGetSetClient.java    From moleculer-java with MIT License 6 votes vote down vote up
@Override
public final void connect() {
	super.connect();
	List<RedisURI> redisURIs = parseURLs(urls, password, secure);
	ByteArrayCodec codec = new ByteArrayCodec();
	if (urls.length > 1) {

		// Clustered client
		clusteredClient = RedisClusterClient.create(resources, redisURIs).connect(codec).async();

	} else {

		// Single server connection
		client = RedisClient.create(resources, redisURIs.get(0)).connect(codec).async();
	}
}
 
Example #3
Source File: RedisPubSubClient.java    From moleculer-java with MIT License 6 votes vote down vote up
public final void connect() {
	super.connect();
	List<RedisURI> redisURIs = parseURLs(urls, password, secure);
	StatefulRedisPubSubConnection<byte[], byte[]> connection;
	ByteArrayCodec codec = new ByteArrayCodec();
	if (urls.length > 1) {

		// Clustered client
		connection = RedisClusterClient.create(resources, redisURIs).connectPubSub(codec);

	} else {

		// Single connection
		connection = RedisClient.create(resources, redisURIs.get(0)).connectPubSub(codec);
	}

	// Add listener
	if (listener != null) {
		connection.addListener(listener);
	}
	client = connection.async();
}
 
Example #4
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 #5
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 #6
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 #7
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 #8
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 #9
Source File: RedissonDemo.java    From dyno with Apache License 2.0 5 votes vote down vote up
RedissonDemo(int nThreads, int eLoop) {
    numThreads = nThreads;
    eventLoop = eLoop;

    eg = new NioEventLoopGroup(eventLoop);
    threadPool = Executors.newFixedThreadPool(numThreads + 1);
    stop = new AtomicBoolean(false);
    client = new RedisClient(eg, "ec2-54-227-136-137.compute-1.amazonaws.com", 8102);
    rConn = client.connectAsync();
}
 
Example #10
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 #11
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 #12
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 #13
Source File: LettuceStore.java    From attic-apex-malhar with Apache License 2.0 5 votes vote down vote up
@Override
public void connect() throws IOException
{
  client = new RedisClient(host, port);
  connection = client.connect();
  connection.select(dbIndex);
}
 
Example #14
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 #15
Source File: AbstractRedisConnectionFactory.java    From streamline with Apache License 2.0 4 votes vote down vote up
public AbstractRedisConnectionFactory(RedisClient redisClient, RedisCodec<K, V> codec) {
    this.redisClient = redisClient;
    this.codec = codec;
}
 
Example #16
Source File: RedisConnectionPoolFactory.java    From streamline with Apache License 2.0 4 votes vote down vote up
public RedisConnectionPoolFactory(RedisClient redisClient, RedisCodec<K, V> codec) {
    this(redisClient, codec, MAX_IDLE, MAX_ACTIVE);
}
 
Example #17
Source File: RedisConnectionFactory.java    From streamline with Apache License 2.0 4 votes vote down vote up
public RedisConnectionFactory(RedisClient redisClient, RedisCodec<K, V> codec) {
    super(redisClient, codec);
}
 
Example #18
Source File: RedissonConnectionFactory.java    From dyno with Apache License 2.0 4 votes vote down vote up
public RedissonConnection(HostConnectionPool<RedisAsyncConnection<String, String>> hPool, EventLoopGroup eventGroupLoop, OperationMonitor opMonitor) {
    this.hostPool = hPool;
    Host host = hostPool.getHost();
    this.opMonitor = opMonitor;
    this.client = new RedisClient(eventGroupLoop, host.getHostAddress(), host.getPort());
}
 
Example #19
Source File: AbstractRedisConnectionFactory.java    From streamline with Apache License 2.0 4 votes vote down vote up
public RedisClient getRedisClient() {
    return redisClient;
}
 
Example #20
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 #21
Source File: RedisConnectionPoolFactory.java    From streamline with Apache License 2.0 4 votes vote down vote up
public RedisConnectionPoolFactory(RedisClient redisClient, RedisCodec<K, V> codec, int maxIdle, int maxActive) {
    super(redisClient, codec);
    this.maxIdle = maxIdle;
    this.maxActive = maxActive;
}
 
Example #22
Source File: AbstractRedisConnectionFactory.java    From registry with Apache License 2.0 4 votes vote down vote up
public RedisClient getRedisClient() {
    return redisClient;
}
 
Example #23
Source File: AbstractRedisConnectionFactory.java    From registry with Apache License 2.0 4 votes vote down vote up
public AbstractRedisConnectionFactory(RedisClient redisClient, RedisCodec<K, V> codec) {
    this.redisClient = redisClient;
    this.codec = codec;
}
 
Example #24
Source File: RedisConnectionFactory.java    From registry with Apache License 2.0 4 votes vote down vote up
public RedisConnectionFactory(RedisClient redisClient, RedisCodec<K, V> codec) {
    super(redisClient, codec);
}
 
Example #25
Source File: RedisConnectionPoolFactory.java    From registry with Apache License 2.0 4 votes vote down vote up
public RedisConnectionPoolFactory(RedisClient redisClient, RedisCodec<K, V> codec) {
    this(redisClient, codec, MAX_IDLE, MAX_ACTIVE);
}
 
Example #26
Source File: RedisConnectionPoolFactory.java    From registry with Apache License 2.0 4 votes vote down vote up
public RedisConnectionPoolFactory(RedisClient redisClient, RedisCodec<K, V> codec, int maxIdle, int maxActive) {
    super(redisClient, codec);
    this.maxIdle = maxIdle;
    this.maxActive = maxActive;
}
 
Example #27
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();
}
 
Example #28
Source File: Lettuce3InstrumentationTest.java    From apm-agent-java with Apache License 2.0 4 votes vote down vote up
@Before
public void setUpLettuce() {
    client = new RedisClient("localhost", redisPort);
    connection = client.connect();
    reporter.disableDestinationAddressCheck();
}