Skip to content

Commit be38856

Browse files
JakubOnderkamichael-grunder
authored andcommitted
Reuse redis_sock_append_auth method
In library.c, there are currently two methods for constructing AUTH command, so we can reuse code from redis_sock_append_auth also in redis_sock_auth_cmd method
1 parent 571ffbc commit be38856

File tree

1 file changed

+4
-9
lines changed

1 file changed

+4
-9
lines changed

library.c

+4-9
Original file line numberDiff line numberDiff line change
@@ -223,19 +223,14 @@ redis_sock_free_auth(RedisSock *redis_sock) {
223223

224224
PHP_REDIS_API char *
225225
redis_sock_auth_cmd(RedisSock *redis_sock, int *cmdlen) {
226-
char *cmd;
226+
smart_string cmd = {0};
227227

228-
/* AUTH requires at least a password */
229-
if (redis_sock->pass == NULL)
228+
if (redis_sock_append_auth(redis_sock, &cmd) == 0) {
230229
return NULL;
231-
232-
if (redis_sock->user) {
233-
*cmdlen = redis_spprintf(redis_sock, NULL, &cmd, "AUTH", "SS", redis_sock->user, redis_sock->pass);
234-
} else {
235-
*cmdlen = redis_spprintf(redis_sock, NULL, &cmd, "AUTH", "S", redis_sock->pass);
236230
}
237231

238-
return cmd;
232+
*cmdlen = cmd.len;
233+
return cmd.c;
239234
}
240235

241236
/* Send Redis AUTH and process response */

0 commit comments

Comments
 (0)