This article mainly introduces how to access the Redis with password, the article began to introduce how to set up Redis password and method with password Redis, easy to learn and understand, the need for friends can reference, below to see together.
First, set up a redis password to provide remote login
Open the Redis.conf configuration file, locate the Requirepass, and then modify the following:
Requirepass YourPassword
YourPassword is the Redis authentication password, set the password after the discovery can login, but unable to execute the command.
The command is as follows:
Redis-cli-h 127.0.0.1-p 6379//Start the Redis client and connect to the server
Keys *//All keys in the output server
The error is as follows
(Error) ERR Operation not permitted
At this time you can use the authorization command to authorize, no error.
The command is as follows:
Auth Youpassword
Second, PHP access to Redis
$redis = new Redis (), $conn = $redis->connect (' localhost ', 6379); $auth = $redis->auth (' 20160601 '); Set Password Var_dump ($auth), $redis->set (' Access_token ', "123213213213213213"), $redis->set (' Expired_time ', 1464344863), Var_dump ($redis->get ("Access_token")), Var_dump ($redis->get ("Expired_time"));
Summarize
The above is the use of PHP access to the password with the Redis method sample content, more relevant content please pay attention to topic.alibabacloud.com (www.php.cn)!