分布式缓存Redis

不同编程语言如何使用Cluster集群客户端?

2024-05-22 06:45:50

当前DCS Cluster集群对比Proxy集群的优势和特性:

1 Cluster集群与Proxy集群差异

对比项

Cluster集群

Proxy集群

原生兼容性

客户端兼容性

性价比

时延

低时延

中等时延

性能

Cluster集群由于没有代理层,在时延和性能方面具备一定的优势;但是对于客户端使用方面,由于Cluster集群使用开源的Redis Cluster协议,在客户端的兼容性方面略差与Proxy集群。

推荐的Cluster集群客户端:

官方推荐的开源客户端列表:https://redis.io/clients

2 Cluster集群客户端

客户端语言

客户端类型

Cluster集群参考文档

Java

Jedis

https://github.com/xetorthio/jedis#jedis-cluster

Java

Lettuce

https://github.com/lettuce-io/lettuce-core/wiki/Redis-Cluster

PHP

php redis

https://github.com/phpredis/phpredis#readme

Go

Go Redis

Cluster集群:https://pkg.go.dev/github.com/go-redis/redis/v8#NewClusterClientProxy集群或单机主备:https://pkg.go.dev/github.com/go-redis/redis/v8#NewClient

Python

redis-py-cluster

https://github.com/Grokzen/redis-py-cluster#usage-example

C

hiredis-vip

https://github.com/vipshop/hiredis-vip?_ga=2.64990636.268662337.1603553558-977760105.1588733325

C++

redis-plus-plus

https://github.com/sewenew/redis-plus-plus?_ga=2.64990636.268662337.1603553558-977760105.1588733325#redis-cluster

Node.js

node-redisio-redis

https://github.com/NodeRedis/node-redishttps://github.com/luin/ioredis

使用ClusterRedis集群时建议配置合理的超时时间?

当客户端使用Spring BootLettuce方式连接Redis时,它需要与所有节点建立连接,包括备节点。因此,在集群备节点故障时可能会遇到客户端连接问题,尤其是在未配置超时时可能导致分钟级的超时阻塞。

在未配置 timeout 超时的情况下,模拟备节点故障时,可能会出现分钟级的超时阻塞(Lettuce客户端的老版本默认超时为120秒,新版本默认为60秒),这可能导致端到端业务访问时间过长,最长达到默认超时时间。

建议:

为避免潜在的故障场景,建议在客户端侧添加合适的 timeout 配置,显著缩短备节点的超时时间。用户应根据业务允许的超时时间进行设置。例如,在一次HTTP端到端请求中,如果需要请求两次Redis,而HTTP请求的最大超时时间为10秒,则建议将超时时间配置为5秒,以防止由于超时时间过长或未配置超时时间而导致的业务受损。这样可以更好地应对集群备节点故障情况,提高系统的稳定性和性能。


pa5fYKBpOn9E