Example of using PHP to access a Redis method with a password

Source: Internet
Author: User
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)!

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.