如何在集群模式下使用 Elasticache 连接 Vertx RedisClient [英] How to connect Vertx RedisClient in cluster mode with Elasticache

查看:44
本文介绍了如何在集群模式下使用 Elasticache 连接 Vertx RedisClient的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用包 io.vertx.rxjava.redis.RedisClient 中的 Vertx Redis 客户端连接到 Elasticache Redis.

I am using Vertx Redis client from the package io.vertx.rxjava.redis.RedisClient to connect to Elasticache Redis.

它确实连接但显示错误,

It does connect but shows an error,

io.vertx.redis.client.impl.types.ErrorType: MOVED 4985 xxx.xxx.xxx.xxx:63791

在阅读错误后,我发现这是因为存在分片并且无法连接到所有分片.

After reading about the error I found its because there are sharding and its not able to connect to all of them.

从库中,我无法确定在集群模式下使用什么方法进行连接.

From the library, I am not able to figure what method to use to connect in cluster mode.

推荐答案

这里举例说明如何在集群模式下连接和发送 get 命令.

Here is an example how to connect and send get command in cluster mode.

定义选项:

final RedisOptions options = new RedisOptions()
    .setType(RedisClientType.CLUSTER)
    .setUseSlave(RedisSlaves.SHARE)
    .setMaxWaitingHandlers(128 * 1024)
    .addEndpoint("redis://127.0.0.1:7000")
    .addEndpoint("redis://127.0.0.1:7001")
    .addEndpoint("redis://127.0.0.1:7002")
    .addEndpoint("redis://127.0.0.1:7003")
    .addEndpoint("redis://127.0.0.1:7004")
    .addEndpoint("redis://127.0.0.1:7005");

连接并发送命令:

Redis.createClient(vertx, options).connect(onCreate -> {
  final Redis cluster = onCreate.result();
  cluster.send(cmd(SET).arg("key"), set -> {
    System.out.println(set.result());
  });
});

提示:如果您不确定如何使用某些库或文档不够清楚,您可以随时查看测试(如果该项目有测试).您可以检查它们的实现方式,以便您可以使用那里的示例.

Tip: If you are unsure how use some library or documentation is not clear enough you can always checkout Tests if that projects has them. You can check how they are implemented so you can use examples from there.

这篇关于如何在集群模式下使用 Elasticache 连接 Vertx RedisClient的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆