dongmu5246 2016-08-15 16:13
浏览 20

无法存储memcache密钥

I need memcache for store specific configuration keys. I've integrate memcache inside my Settings class, this class is instatiated each time that a request is performed. Infact, in my own framework, all requests are shunt from index.php. So:

index.php -> autoloader (new Settings, new Model, new Controller, etc...) -> logic

the Settings class is like this:

include 'config.php'; //contains the `$config` array

class Settings
{
    private $_config = array();
    private static $_memcache = null;

    function __construct()
    {
       self::$_memcache = new Memcache();
       self::$_memcache->connect('localhost', 11211); //take in the php doc example

      $this->_config = $config;

      foreach($config as $item => $value)
      {
         self::$_memcache->add($item, $value);
      }
   }

   public static function set($name, $value)
   {
      self::$_memcache->set($name, $value);
   }

   public static function get($name)
   {
      return self::$_memcache->get($name);
   }
}

How you can see I use the method add, in the doc I've read that return false when a key is already setted. The value to set in memcache are taken from my $config array that is included by config.php file.

I also have two method set that should set a specific key, and get that should return a key.

The problem's that each time that this script is executed I get true when I var_dump(self::$_memcache->add($item, $value));.

I use self for use static method of settings. What am I doing wrong?

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 BP神经网络控制倒立摆
    • ¥20 要这个数学建模编程的代码 并且能完整允许出来结果 完整的过程和数据的结果
    • ¥15 html5+css和javascript有人可以帮吗?图片要怎么插入代码里面啊
    • ¥30 Unity接入微信SDK 无法开启摄像头
    • ¥20 有偿 写代码 要用特定的软件anaconda 里的jvpyter 用python3写
    • ¥20 cad图纸,chx-3六轴码垛机器人
    • ¥15 移动摄像头专网需要解vlan
    • ¥20 access多表提取相同字段数据并合并
    • ¥20 基于MSP430f5529的MPU6050驱动,求出欧拉角
    • ¥20 Java-Oj-桌布的计算