当前位置:Gxlcms > PHP教程 > Phalcon框架,redis如何切换库

Phalcon框架,redis如何切换库

时间:2021-07-01 10:21:17 帮助过:47人阅读

modelsCache配置如下

  1. <code>$di->set('modelsCache', function () use ($config) {
  2. $cache = new Phalcon\Cache\Backend\Redis(xx, xx);
  3. return $cache;
  4. });</code>

在注入服务时候,配置参数 index可选择指定库存储,查看 API 看到有个 setOptions 函数,试图远行下面代码
想从当前 db0,切换到 db1,但是所有数据都存到 db0 了,没有切换,应该怎么做才能随时换库??

  1. <code>$this->modelsCache->save('data_in_db0','value');
  2. $opt=$this->modelsCache->getOptions();
  3. $opt['index']=1;
  4. $this->modelsCache->setOptions($opt);
  5. $this->modelsCache->save('data_in_db1','value');</code>

回复内容:

modelsCache配置如下

  1. <code>$di->set('modelsCache', function () use ($config) {
  2. $cache = new Phalcon\Cache\Backend\Redis(xx, xx);
  3. return $cache;
  4. });</code>

在注入服务时候,配置参数 index可选择指定库存储,查看 API 看到有个 setOptions 函数,试图远行下面代码
想从当前 db0,切换到 db1,但是所有数据都存到 db0 了,没有切换,应该怎么做才能随时换库??

  1. <code>$this->modelsCache->save('data_in_db0','value');
  2. $opt=$this->modelsCache->getOptions();
  3. $opt['index']=1;
  4. $this->modelsCache->setOptions($opt);
  5. $this->modelsCache->save('data_in_db1','value');</code>

自己封装redis的操作类

人气教程排行