Skip to content

Redis clients

Peng Jian edited this page Apr 28, 2019 · 3 revisions

1. Jedis

How to use jedis to connect the Peids cluster?

  • First, initialize the JedisCluster client.
        Set<HostAndPort> jedisClusterNode = new HashSet<HostAndPort>();
        jedisClusterNode.add(new HostAndPort("seed_one_host", 6379));
        jedisClusterNode.add(new HostAndPort("seed_two_host", 6379));
        JedisCluster jedis = new JedisCluster(jedisClusterNode);

Note: seed_one_host, seed_two_host is the seed nodes's host configurated in `seed_provider of the cluster's config file which named scylla.yaml.

You also use the other nodes' host in the cluster. And the hosts of seed nodes are recommended. It's unnecessary to configurate all the nodes's host as the arguments of JedisCluster.

  • Second, use the JedisCluster api to access the cluster. For example,
   jedis.set("a", "b");

1. 如何使用开源的Jedis客户端访问pedis集群?

  • 首先,初始化Jedis客户端,选择集群模式。初始化代码如下:
        Set<HostAndPort> jedisClusterNode = new HashSet<HostAndPort>();
        jedisClusterNode.add(new HostAndPort("seed_one_host", 6379));
        jedisClusterNode.add(new HostAndPort("seed_two_host", 6379));
        JedisCluster jedis = new JedisCluster(jedisClusterNode);

注意,这里的seed_one_node, seed_two_node 是pedis集群的种子节点。当然,你也可以填写其他节点。 但是我们强烈推荐使用种子节点的IP作为初始化参数。同时,也没必要将所有的节点都配置在JedisCluster中。 因为,JedisCluster在启动时,会向集群请求有节点。

  • 其次,就可以使用JedisCluster的API 访问集群了。
Clone this wiki locally