auth

abbr.author writer;authenticity certainty;authentic credibility;authoress female writer

redis AUTH command syntax

Function:By setting the value of the requirepass item in the configuration file (using the command CONFIG SET requirepass password), you can use a password to protect the Redis server.

Syntax: AUTH password

Instructions: If password protection is turned on, you must use the AUTH command after each connection to the Redis server Unlock. Only after unlocking can you use other Redis commands. If the password given in the AUTH command matches the password in the configuration file, the server will return OK and start accepting command input. On the other hand, if the passwords do not match, the server will return an error and ask the client to re-enter the password. Because of the high-performance characteristics of Redis, it is possible to try to guess many passwords in a short period of time, so please ensure that the password used is complex and long enough to avoid password guessing attacks.

Available versions: >= 1.0.0

Time complexity: O(1)

Return: Return OK when the password matches, otherwise return an error.

redis AUTH command example

# 設置密碼
redis> CONFIG SET requirepass secret_password   # 將密碼設置為 secret_password
OK
redis> QUIT                                     # 退出再連接,讓新密碼對客戶端生效
[huangz@mypad]$ redis
redis> PING                                     # 未驗證密碼,操作被拒絕
(error) ERR operation not permitted
redis> AUTH wrong_password_testing              # 嘗試輸入錯誤的密碼
(error) ERR invalid password
redis> AUTH secret_password                     # 輸入正確的密碼
OK
redis> PING                                     # 密碼驗證成功,可以正常操作命令了
PONG
# 清空密碼
redis> CONFIG SET requirepass ""   # 通過將密碼設為空字符來清空密碼
OK
redis> QUIT
$ redis                            # 重新進入客戶端
redis> PING                        # 執(zhí)行命令不再需要密碼,清空密碼操作成功
PONG