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.