org.redisson.client.RedisClient Java Examples

The following examples show how to use org.redisson.client.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: RedissonTimeSeries.java    From redisson with Apache License 2.0 6 votes vote down vote up
@Override
public Iterator<V> iterator(String pattern, int count) {
    return new RedissonBaseIterator<V>() {

        @Override
        protected ListScanResult<Object> iterator(RedisClient client, long nextIterPos) {
            return scanIterator(getName(), client, nextIterPos, pattern, count);
        }

        @Override
        protected void remove(Object value) {
            throw new UnsupportedOperationException();
        }

    };
}
 
Example #2
Source File: RedissonConnectionFactory.java    From redisson with Apache License 2.0 6 votes vote down vote up
@Override
public RedisSentinelConnection getSentinelConnection() {
    if (!redisson.getConfig().isSentinelConfig()) {
        throw new InvalidDataAccessResourceUsageException("Redisson is not in Sentinel mode");
    }
    
    SentinelConnectionManager manager = ((SentinelConnectionManager)((Redisson)redisson).getConnectionManager());
    for (RedisClient client : manager.getSentinels()) {
        org.redisson.client.RedisConnection connection = client.connect();
        try {
            String res = connection.sync(RedisCommands.PING);
            if ("pong".equalsIgnoreCase(res)) {
                return new RedissonSentinelConnection(connection);
            }
        } catch (Exception e) {
            log.warn("Can't connect to " + client, e);
            connection.closeAsync();
        }
    }
    
    throw new InvalidDataAccessResourceUsageException("Sentinels are not found");
}
 
Example #3
Source File: RedissonConnectionFactory.java    From redisson with Apache License 2.0 6 votes vote down vote up
@Override
public RedisSentinelConnection getSentinelConnection() {
    if (!redisson.getConfig().isSentinelConfig()) {
        throw new InvalidDataAccessResourceUsageException("Redisson is not in Sentinel mode");
    }
    
    SentinelConnectionManager manager = ((SentinelConnectionManager)((Redisson)redisson).getConnectionManager());
    for (RedisClient client : manager.getSentinels()) {
        org.redisson.client.RedisConnection connection = client.connect();
        try {
            String res = connection.sync(RedisCommands.PING);
            if ("pong".equalsIgnoreCase(res)) {
                return new RedissonSentinelConnection(connection);
            }
        } catch (Exception e) {
            log.warn("Can't connect to " + client, e);
            connection.closeAsync();
        }
    }
    
    throw new InvalidDataAccessResourceUsageException("Sentinels are not found");
}
 
Example #4
Source File: RedissonSetCache.java    From redisson with Apache License 2.0 6 votes vote down vote up
@Override
public Iterator<V> iterator(final String pattern, final int count) {
    return new RedissonBaseIterator<V>() {

        @Override
        protected ListScanResult<Object> iterator(RedisClient client, long nextIterPos) {
            return scanIterator(getName(), client, nextIterPos, pattern, count);
        }

        @Override
        protected void remove(Object value) {
            RedissonSetCache.this.remove((V) value);
        }
        
    };
}
 
Example #5
Source File: RedissonReactiveSetCommands.java    From redisson with Apache License 2.0 6 votes vote down vote up
@Override
public Flux<CommandResponse<KeyCommand, Flux<ByteBuffer>>> sScan(Publisher<KeyScanCommand> commands) {
    return execute(commands, command -> {

        Assert.notNull(command.getKey(), "Key must not be null!");
        Assert.notNull(command.getOptions(), "ScanOptions must not be null!");
        
        byte[] keyBuf = toByteArray(command.getKey());
        Flux<byte[]> flux = Flux.create(new SetReactiveIterator<byte[]>() {
            @Override
            protected RFuture<ListScanResult<Object>> scanIterator(RedisClient client, long nextIterPos) {
                if (command.getOptions().getPattern() == null) {
                    return executorService.readAsync(client, keyBuf, ByteArrayCodec.INSTANCE, RedisCommands.SSCAN, 
                            keyBuf, nextIterPos, "COUNT", Optional.ofNullable(command.getOptions().getCount()).orElse(10L));
                }

                return executorService.readAsync(client, keyBuf, ByteArrayCodec.INSTANCE, RedisCommands.SSCAN, 
                            keyBuf, nextIterPos, "MATCH", command.getOptions().getPattern(), 
                                                "COUNT", Optional.ofNullable(command.getOptions().getCount()).orElse(10L));
            }
        });
        return Mono.just(new CommandResponse<>(command, flux.map(v -> ByteBuffer.wrap(v))));
    });
}
 
Example #6
Source File: RedissonReactiveHashCommands.java    From redisson with Apache License 2.0 6 votes vote down vote up
@Override
public Flux<CommandResponse<KeyCommand, Flux<Entry<ByteBuffer, ByteBuffer>>>> hScan(
        Publisher<KeyScanCommand> commands) {
    return execute(commands, command -> {

        Assert.notNull(command.getKey(), "Key must not be null!");
        Assert.notNull(command.getOptions(), "ScanOptions must not be null!");
        
        byte[] keyBuf = toByteArray(command.getKey());
        Flux<Entry<Object, Object>> flux = Flux.create(new MapReactiveIterator<Object, Object, Entry<Object, Object>>(null, null, 0) {
            @Override
            public RFuture<MapScanResult<Object, Object>> scanIterator(RedisClient client, long nextIterPos) {
                if (command.getOptions().getPattern() == null) {
                    return executorService.readAsync(client, keyBuf, ByteArrayCodec.INSTANCE, RedisCommands.HSCAN, 
                            keyBuf, nextIterPos, "COUNT", Optional.ofNullable(command.getOptions().getCount()).orElse(10L));
                }

                return executorService.readAsync(client, keyBuf, ByteArrayCodec.INSTANCE, RedisCommands.HSCAN, 
                            keyBuf, nextIterPos, "MATCH", command.getOptions().getPattern(), 
                                                "COUNT", Optional.ofNullable(command.getOptions().getCount()).orElse(10L));
            }
        });
        Flux<Entry<ByteBuffer, ByteBuffer>> f = flux.map(v -> Collections.singletonMap(ByteBuffer.wrap((byte[])v.getKey()), ByteBuffer.wrap((byte[])v.getValue())).entrySet().iterator().next());
        return Mono.just(new CommandResponse<>(command, f));
    });
}
 
Example #7
Source File: RedissonConnectionFactory.java    From redisson with Apache License 2.0 6 votes vote down vote up
@Override
public RedisSentinelConnection getSentinelConnection() {
    if (!redisson.getConfig().isSentinelConfig()) {
        throw new InvalidDataAccessResourceUsageException("Redisson is not in Sentinel mode");
    }
    
    SentinelConnectionManager manager = ((SentinelConnectionManager)((Redisson)redisson).getConnectionManager());
    for (RedisClient client : manager.getSentinels()) {
        org.redisson.client.RedisConnection connection = client.connect();
        try {
            String res = connection.sync(RedisCommands.PING);
            if ("pong".equalsIgnoreCase(res)) {
                return new RedissonSentinelConnection(connection);
            }
        } catch (Exception e) {
            log.warn("Can't connect to " + client, e);
            connection.closeAsync();
        }
    }
    
    throw new InvalidDataAccessResourceUsageException("Sentinels are not found");
}
 
Example #8
Source File: RedissonReactiveHashCommands.java    From redisson with Apache License 2.0 6 votes vote down vote up
@Override
public Flux<CommandResponse<KeyCommand, Flux<Entry<ByteBuffer, ByteBuffer>>>> hScan(
        Publisher<KeyScanCommand> commands) {
    return execute(commands, command -> {

        Assert.notNull(command.getKey(), "Key must not be null!");
        Assert.notNull(command.getOptions(), "ScanOptions must not be null!");
        
        byte[] keyBuf = toByteArray(command.getKey());
        Flux<Entry<Object, Object>> flux = Flux.create(new MapReactiveIterator<Object, Object, Entry<Object, Object>>(null, null, 0) {
            @Override
            public RFuture<MapScanResult<Object, Object>> scanIterator(RedisClient client, long nextIterPos) {
                if (command.getOptions().getPattern() == null) {
                    return executorService.readAsync(client, keyBuf, ByteArrayCodec.INSTANCE, RedisCommands.HSCAN, 
                            keyBuf, nextIterPos, "COUNT", Optional.ofNullable(command.getOptions().getCount()).orElse(10L));
                }

                return executorService.readAsync(client, keyBuf, ByteArrayCodec.INSTANCE, RedisCommands.HSCAN, 
                            keyBuf, nextIterPos, "MATCH", command.getOptions().getPattern(), 
                                                "COUNT", Optional.ofNullable(command.getOptions().getCount()).orElse(10L));
            }
        });
        Flux<Entry<ByteBuffer, ByteBuffer>> f = flux.map(v -> Collections.singletonMap(ByteBuffer.wrap((byte[])v.getKey()), ByteBuffer.wrap((byte[])v.getValue())).entrySet().iterator().next());
        return Mono.just(new CommandResponse<>(command, f));
    });
}
 
Example #9
Source File: ClientConnectionsEntry.java    From redisson with Apache License 2.0 6 votes vote down vote up
public ClientConnectionsEntry(RedisClient client, int poolMinSize, int poolMaxSize, int subscribePoolMinSize, int subscribePoolMaxSize,
        ConnectionManager connectionManager, NodeType nodeType) {
    this.client = client;
    this.freeConnectionsCounter = new AsyncSemaphore(poolMaxSize);
    this.connectionManager = connectionManager;
    this.nodeType = nodeType;
    this.freeSubscribeConnectionsCounter = new AsyncSemaphore(subscribePoolMaxSize);

    if (subscribePoolMaxSize > 0) {
        connectionManager.getConnectionWatcher().add(subscribePoolMinSize, subscribePoolMaxSize, freeSubscribeConnections, freeSubscribeConnectionsCounter, c -> {
            freeSubscribeConnections.remove(c);
            return allSubscribeConnections.remove(c);
        });
    }
    connectionManager.getConnectionWatcher().add(poolMinSize, poolMaxSize, freeConnections, freeConnectionsCounter, c -> {
            freeConnections.remove(c);
            return allConnections.remove(c);
        });
}
 
Example #10
Source File: RedissonScoredSortedSet.java    From redisson with Apache License 2.0 6 votes vote down vote up
@Override
public Iterator<V> iterator(final String pattern, final int count) {
    return new RedissonBaseIterator<V>() {

        @Override
        protected ListScanResult<Object> iterator(RedisClient client, long nextIterPos) {
            return scanIterator(client, nextIterPos, pattern, count);
        }

        @Override
        protected void remove(Object value) {
            RedissonScoredSortedSet.this.remove((V) value);
        }
        
    };
}
 
Example #11
Source File: RedissonConnectionFactory.java    From redisson with Apache License 2.0 6 votes vote down vote up
@Override
public RedisSentinelConnection getSentinelConnection() {
    if (!redisson.getConfig().isSentinelConfig()) {
        throw new InvalidDataAccessResourceUsageException("Redisson is not in Sentinel mode");
    }
    
    SentinelConnectionManager manager = ((SentinelConnectionManager)((Redisson)redisson).getConnectionManager());
    for (RedisClient client : manager.getSentinels()) {
        org.redisson.client.RedisConnection connection = client.connect();
        try {
            String res = connection.sync(RedisCommands.PING);
            if ("pong".equalsIgnoreCase(res)) {
                return new RedissonSentinelConnection(connection);
            }
        } catch (Exception e) {
            log.warn("Can't connect to " + client, e);
            connection.closeAsync();
        }
    }
    
    throw new InvalidDataAccessResourceUsageException("Sentinels are not found");
}
 
Example #12
Source File: RedisConnectionMethodInterceptor.java    From skywalking with Apache License 2.0 6 votes vote down vote up
@Override
public void onConstruct(EnhancedInstance objInst, Object[] allArguments) {
    String peer = (String) ((EnhancedInstance) allArguments[0]).getSkyWalkingDynamicField();
    if (peer == null) {
        try {
            /*
              In some high versions of redisson, such as 3.11.1.
              The attribute address in the RedisClientConfig class changed from a lower version of the URI to a RedisURI.
              But they all have the host and port attributes, so use the following code for compatibility.
             */
            Object address = ClassUtil.getObjectField(((RedisClient) allArguments[0]).getConfig(), "address");
            String host = (String) ClassUtil.getObjectField(address, "host");
            String port = String.valueOf(ClassUtil.getObjectField(address, "port"));
            peer = host + ":" + port;
        } catch (Exception e) {
            logger.warn("RedisConnection create peer error: ", e);
        }
    }
    objInst.setSkyWalkingDynamicField(peer);
}
 
Example #13
Source File: RedissonReactiveSetCommands.java    From redisson with Apache License 2.0 6 votes vote down vote up
@Override
public Flux<CommandResponse<KeyCommand, Flux<ByteBuffer>>> sScan(Publisher<KeyScanCommand> commands) {
    return execute(commands, command -> {

        Assert.notNull(command.getKey(), "Key must not be null!");
        Assert.notNull(command.getOptions(), "ScanOptions must not be null!");
        
        byte[] keyBuf = toByteArray(command.getKey());
        Flux<byte[]> flux = Flux.create(new SetReactiveIterator<byte[]>() {
            @Override
            protected RFuture<ListScanResult<Object>> scanIterator(RedisClient client, long nextIterPos) {
                if (command.getOptions().getPattern() == null) {
                    return executorService.readAsync(client, keyBuf, ByteArrayCodec.INSTANCE, RedisCommands.SSCAN, 
                            keyBuf, nextIterPos, "COUNT", Optional.ofNullable(command.getOptions().getCount()).orElse(10L));
                }

                return executorService.readAsync(client, keyBuf, ByteArrayCodec.INSTANCE, RedisCommands.SSCAN, 
                            keyBuf, nextIterPos, "MATCH", command.getOptions().getPattern(), 
                                                "COUNT", Optional.ofNullable(command.getOptions().getCount()).orElse(10L));
            }
        });
        return Mono.just(new CommandResponse<>(command, flux.map(v -> ByteBuffer.wrap(v))));
    });
}
 
Example #14
Source File: RedissonReactiveZSetCommands.java    From redisson with Apache License 2.0 6 votes vote down vote up
@Override
public Flux<CommandResponse<KeyCommand, Flux<Tuple>>> zScan(Publisher<KeyScanCommand> commands) {
    return execute(commands, command -> {

        Assert.notNull(command.getKey(), "Key must not be null!");
        Assert.notNull(command.getOptions(), "ScanOptions must not be null!");
        
        byte[] keyBuf = toByteArray(command.getKey());
        Flux<Tuple> flux = Flux.create(new SetReactiveIterator<Tuple>() {
            @Override
            protected RFuture<ListScanResult<Object>> scanIterator(RedisClient client, long nextIterPos) {
                if (command.getOptions().getPattern() == null) {
                    return executorService.readAsync(client, keyBuf, ByteArrayCodec.INSTANCE, ZSCAN, 
                            keyBuf, nextIterPos, "COUNT", Optional.ofNullable(command.getOptions().getCount()).orElse(10L));
                }

                return executorService.readAsync(client, keyBuf, ByteArrayCodec.INSTANCE, ZSCAN, 
                            keyBuf, nextIterPos, "MATCH", command.getOptions().getPattern(), 
                                                "COUNT", Optional.ofNullable(command.getOptions().getCount()).orElse(10L));
            }
        });
        return Mono.just(new CommandResponse<>(command, flux));
    });
}
 
Example #15
Source File: RedissonConnectionFactory.java    From redisson with Apache License 2.0 6 votes vote down vote up
@Override
public RedisSentinelConnection getSentinelConnection() {
    if (!redisson.getConfig().isSentinelConfig()) {
        throw new InvalidDataAccessResourceUsageException("Redisson is not in Sentinel mode");
    }
    
    SentinelConnectionManager manager = ((SentinelConnectionManager)((Redisson)redisson).getConnectionManager());
    for (RedisClient client : manager.getSentinels()) {
        org.redisson.client.RedisConnection connection = client.connect();
        try {
            String res = connection.sync(RedisCommands.PING);
            if ("pong".equalsIgnoreCase(res)) {
                return new RedissonSentinelConnection(connection);
            }
        } catch (Exception e) {
            log.warn("Can't connect to " + client, e);
            connection.closeAsync();
        }
    }
    
    throw new InvalidDataAccessResourceUsageException("Sentinels are not found");
}
 
Example #16
Source File: RedisRunner.java    From redisson with Apache License 2.0 5 votes vote down vote up
public int stop() {
    if (runner.isNosave() && !runner.isRandomDir()) {
        RedisClient c = createDefaultRedisClientInstance();
        RedisConnection connection = c.connect();
        try {
            connection.async(new RedisStrictCommand<Void>("SHUTDOWN", "NOSAVE", new VoidReplayConvertor()))
                    .await(3, TimeUnit.SECONDS);
        } catch (InterruptedException interruptedException) {
            //shutdown via command failed, lets wait and kill it later.
        }
        c.shutdown();
        connection.closeAsync().syncUninterruptibly();
    }
    Process p = redisProcess;
    p.destroy();
    boolean normalTermination = false;
    try {
        normalTermination = p.waitFor(5, TimeUnit.SECONDS);
    } catch (InterruptedException ex) {
        //OK lets hurry up by force kill;
    }
    if (!normalTermination) {
        p = p.destroyForcibly();
    }
    cleanup();
    int exitCode = p.exitValue();
    return exitCode == 1 && RedissonRuntimeEnvironment.isWindows ? 0 : exitCode;
}
 
Example #17
Source File: MasterSlaveEntry.java    From redisson with Apache License 2.0 5 votes vote down vote up
private void changeMaster(RedisURI address, ClientConnectionsEntry oldMaster,
        RFuture<RedisClient> future) {
    future.onComplete((newMasterClient, e) -> {
        if (e != null) {
            if (oldMaster != masterEntry) {
                writeConnectionPool.remove(masterEntry);
                pubSubConnectionPool.remove(masterEntry);
                masterEntry.getClient().shutdownAsync();
                masterEntry = oldMaster;
            }
            log.error("Unable to change master from: " + oldMaster.getClient().getAddr() + " to: " + address, e);
            return;
        }
        
        writeConnectionPool.remove(oldMaster);
        pubSubConnectionPool.remove(oldMaster);
        
        oldMaster.freezeMaster(FreezeReason.MANAGER);
        slaveDown(oldMaster);

        slaveBalancer.changeType(oldMaster.getClient().getAddr(), NodeType.SLAVE);
        slaveBalancer.changeType(newMasterClient.getAddr(), NodeType.MASTER);
        // freeze in slaveBalancer
        slaveDown(oldMaster.getClient().getAddr(), FreezeReason.MANAGER);

        // more than one slave available, so master can be removed from slaves
        if (!config.checkSkipSlavesInit()
                && slaveBalancer.getAvailableClients() > 1) {
            slaveDown(newMasterClient.getAddr(), FreezeReason.SYSTEM);
        }
        oldMaster.getClient().shutdownAsync();
        log.info("master {} has changed to {}", oldMaster.getClient().getAddr(), masterEntry.getClient().getAddr());
    });
}
 
Example #18
Source File: MasterSlaveEntry.java    From redisson with Apache License 2.0 5 votes vote down vote up
private RFuture<RedisClient> setupMasterEntry(RedisClient client) {
    RPromise<RedisClient> result = new RedissonPromise<RedisClient>();
    result.onComplete((res, e) -> {
        if (e != null) {
            client.shutdownAsync();
        }
    });
    RFuture<InetSocketAddress> addrFuture = client.resolveAddr();
    addrFuture.onComplete((res, e) -> {
        if (e != null) {
            result.tryFailure(e);
            return;
        }
        
        masterEntry = new ClientConnectionsEntry(
                client, 
                config.getMasterConnectionMinimumIdleSize(), 
                config.getMasterConnectionPoolSize(),
                config.getSubscriptionConnectionMinimumIdleSize(),
                config.getSubscriptionConnectionPoolSize(), 
                connectionManager,
                NodeType.MASTER);

        int counter = 1;
        if (config.getSubscriptionMode() == SubscriptionMode.MASTER) {
            counter++;
        }
        
        CountableListener<RedisClient> listener = new CountableListener<>(result, client, counter);
        RFuture<Void> writeFuture = writeConnectionPool.add(masterEntry);
        writeFuture.onComplete(listener);
        
        if (config.getSubscriptionMode() == SubscriptionMode.MASTER) {
            RFuture<Void> pubSubFuture = pubSubConnectionPool.add(masterEntry);
            pubSubFuture.onComplete(listener);
        }
    });
    
    return result;
}
 
Example #19
Source File: RedissonScoredSortedSetRx.java    From redisson with Apache License 2.0 5 votes vote down vote up
private Flowable<V> scanIteratorReactive(String pattern, int count) {
    return new SetRxIterator<V>() {
        @Override
        protected RFuture<ListScanResult<Object>> scanIterator(RedisClient client, long nextIterPos) {
            return ((RedissonScoredSortedSet<V>) instance).scanIteratorAsync(client, nextIterPos, pattern, count);
        }
    }.create();
}
 
Example #20
Source File: RedissonSetCacheRx.java    From redisson with Apache License 2.0 5 votes vote down vote up
public Publisher<V> iterator() {
    return new SetRxIterator<V>() {
        @Override
        protected RFuture<ListScanResult<Object>> scanIterator(RedisClient client, long nextIterPos) {
            return ((ScanIterator) instance).scanIteratorAsync(instance.getName(), client, nextIterPos, null, 10);
        }
    }.create();
}
 
Example #21
Source File: RedisRunner.java    From redisson with Apache License 2.0 5 votes vote down vote up
public RedisClient createRedisClientInstance() {
    if (redisProcess.isAlive()) {
        RedisClientConfig config = new RedisClientConfig();
                config.setAddress(runner.getInitialBindAddr(), runner.getPort());
        return RedisClient.create(config);
    }
    throw new IllegalStateException("Redis server instance is not running.");
}
 
Example #22
Source File: RedissonTimeSeriesReactive.java    From redisson with Apache License 2.0 5 votes vote down vote up
public Publisher<V> iterator() {
    return Flux.create(new SetReactiveIterator<V>() {
        @Override
        protected RFuture<ListScanResult<Object>> scanIterator(RedisClient client, long nextIterPos) {
            return ((RedissonTimeSeries) instance).scanIteratorAsync(instance.getName(), client, nextIterPos, null, 10);
        }
    });
}
 
Example #23
Source File: RedisRunner.java    From redisson with Apache License 2.0 5 votes vote down vote up
public RedisClient createRedisClientInstance() {
    if (redisProcess.isAlive()) {
        RedisClientConfig config = new RedisClientConfig();
                config.setAddress(runner.getInitialBindAddr(), runner.getPort());
        return RedisClient.create(config);
    }
    throw new IllegalStateException("Redis server instance is not running.");
}
 
Example #24
Source File: LoadBalancerManager.java    From redisson with Apache License 2.0 5 votes vote down vote up
public RFuture<RedisConnection> getConnection(RedisCommand<?> command, RedisClient client) {
    ClientConnectionsEntry entry = getEntry(client);
    if (entry != null) {
        return slaveConnectionPool.get(command, entry);
    }
    RedisConnectionException exception = new RedisConnectionException("Can't find entry for " + client);
    return RedissonPromise.newFailedFuture(exception);
}
 
Example #25
Source File: CommandAsyncService.java    From redisson with Apache License 2.0 5 votes vote down vote up
@Override
public <T, R> RFuture<R> readAsync(RedisClient client, String name, Codec codec, RedisCommand<T> command, Object... params) {
    RPromise<R> mainPromise = createPromise();
    int slot = connectionManager.calcSlot(name);
    async(true, new NodeSource(slot, client), codec, command, params, mainPromise, false);
    return mainPromise;
}
 
Example #26
Source File: RedissonSetCacheReactive.java    From redisson with Apache License 2.0 5 votes vote down vote up
public Publisher<V> iterator() {
    return Flux.create(new SetReactiveIterator<V>() {
        @Override
        protected RFuture<ListScanResult<Object>> scanIterator(RedisClient client, long nextIterPos) {
            return ((ScanIterator) instance).scanIteratorAsync(instance.getName(), client, nextIterPos, null, 10);
        }
    });
}
 
Example #27
Source File: RedissonLexSortedSetReactive.java    From redisson with Apache License 2.0 5 votes vote down vote up
private Publisher<String> scanIteratorReactive(final String pattern, final int count) {
    return Flux.create(new SetReactiveIterator<String>() {
        @Override
        protected RFuture<ListScanResult<Object>> scanIterator(final RedisClient client, final long nextIterPos) {
            return ((RedissonScoredSortedSet<String>) instance).scanIteratorAsync(client, nextIterPos, pattern, count);
        }
    });
}
 
Example #28
Source File: RedissonSetRx.java    From redisson with Apache License 2.0 5 votes vote down vote up
public Flowable<V> iterator(String pattern, int count) {
    return new SetRxIterator<V>() {
        @Override
        protected RFuture<ListScanResult<Object>> scanIterator(RedisClient client, long nextIterPos) {
            return ((RedissonSet<V>) instance).scanIteratorAsync(instance.getName(), client, nextIterPos, pattern, count);
        }
    }.create();
}
 
Example #29
Source File: RedisRunner.java    From redisson with Apache License 2.0 5 votes vote down vote up
public RedisClient createRedisClientInstance() {
    if (redisProcess.isAlive()) {
        RedisClientConfig config = new RedisClientConfig();
                config.setAddress(runner.getInitialBindAddr(), runner.getPort());
        return RedisClient.create(config);
    }
    throw new IllegalStateException("Redis server instance is not running.");
}
 
Example #30
Source File: RedissonSet.java    From redisson with Apache License 2.0 5 votes vote down vote up
@Override
public RFuture<ListScanResult<Object>> scanIteratorAsync(String name, RedisClient client, long startPos,
        String pattern, int count) {
    if (pattern == null) {
        return commandExecutor.readAsync(client, name, codec, RedisCommands.SSCAN, name, startPos, "COUNT", count);
    }

    return commandExecutor.readAsync(client, name, codec, RedisCommands.SSCAN, name, startPos, "MATCH", pattern, "COUNT", count);
}