Home > Backend Development > PHP Tutorial > Phalcon framework, how to switch redis libraries

Phalcon framework, how to switch redis libraries

WBOY
Release: 2023-03-02 12:06:01
Original
2788 people have browsed it

modelsCache is configured as follows

<code>$di->set('modelsCache', function () use ($config) {
    $cache = new Phalcon\Cache\Backend\Redis(xx, xx);
    return $cache;
});</code>
Copy after login
Copy after login

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>
Copy after login
Copy after login

Reply content:

modelsCache is configured as follows

<code>$di->set('modelsCache', function () use ($config) {
    $cache = new Phalcon\Cache\Backend\Redis(xx, xx);
    return $cache;
});</code>
Copy after login
Copy after login

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>
Copy after login
Copy after login

Encapsulate the redis operation class by yourself

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template