Package com.lambdaworks.redis

Examples of com.lambdaworks.redis.RedisClient


        init(config);

        Map<String, ClusterPartition> partitions = new HashMap<String, ClusterPartition>();

        for (URI addr : cfg.getNodeAddresses()) {
            RedisClient client = new RedisClient(group, addr.getHost(), addr.getPort(), cfg.getTimeout());
            RedisAsyncConnection<String, String> connection = client.connectAsync();
            String nodesValue = connection.clusterNodes().awaitUninterruptibly().getNow();
            System.out.println(nodesValue);

            List<ClusterNodeInfo> nodes = parse(nodesValue);
            for (ClusterNodeInfo clusterNodeInfo : nodes) {
                String id = clusterNodeInfo.getNodeId();
                if (clusterNodeInfo.getFlags().contains(Flag.SLAVE)) {
                    id = clusterNodeInfo.getSlaveOf();
                }
                ClusterPartition partition = partitions.get(id);
                if (partition == null) {
                    partition = new ClusterPartition();
                    partitions.put(id, partition);
                }

                if (clusterNodeInfo.getFlags().contains(Flag.FAIL)) {
                    partition.setMasterFail(true);
                }

                if (clusterNodeInfo.getFlags().contains(Flag.SLAVE)) {
                    partition.addSlaveAddress(clusterNodeInfo.getAddress());
                } else {
                    partition.setEndSlot(clusterNodeInfo.getEndSlot());
                    partition.setMasterAddress(clusterNodeInfo.getAddress());
                }
            }

            for (ClusterPartition partition : partitions.values()) {
                if (partition.isMasterFail()) {
                    continue;
                }

                MasterSlaveServersConfig c = create(cfg);
                log.info("master: {}", partition.getMasterAddress());
                c.setMasterAddress(partition.getMasterAddress());
                for (String slaveAddress : partition.getSlaveAddresses()) {
                    log.info("slave: {}", slaveAddress);
                    c.addSlaveAddress(slaveAddress);
                }

                MasterSlaveEntry entry = new MasterSlaveEntry(codec, group, c);
                entries.put(partition.getEndSlot(), entry);
            }

            client.shutdown();
            break;
        }

        this.config = create(cfg);
    }
View Full Code Here


        final AtomicReference<String> master = new AtomicReference<String>();
        final Set<String> freezeSlaves = Collections.newSetFromMap(new ConcurrentHashMap<String, Boolean>());
        final Set<String> addedSlaves = Collections.newSetFromMap(new ConcurrentHashMap<String, Boolean>());

        for (final URI addr : cfg.getSentinelAddresses()) {
            RedisClient client = new RedisClient(group, addr.getHost(), addr.getPort(), cfg.getTimeout());
            nodeClients.add(client);

            RedisPubSubConnection<String, String> pubsub = client.connectPubSub();
            pubsub.addListener(new RedisPubSubAdapter<String>() {
                @Override
                public void subscribed(String channel, long count) {
                    log.info("subscribed to channel: {} from Sentinel {}:{}", channel, addr.getHost(), addr.getPort());
                }
View Full Code Here

        slaveBalancer.init(codec, config);

        List<URI> addresses = new ArrayList<URI>(config.getSlaveAddresses());
        addresses.add(config.getMasterAddress());
        for (URI address : addresses) {
            RedisClient client = new RedisClient(group, address.getHost(), address.getPort(), config.getTimeout());
            SubscribesConnectionEntry entry = new SubscribesConnectionEntry(client,
                    config.getSlaveConnectionPoolSize(),
                    config.getSlaveSubscriptionConnectionPoolSize());
            slaveBalancer.add(entry);
        }
View Full Code Here

        setupMasterEntry(config.getMasterAddress().getHost(), config.getMasterAddress().getPort());
    }

    public void setupMasterEntry(String host, int port) {
        RedisClient masterClient = new RedisClient(group, host, port, config.getTimeout());
        masterEntry = new ConnectionEntry(masterClient, config.getMasterConnectionPoolSize());
    }
View Full Code Here

    }

    public void addSlave(String host, int port) {
        slaveDown(masterEntry.getClient().getAddr().getHostName(), masterEntry.getClient().getAddr().getPort());

        RedisClient client = new RedisClient(group, host, port, config.getTimeout());
        slaveBalancer.add(new SubscribesConnectionEntry(client,
                this.config.getSlaveConnectionPoolSize(),
                this.config.getSlaveSubscriptionConnectionPoolSize()));
    }
View Full Code Here

        c.setSlaveSubscriptionConnectionPoolSize(cfg.getSlaveSubscriptionConnectionPoolSize());
        c.setSubscriptionsPerConnection(cfg.getSubscriptionsPerConnection());

        final Set<String> addedSlaves = Collections.newSetFromMap(new ConcurrentHashMap<String, Boolean>());
        for (URI addr : cfg.getSentinelAddresses()) {
            RedisClient client = new RedisClient(group, addr.getHost(), addr.getPort(), cfg.getTimeout());
            RedisAsyncConnection<String, String> connection = client.connectAsync();

            // TODO async
            List<String> master = connection.getMasterAddrByKey(cfg.getMasterName()).awaitUninterruptibly().getNow();
            String masterHost = master.get(0) + ":" + master.get(1);
            c.setMasterAddress(masterHost);
            log.info("master: {}", masterHost);
//            c.addSlaveAddress(masterHost);

            // TODO async
            List<Map<String, String>> slaves = connection.slaves(cfg.getMasterName()).awaitUninterruptibly().getNow();
            for (Map<String, String> map : slaves) {
                String ip = map.get("ip");
                String port = map.get("port");
                log.info("slave: {}:{}", ip, port);
                c.addSlaveAddress(ip + ":" + port);
                String host = ip + ":" + port;
                addedSlaves.add(host);
            }

            client.shutdown();
            break;
        }

        init(c);
View Full Code Here

    private void monitorMasterChange(final SentinelServersConfig cfg, final Set<String> addedSlaves) {
        final AtomicReference<String> master = new AtomicReference<String>();
        final Set<String> freezeSlaves = Collections.newSetFromMap(new ConcurrentHashMap<String, Boolean>());

        for (final URI addr : cfg.getSentinelAddresses()) {
            RedisClient client = new RedisClient(group, addr.getHost(), addr.getPort(), cfg.getTimeout());
            sentinels.add(client);

            RedisPubSubConnection<String, String> pubsub = client.connectPubSub();
            pubsub.addListener(new RedisPubSubAdapter<String>() {
                @Override
                public void subscribed(String channel, long count) {
                    log.info("subscribed to channel: {} from Sentinel {}:{}", channel, addr.getHost(), addr.getPort());
                }
View Full Code Here

        super(codec, group, config);
    }

    @Override
    public void setupMasterEntry(String host, int port) {
        RedisClient masterClient = new RedisClient(group, host, port, config.getTimeout());
        masterEntry = new SubscribesConnectionEntry(masterClient, config.getMasterConnectionPoolSize(), config.getSlaveSubscriptionConnectionPoolSize());
    }
View Full Code Here

        return RedisClient.class;
    }

    @Override
    protected RedisClient createInstance() throws Exception {
        return new RedisClient(getRedisURI());
    }
View Full Code Here

        return RedisClient.class;
    }

    @Override
    protected RedisClient createInstance() throws Exception {
        return new RedisClient(getRedisURI());
    }
View Full Code Here

TOP

Related Classes of com.lambdaworks.redis.RedisClient

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.