thinkphp 3.2 using Redis

Source: Internet
Author: User

(1) Call the Redis class that comes with the frame directly:

Path: \thinkphp\library\think\cache\driver\redis.class.php.

     Public functionTest () {//Create a Redis object        $redis=New\redis (); //Connect to a local Redis service        $redis->connect (' 127.0.0.1 ', 6379); //password verification, if there is no can not set        $redis->auth (' 123456 '); //See if the service is running        Echo"Server is running:".$redis-Ping ();        Echo ' <br/> '; //setting up the cache        $redis->set (' username ', ' Zhang San ', 3600); //Get Cache        $user _name=$redis->get (' username '); Var_dump($user _name); }    

Operation Result:

Server is running: +pong

String (9) "Zhang San"

(2) using the S method:

To add a configuration to a configuration file

' Data_cache_type ' = ' Redis ',
' Redis_host ' = ' 127.0.0.1 ',
' Redis_port ' = 6379,

One, Redis does not set the password case:

     Public function Set_info () {        S (' study ', ' 123 ');            }      Public function Get_info () {        echo C (' Data_cache_type ');         Echo ' <br/> ';         $a = S (' study ');         Echo $a ;    }

Visit Set_info First, then visit Get_info and return the results:

Redis
123

Second, the Redis set the password case:

Using the S method directly, the result is error:

Noauth Authentication required.
And then add the settings
' Redis_auth ' = 123456,
Find the Redis class, find that no password is set, and add code in Redis.class.php's __construct method:

Then test the S method again:
     Public functionSet_info () {$a= S (' study ', ' 1223 '); Var_dump($a);//true    }     Public functionGet_info () {EchoC (' Data_cache_type ');//Redis        Echo' <br/> '; $a= S (' study '); Echo $a;//1223}




thinkphp 3.2 using Redis

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.