首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Redis-py读LOWEST_LATENCY或最近

Redis-py读LOWEST_LATENCY或最近
EN

Stack Overflow用户
提问于 2022-03-28 00:05:41
回答 1查看 121关注 0票数 2

Redis-py版本:4.2.0

如何使redis-py能够从LOWEST_LATENCY节点读取?我们正在使用AWS全局数据存储,所以我们想让redis-py从地理分布的最近节点读取最近的节点吗?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2022-04-13 08:06:46

我觉得你做不到。

根据这篇亚马逊文章的说法,Python最初是在这个项目中实现的集成集群支持,因此用户不需要第三方库来支持集群。但是,在写入时,不支持最低延迟模式。支持的模式有PRIMARIESREPLICASALL_NODESRANDOM。请注意,其中一些内容在Java库中进行了介绍,如REPLICAS,我认为这是生菜中的ANY_REPLICA

LOWEST_LATENCY模式是在Java中实现的,它似乎不是AWS支持或提供的参数,据我所见,它不存在于Python中。

代码语言:javascript
复制
/**
 * Setting to read from the node with the lowest latency during topology discovery. Note that latency measurements are
 * momentary snapshots that can change in rapid succession. Requires dynamic refresh sources to obtain topologies and
 * latencies from all nodes in the cluster.
 * @since 6.1.7
 */
public static final ReadFrom LOWEST_LATENCY = new ReadFromImpl.ReadFromLowestCommandLatency();

这显然被称为最近,这可能意味着它最初是与地球空间的接近(但这只是一个猜测):

代码语言:javascript
复制
/**
 * Setting to read from the node with the lowest latency during topology discovery. Note that latency measurements are
 * momentary snapshots that can change in rapid succession. Requires dynamic refresh sources to obtain topologies and
 * latencies from all nodes in the cluster.
 * @deprecated since 6.1.7 as we're renaming this setting to {@link #LOWEST_LATENCY} for more clarity what this setting
 *             actually represents.
 */
@Deprecated
public static final ReadFrom NEAREST = LOWEST_LATENCY;

看看ReadFromLowestCommandLatency(),这是一个定义。注释有关于延迟模型的重要信息:

代码语言:javascript
复制
/**
 * Read from the node with the lowest latency during topology discovery. Note that latency measurements are momentary
 * snapshots that can change in rapid succession. Requires dynamic refresh sources to obtain topologies and latencies from
 * all nodes in the cluster.
 */
static final class ReadFromLowestCommandLatency

所有这些Readxxx方法都以某种方式使用getNodes(),它返回按延迟排序的节点。但是这种排序发生在库中。库似乎实现了延迟排序,这在Python实现中没有实现。

代码语言:javascript
复制
// Returns the list of nodes that are applicable for the read operation. The list is ordered by latency.
List<RedisNodeDescription> getNodes();

我没有执行完整的代码分析,但例如,TopologyComparators.java中的这个方法似乎证实了这一点:

代码语言:javascript
复制
/**
 * Sort partitions by latency.
 * @param clusterNodes
 * @return List containing {@link RedisClusterNode}s ordered by latency
 */
public static List<RedisClusterNode> sortByLatency(Iterable<RedisClusterNode> clusterNodes) {
    List<RedisClusterNode> ordered = LettuceLists.newList(clusterNodes);
    ordered.sort(LatencyComparator.INSTANCE);
    return ordered;
}

对不起,如果你已经知道一些这一点,但当我看了一下,我想我会把它作为一个答复。

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/71641226

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档