How does CodeIgniterCI3.0 use redis?

Source: Internet
Author: User
Config has been configured, and will only be used in each method now, {code ...} in this way, it is not good to use a new method, because sometimes several functions need to be called, which is used in the manual. But an error is reported. {code...} does not have the static method Redis: get...

Config has been configured, and will only be used in each method now,

// Connect to the local Redis service $ redis = new Redis (); $ redis-> connect ('2017. 127. 0.0.1 ', 6379); $ access_token = $ redis-> get ('oss _ access_token ');

In this way, it is not good for each method to be new once, because sometimes several functions need to be called,

This is the case with the manual. But an error is reported.

$this->load->driver('cache');var_dump($this->cache->redis->get("ci_session:932dd5eb64ccbf43ee76bfe378a2710666dd07f9"));

Is there no static method for using Redis: get?
How do you use it?

Reply content:

Config has been configured, and will only be used in each method now,

// Connect to the local Redis service $ redis = new Redis (); $ redis-> connect ('2017. 127. 0.0.1 ', 6379); $ access_token = $ redis-> get ('oss _ access_token ');

In this way, it is not good for each method to be new once, because sometimes several functions need to be called,

This is the case with the manual. But an error is reported.

$this->load->driver('cache');var_dump($this->cache->redis->get("ci_session:932dd5eb64ccbf43ee76bfe378a2710666dd07f9"));

Is there no static method for using Redis: get?
How do you use it?

// When multiple redis instances are configured $ this-> config-> load ('redis ', TRUE, TRUE ); $ redis_conf = $ this-> config-> item ('redis '); $ this-> load-> driver ('cache ', array ('adapter '=> 'redis', 'config' => $ redis_conf ['redis _ config_name ']), 'redis _ name '); // only the default redis $ this-> load-> driver ('cache', array ('adapter '=> 'redis'), 'redis _ name') is configured '); // use $ this-> redis_name-> info ();

I flipped through the system of CI 3.0 just now. In fact, CI has put CI into the cache and is not put into the system database. It seems that redis is not treated as a database, it is only used as a cache.
As for your question:
Every time you create a new instance, we recommend that you write a redis library and then perform it in a singleton mode so that you do not need to create a new instance each time. Only by writing it yourself can you achieve the desired effect. Or Secondary Development of the CI database core, of course, I do not recommend that you do this.
Next is your second question. I checked the cache class of ci system, and finally there is a method called is_supported, I suggest you test whether the redis extension is loaded with OK in your environment.
Wish everything went well.

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.