Skip to content

Commit

Permalink
Store auth information in cluster->flags->auth
Browse files Browse the repository at this point in the history
  • Loading branch information
yatsukhnenko committed Jun 5, 2020
1 parent 890ee0e commit 58dab56
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 11 deletions.
14 changes: 6 additions & 8 deletions cluster_library.c
Original file line number Diff line number Diff line change
Expand Up @@ -637,8 +637,8 @@ cluster_node_create(redisCluster *c, char *host, size_t host_len,
node->sock = redis_sock_create(host, host_len, port, c->timeout,
c->read_timeout, c->persistent, NULL, 0);

if (c->auth) {
node->sock->auth = zend_string_copy(c->auth);
if (c->flags->auth) {
node->sock->auth = zend_string_copy(c->flags->auth);
}

return node;
Expand Down Expand Up @@ -826,7 +826,6 @@ PHP_REDIS_API redisCluster *cluster_create(double timeout, double read_timeout,
c->read_timeout = read_timeout;
c->failover = failover;
c->persistent = persistent;
c->auth = NULL;
c->err = NULL;

/* Set up our waitms based on timeout */
Expand All @@ -851,6 +850,8 @@ cluster_free(redisCluster *c, int free_ctx)

/* Free any allocated prefix */
if (c->flags->prefix) zend_string_release(c->flags->prefix);
/* Free auth info we've got */
if (c->flags->auth) zend_string_release(c->flags->auth);
efree(c->flags);

/* Call hash table destructors */
Expand All @@ -861,9 +862,6 @@ cluster_free(redisCluster *c, int free_ctx)
efree(c->seeds);
efree(c->nodes);

/* Free auth info we've got */
if (c->auth) zend_string_release(c->auth);

/* Free any error we've got */
if (c->err) zend_string_release(c->err);

Expand Down Expand Up @@ -1089,8 +1087,8 @@ cluster_init_seeds(redisCluster *cluster, HashTable *ht_seeds) {
cluster->read_timeout, cluster->persistent, NULL, 0);

// Set auth information if specified
if (cluster->auth) {
redis_sock->auth = zend_string_copy(cluster->auth);
if (cluster->flags->auth) {
redis_sock->auth = zend_string_copy(cluster->flags->auth);
}

// Index this seed by host/port
Expand Down
1 change: 0 additions & 1 deletion cluster_library.h
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,6 @@ typedef struct clusterFoldItem clusterFoldItem;

/* RedisCluster implementation structure */
typedef struct redisCluster {
zend_string *auth;

/* Timeout and read timeout (for normal operations) */
double timeout;
Expand Down
2 changes: 1 addition & 1 deletion redis_cluster.c
Original file line number Diff line number Diff line change
Expand Up @@ -370,7 +370,7 @@ static void redis_cluster_init(redisCluster *c, HashTable *ht_seeds, double time
cluster_validate_args(timeout, read_timeout, ht_seeds);

if (auth && auth_len > 0) {
c->auth = zend_string_init(auth, auth_len, 0);
c->flags->auth = zend_string_init(auth, auth_len, 0);
}

c->timeout = timeout;
Expand Down
2 changes: 1 addition & 1 deletion redis_session.c
Original file line number Diff line number Diff line change
Expand Up @@ -962,7 +962,7 @@ PS_OPEN_FUNC(rediscluster) {

c = cluster_create(timeout, read_timeout, failover, persistent);
if (auth && auth_len > 0) {
c->auth = zend_string_init(auth, auth_len, 0);
c->flags->auth = zend_string_init(auth, auth_len, 0);
}

redisCachedCluster *cc;
Expand Down

0 comments on commit 58dab56

Please sign in to comment.