Home >Backend Development >PHP Tutorial >Phalcon framework, how to switch redis libraries
modelsCache
is configured as follows
<code>$di->set('modelsCache', function () use ($config) { $cache = new Phalcon\Cache\Backend\Redis(xx, xx); return $cache; });</code>
When injecting the service, the configuration parameter index
can choose to specify the library storage. Check the API and see that there is a setOptions
function. I tried to run the following code
and wanted to switch from the current db0
to db1
, but all the data They are all saved to db0
, but there is no switch. What should I do to switch databases at any time? ?
<code>$this->modelsCache->save('data_in_db0','value'); $opt=$this->modelsCache->getOptions(); $opt['index']=1; $this->modelsCache->setOptions($opt); $this->modelsCache->save('data_in_db1','value');</code>
modelsCache
is configured as follows
<code>$di->set('modelsCache', function () use ($config) { $cache = new Phalcon\Cache\Backend\Redis(xx, xx); return $cache; });</code>
When injecting the service, the configuration parameter index
can choose to specify the library storage. Check the API and see that there is a setOptions
function. I tried to run the following code
and wanted to switch from the current db0
to db1
, but all the data They are all saved to db0
, but there is no switch. What should I do to switch databases at any time? ?
<code>$this->modelsCache->save('data_in_db0','value'); $opt=$this->modelsCache->getOptions(); $opt['index']=1; $this->modelsCache->setOptions($opt); $this->modelsCache->save('data_in_db1','value');</code>
Encapsulate the redis operation class by yourself