/** * Generates a unique key used for storing session data in cache. * @param string $id session variable name * @return string a safe cache key associated with the session variable name */ protected function getKey($id) { $ns = $this->aerospike->namespace; $set = $this->aerospike->set; $key = $this->keyPrefix . md5(json_encode([__CLASS__, $id])); return $this->aerospike->getConnection()->initKey($ns, $set, $key); }
/** * Initializes the aerospike Session component. * This method will initialize the [[aerospike]] property to make sure it refers to a valid aerospike connection. * @throws InvalidConfigException if [[aerospike]] is invalid. */ public function init() { if (is_string($this->aerospike)) { $this->aerospike = Yii::$app->get($this->aerospike); } elseif (is_array($this->aerospike)) { if (!isset($this->aerospike['class'])) { $this->aerospike['class'] = Connection::className(); } $this->aerospike = Yii::createObject($this->aerospike); } if (!$this->aerospike instanceof Connection) { throw new InvalidConfigException("Session::aerospike must be either a Redis connection instance or the application component ID of a Redis connection."); } if ($this->keyPrefix === null) { $this->keyPrefix = substr(md5(Yii::$app->id), 0, 5); } parent::init(); }
/** * Initializes the aerospike Cache component. * This method will initialize the [[aerospike]] property to make sure it refers to a valid aerospike connection. * @throws InvalidConfigException if [[aerospike]] is invalid. */ public function init() { parent::init(); // Set serializer for aerospike $this->serializer = [function ($value) { return $value[0]; }, function ($value) { return [$value, null]; }]; if (is_string($this->aerospike)) { $this->aerospike = Yii::$app->get($this->aerospike); } elseif (is_array($this->aerospike)) { if (!isset($this->aerospike['class'])) { $this->aerospike['class'] = Connection::className(); } $this->aerospike = Yii::createObject($this->aerospike); } if (!$this->aerospike instanceof Connection) { throw new InvalidConfigException("Cache::aerospike must be either a Aerospike connection instance or the application component ID of a Aerospike connection."); } }
/** * @inheritdoc */ protected function deleteValue($key) { $db = $this->aerospike->getConnection(); return $db->remove($key) == 0 ? true : false; }