Exemplo n.º 1
0
 public function del($key)
 {
     if (!$this->isConnected()) {
         return false;
     }
     return (bool) $this->redis->del($key);
 }
Exemplo n.º 2
0
 public function get($key, $top = 10)
 {
     $result_key = $this->result_prefix . $key;
     $this->redis->zInter($result_key, [$this->key_prefix . $key, $this->word_prefix], [1, 1]);
     $result = $this->redis->zRevRange($result_key, 0, $top, true);
     $this->redis->del($result_key);
     return $result;
 }
Exemplo n.º 3
0
 /**
  * {@inheritdoc}
  */
 public function releaseLock($name)
 {
     if (isset($this->locks[$name]) && $this->redis->del($name)) {
         $this->clearLock($name);
         return true;
     }
     return false;
 }
Exemplo n.º 4
0
 public function clear()
 {
     $this->redis->setOption(\Redis::OPT_SERIALIZER, \Redis::SERIALIZER_NONE);
     $prefix = $this->redis->getOption(\Redis::OPT_PREFIX);
     $offset = strlen($prefix);
     $keys = $this->redis->keys('*');
     foreach ($keys as $key) {
         $this->redis->del(substr($key, $offset));
     }
 }
 /**
  * Disable a dark launch feature
  * @param $feature string - The name of the feature
  */
 public function disable_feature($feature_name)
 {
     $multi = $this->redis->multi();
     $this->redis->del("{$this->feature_namespace()}:feature:{$feature_name}");
     $this->redis->srem("{$this->feature_namespace()}:features", $feature_name);
     $multi->exec();
 }
Exemplo n.º 6
0
 /**
  * Delete the keys that were added to the database during the test
  */
 public function tearDown()
 {
     parent::tearDown();
     Redis::del($this->testingResource->testModelHashId);
     Redis::del($this->testingResource->testModelSearchableId);
     Redis::del("testmodels");
 }
Exemplo n.º 7
0
 /**
  * Releases a given lock if the owner information matches.
  *
  * @see cache_is_lockable
  * @param string $key Name of the lock to release.
  * @param string $ownerid Owner information to use.
  * @return bool True if the lock is released, false if it is not.
  */
 public function release_lock($key, $ownerid)
 {
     if ($this->check_lock_state($key, $ownerid)) {
         return $this->redis->del($key) !== false;
     }
     return false;
 }
Exemplo n.º 8
0
 public function unlock()
 {
     try {
         $this->rd->del($this->k);
     } catch (\RedisException $e) {
     }
 }
Exemplo n.º 9
0
 private function unlock()
 {
     if ($this->locked) {
         $this->redis->del($this->lockKey);
         $this->locked = false;
     }
 }
 /**
  * {@inheritDoc}
  */
 public function removeWord($language, $word)
 {
     $word = mb_strtolower($word, mb_detect_encoding($word));
     if ($this->redis->exists($word)) {
         $languages = unserialize($this->redis->get($word));
         if (false !== ($index = array_search($language, $languages))) {
             unset($languages[$index]);
             if (!count($languages)) {
                 $this->redis->del($word);
             } else {
                 $this->redis->set($word, serialize($languages));
             }
         }
     }
     return $this;
 }
Exemplo n.º 11
0
 /**
  * Deletes all items from cache.
  *
  * This should only be used for maintenance purposes (slow performance).
  */
 public function flush()
 {
     $keys = $this->redis->keys($this->redis->prefix('*'));
     foreach ($keys as $key) {
         $this->redis->del($key);
     }
 }
Exemplo n.º 12
0
 public function testUnserialize()
 {
     $vals = array(1, 1.5, 'one', array('this', 'is', 'an', 'array'));
     $serializers = array(Redis::SERIALIZER_PHP);
     if (defined('Redis::SERIALIZER_IGBINARY')) {
         $serializers[] = Redis::SERIALIZER_IGBINARY;
     }
     foreach ($serializers as $mode) {
         $vals_enc = array();
         // Pass them through redis so they're serialized
         foreach ($vals as $key => $val) {
             $this->redis->setOption(Redis::OPT_SERIALIZER, $mode);
             $key = "key" . ++$key;
             $this->redis->del($key);
             $this->redis->set($key, $val);
             // Clear serializer, get serialized value
             $this->redis->setOption(Redis::OPT_SERIALIZER, Redis::SERIALIZER_NONE);
             $vals_enc[] = $this->redis->get($key);
         }
         // Run through our array comparing values
         for ($i = 0; $i < count($vals); $i++) {
             // reset serializer
             $this->redis->setOption(Redis::OPT_SERIALIZER, $mode);
             $this->assertTrue($vals[$i] == $this->redis->_unserialize($vals_enc[$i]));
             $this->redis->setOption(Redis::OPT_SERIALIZER, Redis::SERIALIZER_NONE);
         }
     }
 }
Exemplo n.º 13
0
 /**
  * Destroy a session.
  * Expects a session id.
  * @param string $sessionId
  * @return boolean
  */
 public function destroy($sessionId = '')
 {
     if ($sessionId !== '' && $this->_redis->exists($this->_key($sessionId))) {
         $this->_redis->del($this->_key($sessionId));
     }
     session_destroy();
     return true;
 }
Exemplo n.º 14
0
 public function remove()
 {
     if (!$this->id) {
         return false;
     }
     Redis::del($this->key());
     Redis::zrem(get_class($this), $this->id);
 }
Exemplo n.º 15
0
 protected static function clear(\Redis $redis)
 {
     $prefix = $redis->getOption(\Redis::OPT_PREFIX);
     $offset = strlen($prefix);
     $keys = $redis->keys('*');
     foreach ($keys as $key) {
         $redis->del(substr($key, $offset));
     }
 }
Exemplo n.º 16
0
 public function testRawCommand()
 {
     $this->redis->set('mykey', 'some-value');
     $str_result = $this->redis->rawCommand('get', 'mykey');
     $this->assertEquals($str_result, 'some-value');
     $this->redis->del('mylist');
     $this->redis->rpush('mylist', 'A', 'B', 'C', 'D');
     $this->assertEquals($this->redis->lrange('mylist', 0, -1), array('A', 'B', 'C', 'D'));
 }
Exemplo n.º 17
0
 public function postDeleteNode()
 {
     $node = \Input::get('node');
     foreach (\Redis::keys('*') as $key) {
         if (starts_with($key, $node)) {
             \Redis::del($key);
         }
     }
 }
Exemplo n.º 18
0
 /**
  * Delete all keys from the cache
  *
  * @param bool $check Whether or not expiration keys should be checked. If
  *   true, no keys will be removed as cache will rely on redis TTL's.
  * @return bool True if the cache was successfully cleared, false otherwise
  */
 public function clear($check)
 {
     if ($check) {
         return true;
     }
     $keys = $this->_Redis->getKeys($this->settings['prefix'] . '*');
     $this->_Redis->del($keys);
     return true;
 }
Exemplo n.º 19
0
 public function actionDelete()
 {
     $key = __METHOD__;
     $this->ssdb->set($key, __METHOD__);
     print_r(['key' => $key, 'val' => $this->ssdb->get($key)]);
     // delete it
     $this->ssdb->del($key);
     // delete操作失效 但del可用!
     print_r(['after delete: ', 'key' => $key, 'val' => $this->ssdb->get($key)]);
 }
Exemplo n.º 20
0
 /**
  * @param string $name
  * @param string $secret
  *
  * @return bool
  */
 public function unlock($name, $secret = null)
 {
     $nsName = $this->applyNamespace($name, 'lock');
     if (!$this->isLocked($name, $secret)) {
         return false;
     }
     if (!$this->client->del($nsName)) {
         return false;
     }
     unset($this->locks[$nsName]);
     return true;
 }
Exemplo n.º 21
0
 /**
  * 删除该k值,其他模型中的del一般是其他作用
  * @return bool 成功返回TRUE,失败返回FALSE
  */
 public function destroy()
 {
     try {
         return $this->rd->del($this->k);
     } catch (\RedisException $e) {
         // 只有当连接出错的时候,才会报RedisException错误
         // 重连不再throw Exception,只会返回FALSE
         if ($this->reconnRedis()) {
             return $this->rd->del($this->k);
         }
     }
     return FALSE;
 }
Exemplo n.º 22
0
 /**
  * 设置Redis,防止缓存击穿
  * @param int  $key    Redis key
  * @param Mix  $value  缓存值
  * @param int  $expire 过期时间
  * @return bool
  */
 public function setByLock($key, $value, $expire = 0)
 {
     $expire = intval($expire);
     if ($expire > 0) {
         $r_exp = $expire + 100;
         $c_exp = time() + $expire;
     } else {
         $expire = 300;
         $r_exp = $expire + 100;
         $c_exp = time() + $expire;
     }
     $arg = array("data" => $value, "expire" => $c_exp);
     $rs = $this->redis->setex($key, $r_exp, json_encode($arg, true));
     $this->redis->del($key . ".lock");
     return $rs;
 }
Exemplo n.º 23
0
 public function remove()
 {
     if (!$this->exists()) {
         return false;
     }
     // Remove all of the user's surveys
     foreach ($this->surveys as $surveyID) {
         $survey = new Survey($surveyID);
         $survey->remove();
     }
     // And the container which references them
     Redis::del("User:{$this->id}:surveys");
     // And the username-userid reference
     Redis::set("User:username:{$this->username}");
     parent::remove();
 }
 public function index()
 {
     \Redis::set('name', 'alegriaghost');
     $name = \Redis::get('name');
     \Redis::del('name');
     \Debugbar::info($name);
     \Debugbar::warning($name);
     \Debugbar::error($name);
     \Debugbar::addMessage($name, '$name');
     var_dump($name);
     \Redis::set('name1', 'alegriaghost1');
     \Redis::set('name2', 'alegriaghost2');
     \Redis::set('name3', 'alegriaghost3');
     $list = Redis::keys('*');
     $values = Redis::mget($list);
     var_dump($list);
     var_dump($values);
 }
Exemplo n.º 25
0
 public function flush()
 {
     $this->_cache = [];
     if ($this->_connected) {
         try {
             $keys = $this->_redis->keys($this->_prefix . $this->_blog_id . ':*');
             foreach ($keys as $key) {
                 $this->_redis->del($key);
             }
             $keys = $this->_redis->keys($this->_prefix . '0:*');
             foreach ($keys as $key) {
                 $this->_redis->del($key);
             }
         } catch (Exception $e) {
             $this->_connected = false;
             return false;
         }
     }
     return true;
 }
 /**
  * Removes all cache entries matching the specified identifier.
  * Usually this only affects one entry but if - for what reason ever -
  * old entries for the identifier still exist, they are removed as well.
  *
  * @param string $entryIdentifier Specifies the cache entry to remove
  * @throws \RuntimeException
  * @return boolean TRUE if (at least) an entry could be removed or FALSE if no entry was found
  * @api
  */
 public function remove($entryIdentifier)
 {
     if ($this->isFrozen()) {
         throw new \RuntimeException(sprintf('Cannot remove cache entry because the backend of cache "%s" is frozen.', $this->cacheIdentifier), 1323344192);
     }
     do {
         $tagsKey = $this->buildKey('tags:' . $entryIdentifier);
         $this->redis->watch($tagsKey);
         $tags = $this->redis->sMembers($tagsKey);
         $this->redis->multi();
         $this->redis->del($this->buildKey('entry:' . $entryIdentifier));
         foreach ($tags as $tag) {
             $this->redis->sRem($this->buildKey('tag:' . $tag), $entryIdentifier);
         }
         $this->redis->del($this->buildKey('tags:' . $entryIdentifier));
         $this->redis->lRem($this->buildKey('entries'), $entryIdentifier, 0);
         $result = $this->redis->exec();
     } while ($result === false);
     return true;
 }
Exemplo n.º 27
0
 /**
  * Used to delete the given resource from the database
  *
  * @param null $id
  *
  * @return null|void
  */
 public function delete($id = NULL)
 {
     if (NULL === $id) {
         if (is_array($this->data) && array_key_exists($this->idFieldName(), $this->data)) {
             $id = $this->data[$this->idFieldName()];
         } else {
             return NULL;
         }
     }
     $this->guardHidden = false;
     $resource = $this->get($id);
     $this->guardHidden = true;
     if (!$resource) {
         throw new ResourceNotFound(ucwords($this->hashName) . ' not found in database.');
     }
     // Delete the resource
     $this->redis->del($this->getHash($id));
     // Delete the searchable key
     $this->redis->del($this->getSearchableKey($id, $resource->toArray()));
 }
Exemplo n.º 28
0
 /**
  * @inheritdoc
  */
 public function delete($id)
 {
     $this->redis->del($id);
 }
Exemplo n.º 29
0
 /**
  * @param string $key
  */
 public function del($key)
 {
     return parent::del($key);
 }
Exemplo n.º 30
0
 /**
  * @see AdvancedQueueInterface::clear()
  */
 public function clear()
 {
     $this->redis->del(array('tasks', 'sequence'));
 }