Skip to content

Commit b3bc3d4

Browse files
committed
[Fix] When there are a large number of client NODES, the initialization commands CLUSTER SLOTS 0 and CLUSTER NODES 0 cause shard 0 in the Redis cluster to exceed the maximum number of connections.
1 parent 771996d commit b3bc3d4

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

tensorflow_recommenders_addons/dynamic_embedding/core/kernels/redis_impl/redis_cluster_connection_pool.hpp

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ limitations under the License.
2222

2323
#include <chrono>
2424
#include <iostream>
25+
#include <random>
2526

2627
#include "redis_connection_util.hpp"
2728
#include "thread_pool.h"
@@ -213,6 +214,12 @@ class RedisWrapper<RedisInstance, K, V,
213214
return nullptr;
214215
}
215216

217+
int GenerateRedisRandomTag() {
218+
static thread_local std::mt19937 generator(std::random_device{}());
219+
std::uniform_int_distribution<int> distribution(0, 16383);
220+
return distribution(generator);
221+
}
222+
216223
public:
217224
virtual std::vector<std::string> GetKeyBucketsAndOptimizerParamsWithName(
218225
const std::string &keys_prefix_name,
@@ -224,7 +231,7 @@ class RedisWrapper<RedisInstance, K, V,
224231
::sw::redis::StringView hkey) {
225232
connection.send("CLUSTER SLOTS");
226233
};
227-
::sw::redis::StringView _hkey("0");
234+
::sw::redis::StringView _hkey(std::to_string(GenerateRedisRandomTag()));
228235
std::unique_ptr<redisReply, ::sw::redis::ReplyDeleter> reply;
229236
try {
230237
reply = redis_conn_read->command(cmd, _hkey);
@@ -363,7 +370,7 @@ class RedisWrapper<RedisInstance, K, V,
363370
::sw::redis::StringView hkey) {
364371
connection.send("CLUSTER NODES");
365372
};
366-
::sw::redis::StringView _hkey("0");
373+
::sw::redis::StringView _hkey(std::to_string(GenerateRedisRandomTag()));
367374
std::unique_ptr<redisReply, ::sw::redis::ReplyDeleter> reply;
368375
try {
369376
reply = redis_conn_read->command(cmd, _hkey);

0 commit comments

Comments
 (0)