Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Reduce number of connections to one cluster node by shuffling nodes. #777

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 14 additions & 5 deletions cluster_library.c
Original file line number Diff line number Diff line change
Expand Up @@ -856,14 +856,21 @@ cluster_init_seeds(redisCluster *cluster, HashTable *ht_seeds) {
char *str, *psep, key[1024];
int key_len;
zval **z_seed;
int *seeds;
size_t i, count;

count = zend_hash_num_elements(ht_seeds);
seeds = emalloc(sizeof(int) * count);

for (i = 0; i < count; i++) seeds[i] = i;
fyshuffle(seeds, count);

// Iterate our seeds array
for(zend_hash_internal_pointer_reset(ht_seeds);
zend_hash_has_more_elements(ht_seeds)==SUCCESS;
zend_hash_move_forward(ht_seeds))
{
for (i = 0; i < count; i++) {
// Grab seed string
zend_hash_get_current_data(ht_seeds, (void**)&z_seed);
if (zend_hash_index_find(ht_seeds, seeds[i], (void**)&z_seed) != SUCCESS) {
continue;
}

// Skip anything that isn't a string
if(Z_TYPE_PP(z_seed)!=IS_STRING)
Expand All @@ -890,6 +897,8 @@ cluster_init_seeds(redisCluster *cluster, HashTable *ht_seeds) {
sizeof(RedisSock*),NULL);
}

efree(seeds);

// Success if at least one seed seems valid
return zend_hash_num_elements(cluster->seeds) > 0 ? 0 : -1;
}
Expand Down
2 changes: 2 additions & 0 deletions cluster_library.h
Original file line number Diff line number Diff line change
Expand Up @@ -458,6 +458,8 @@ int mbulk_resp_loop_zipdbl(RedisSock *redis_sock, zval *z_result,
int mbulk_resp_loop_assoc(RedisSock *redis_sock, zval *z_result,
long long count, void *ctx TSRMLS_DC);

static void fyshuffle(int *array, size_t len);

#endif

/* vim: set tabstop=4 softtabstops=4 noexpandtab shiftwidth=4: */