Redis-py版本:4.2.0
如何使redis-py能够从LOWEST_LATENCY节点读取?我们正在使用AWS全局数据存储,所以我们想让redis-py从地理分布的最近节点读取最近的节点吗?
发布于 2022-04-13 08:06:46
我觉得你做不到。
根据这篇亚马逊文章的说法,Python最初是在这个项目中实现的集成集群支持,因此用户不需要第三方库来支持集群。但是,在写入时,不支持最低延迟模式。支持的模式有PRIMARIES、REPLICAS、ALL_NODES和RANDOM。请注意,其中一些内容在Java库中进行了介绍,如REPLICAS,我认为这是生菜中的ANY_REPLICA。
LOWEST_LATENCY模式是在Java中实现的,它似乎不是AWS支持或提供的参数,据我所见,它不存在于Python中。
/**
* 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();这显然被称为最近,这可能意味着它最初是与地球空间的接近(但这只是一个猜测):
/**
* 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(),这是一个定义。注释有关于延迟模型的重要信息:
/**
* 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实现中没有实现。
// Returns the list of nodes that are applicable for the read operation. The list is ordered by latency.
List<RedisNodeDescription> getNodes();我没有执行完整的代码分析,但例如,TopologyComparators.java中的这个方法似乎证实了这一点:
/**
* 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;
}对不起,如果你已经知道一些这一点,但当我看了一下,我想我会把它作为一个答复。
https://stackoverflow.com/questions/71641226
复制相似问题