public function clear($prefix = '') { $prefix = $this->getNamespace() . $prefix . '*'; $it = null; self::$cache->setOption(\Redis::OPT_SCAN, \Redis::SCAN_RETRY); while ($keys = self::$cache->scan($it, $prefix)) { self::$cache->delete($keys); } return true; }
public function testLoadStatusEmpty() { $this->_connection->delete('EjsmontCircuitBreakerAAAbbb'); $this->assertEquals("", $this->_adapter->loadStatus('GGG', '')); $this->assertEquals("", $this->_adapter->loadStatus('AAA', 'bbb')); $this->_adapter->saveStatus('B', 'bbb', ""); $this->assertEquals("", $this->_adapter->loadStatus('A', 'bbb'), 6); $this->assertEquals("", $this->_adapter->loadStatus('B', 'bbb'), 7); }
/** * Delete data tied to a key on the cache server. * * @param string $key Key we can use to retrieve the data. * * @return bool True if deleted, false if not. * @access public */ public function delete($key) { if ($this->connected === true && $this->ping() === true) { return (bool) $this->server->delete($key); } return false; }
/** * {@inheritDoc} */ public function delete($storageName, $key) { $key = $this->getKeyName($key); if ($this->client->exists($key)) { $this->client->delete($key); } }
public function testExists() { $this->redis->delete('key'); $this->assertFalse($this->redis->exists('key')); $this->redis->set('key', 'val'); $this->assertEquals(True, $this->redis->exists('key')); }
/** * Delete cache object (or entire namespace if $name is null) * * This method will throw only logical exceptions. * In case of failures, it will return a boolean false. * * @param string $name Name for cache element * * @return bool * @throws \Comodojo\Exception\CacheException */ public function delete($name = null) { if (!$this->isEnabled()) { return false; } $this->resetErrorState(); try { $namespace = $this->getNamespaceKey(); if ($namespace === false) { return true; } if (empty($name)) { $this->instance->delete($this->getNamespace()); } else { $this->instance->delete($namespace . "-" . md5($name)); } } catch (CacheException $ce) { throw $ce; } catch (RedisException $re) { $this->raiseError("Server unreachable (PhpRedis), exiting gracefully", array("RESULTCODE" => $re->getCode(), "RESULTMESSAGE" => $re->getMessage())); $this->setErrorState(); return false; } return true; }
/** * Removes multiple items from Redis. * * @param array $keys of items to be removed * * @return bool true on success, also if memcached has been disabled */ public function deleteMulti(array $keys) { $keys2 = array(); foreach ($keys as $key) { $keys2[] = md5($this->uniqId . '_' . $key); } return $this->redis->delete($keys2); }
/** * 删除缓存 * @param sting $cache_id * @return bool */ public function clear ($cache_id) { try { return $this->_redis->delete($cache_id); } catch (Exception $e) { $this->_error = $e->getMessage(); return false; } }
/** * 摧毁SESSION * * @param int $id key * * @return bool true/false */ public function destroy($id) { $id = 'sess_' . $id; if ($this->redis->exists($id)) { return $this->redis->delete($id); } return true; }
public function testsGetMembers() { $this->redis->delete('set'); $this->redis->sAdd('set', 'val'); $this->redis->sAdd('set', 'val2'); $this->redis->sAdd('set', 'val3'); $array = array('val', 'val2', 'val3'); $this->assertEquals($array, $this->redis->sGetMembers('set')); }
/** * 删除指定key的缓存,若$key===true则表示删除全部 * * @param string $key */ public function delete($key) { $this->_connect(); if ($key === true) { return $this->_redis->flushAll(); } else { $keys = func_get_args(); return $this->_redis->delete($keys); } }
public function testHashes() { $this->redis->delete('h', 'key'); $this->assertTrue(0 === $this->redis->hLen('h')); $this->assertTrue(TRUE === $this->redis->hSet('h', 'a', 'a-value')); $this->assertTrue(1 === $this->redis->hLen('h')); $this->assertTrue(TRUE === $this->redis->hSet('h', 'b', 'b-value')); $this->assertTrue(2 === $this->redis->hLen('h')); $this->assertTrue('a-value' === $this->redis->hGet('h', 'a')); // simple get $this->assertTrue('b-value' === $this->redis->hGet('h', 'b')); // simple get $this->assertTrue(FALSE === $this->redis->hSet('h', 'a', 'another-value')); // replacement $this->assertTrue('another-value' === $this->redis->hGet('h', 'a')); // get the new value $this->assertTrue('b-value' === $this->redis->hGet('h', 'b')); // simple get $this->assertTrue(FALSE === $this->redis->hGet('h', 'c')); // unknown hash member $this->assertTrue(FALSE === $this->redis->hGet('key', 'c')); // unknownkey // hDel $this->assertTrue(TRUE === $this->redis->hDel('h', 'a')); // TRUE on success $this->assertTrue(FALSE === $this->redis->hDel('h', 'a')); // FALSE on failure $this->redis->delete('h'); $this->redis->hSet('h', 'x', 'a'); $this->redis->hSet('h', 'y', 'b'); // keys $keys = $this->redis->hKeys('h'); $this->assertTrue($keys === array('x', 'y') || $keys === array('y', 'x')); // values $values = $this->redis->hVals('h'); $this->assertTrue($values === array('a', 'b') || $values === array('b', 'a')); // keys + values $all = $this->redis->hGetAll('h'); $this->assertTrue($all === array('x' => 'a', 'y' => 'b') || $all === array('y' => 'b', 'x' => 'a')); // hExists $this->assertTrue(TRUE === $this->redis->hExists('h', 'x')); $this->assertTrue(TRUE === $this->redis->hExists('h', 'y')); $this->assertTrue(FALSE === $this->redis->hExists('h', 'w')); $this->redis->delete('h'); $this->assertTrue(FALSE === $this->redis->hExists('h', 'x')); // hIncrBy /* $this->redis->delete('h'); $this->assertTrue(2.5 === $this->redis->hIncrBy('h', 2.5, 'x')); $this->assertTrue(3.5 === $this->redis->hIncrBy('h', 1, 'x')); $this->redis->hSet('h', 'y', 'not-a-number'); $this->assertTrue(FALSE === $this->redis->hIncrBy('h', 1, 'y')); */ }
/** * Delete from cache * * @param string Cache key * @return bool */ public function delete($key) { if ($this->_redis->delete($key) !== 1) { return FALSE; } if (isset($this->_serialized[$key])) { $this->_serialized[$key] = NULL; $this->_redis->sRemove('_ci_redis_serialized', $key); } return TRUE; }
/** * Delete from cache. * * @param string $key Cache key * * @return bool */ public function delete($key) { if ($this->_redis->delete($key) !== 1) { return false; } if (isset($this->_serialized[$key])) { $this->_serialized[$key] = null; $this->_redis->sRemove('_ci_redis_serialized', $key); } return true; }
/** * Resets the Temporal object to its initial value * * @return int Returns the initial value */ public function reset() { Assertion::notNull(self::$redis, "Redis connection hasn't been set"); // Remove each individual key $items = self::$redis->sMembers($this->identifier); foreach ($items as $i) { self::$redis->delete($i); } // Remove the set and check its emptiness self::$redis->delete($this->identifier); Assertion::count(self::$redis->sMembers($this->identifier), 0); return $this->initialNumber; }
/** * @test Implementation */ public function collectGarbageRemovesExpiredIdentifierFromTagsToIdentifierSet() { $this->setUpBackend(); $this->setUpRedis(); $identifier = 'identifier' . uniqid(); $this->backend->set($identifier . 'A', 'data', array('tag1', 'tag2')); $this->backend->set($identifier . 'B', 'data', array('tag2')); $this->redis->delete('identData:' . $identifier . 'A'); $this->backend->collectGarbage(); $expectedResult = array(array(), array($identifier . 'B')); $actualResult = array($this->redis->sMembers('tagIdents:tag1'), $this->redis->sMembers('tagIdents:tag2')); $this->assertSame($expectedResult, $actualResult); }
/** * Delete data tied to a key on the cache server. * * @param string $key Key we can use to retrieve the data. * * @return bool True if deleted, false if not. * @access public */ public function delete($key) { if ($this->ping()) { switch (NN_CACHE_TYPE) { case self::TYPE_REDIS: case self::TYPE_MEMCACHED: return (bool) $this->server->delete($key); case self::TYPE_APC: return apc_delete($key); } } return false; }
/** * 删除指定key的缓存 * * 若 `$key===true` 则表示删除全部 * * // 支持下面的方式 * $this->delete('abc'); * $this->delete('abc', 'abc2'); * $this->delete(['abc', 'abc2']); * * // 删除全部 * $this->delete(true); * // 也可使用 * $this->delete_all(); * * @param string|array|true $key */ public function delete($key) { $this->_connect(); if (true === $key) { return $this->_redis->flushAll(); } else { if (is_array($key)) { $keys = $key; } else { $keys = func_get_args(); } return $this->_redis->delete($keys); } }
/** * @return void */ public function __destruct() { // clean all messages sent and not parsed to skip unexpected errors // on next run... // Note: all keys have full name, trim keys until getting them without prefix $prefixOffset = strlen($this->prefix); $keys = array_map(function ($key) use($prefixOffset) { return substr($key, $prefixOffset); }, array_filter($this->client->keys("*"), function ($key) { return preg_match(sprintf("/^(%s)/", preg_quote($this->prefix, "/")), $key); })); $this->client->delete($keys); $this->client->close(); }
/** * {@inheritdoc} */ public function clear($key = null) { if (is_null($key)) { $this->redis->flushDB(); return true; } $keyString = $this->makeKeyString($key, true); $keyReal = $this->makeKeyString($key); $this->redis->incr($keyString); // increment index for children items $this->redis->delete($keyReal); // remove direct item. $this->keyCache = array(); return true; }
public function bind() { $redis = new Redis(); $redis->connect(REDIS_HOST, REDIS_PORT); $redis->auth(REDIS_AUTH); $results = $this->job_model->getWxUserKeys(); $keys = array_map(function ($v) { return 'map:' . $v['broker_id']; }, $results); $redis->delete($keys); $results = $this->job_model->getWxUser(); foreach ($results as $u) { $key = 'map:' . $u['broker_id']; $open_id = $u['open_id']; $redis->lpush($key, $open_id); } }
/** * Clean cache for a group given a mode. * * group mode : cleans all cache in the group * notgroup mode : cleans all cache not in the group * * @param string $group The cache data group * @param string $mode The mode for cleaning cache [group|notgroup] * * @return boolean * * @since 3.4 */ public function clean($group, $mode = null) { if (static::isConnected() == false) { return false; } $allKeys = static::$_redis->keys('*'); if ($allKeys === false) { $allKeys = array(); } $secret = $this->_hash; foreach ($allKeys as $key) { if (strpos($key, $secret . '-cache-' . $group . '-') === 0 && $mode == 'group') { static::$_redis->delete($key); } if (strpos($key, $secret . '-cache-' . $group . '-') !== 0 && $mode != 'group') { static::$_redis->delete($key); } } return true; }
public function testReconnectSelect() { $key = 'reconnect-select'; $value = 'Has been set!'; $original_cfg = $this->redis->config('GET', 'timeout'); // Make sure the default DB doesn't have the key. $this->redis->select(0); $this->redis->delete($key); // Set the key on a different DB. $this->redis->select(5); $this->redis->set($key, $value); // Time out after 1 second. $this->redis->config('SET', 'timeout', '1'); // Wait for the timeout. With Redis 2.4, we have to wait up to 10 s // for the server to close the connection, regardless of the timeout // setting. sleep(11); // Make sure we're still using the same DB. $this->assertEquals($value, $this->redis->get($key)); // Revert the setting. $this->redis->config('SET', 'timeout', $original_cfg['timeout']); }
preconnect: true auto_eject_hosts: true server_retry_timeout: 2000 server_failure_limit: 3 servers: - 127.0.0.1:11211:1 - 127.0.0.1:11212:1 */ $redis = new Redis(); $redis->connect('127.0.0.1', 22121, 1); $key1 = 'twenproxy1'; $result = $redis->set($key1, 1); var_dump($result); $result = $redis->get($key1); var_dump($result); $result = $redis->delete($key1); var_dump($result); $result = $redis->get($key1); var_dump($result); $key2 = 'twenproxy2'; $memcached = new Memcached(); $memcached->addServer('127.0.0.1', 22122); $result = $memcached->set($key2, 2); var_dump($result); $result = $memcached->get($key2); var_dump($result); $key3 = 'twenproxy3'; $result = $memcached->set($key3, 3); var_dump($result); $result = $memcached->get($key3); var_dump($result);
<?php $redis = new Redis(); $redis->connect('127.0.0.1', 6379); $mysql_conn = mysql_connect("localhost", "root", ''); if (!$mysql_conn) { die('connect fail ' . mysql_error()); } mysql_query("set character set 'utf8'"); mysql_select_db("thinkphp", $mysql_conn); //user表 $user_keys = $redis->keys('user*'); foreach ($user_keys as $key) { if ($redis->exists($key)) { $redis->delete($key); echo $key . " delete success" . PHP_EOL; } else { die('delete table user keys not exists'); } } // die(); $sql = 'select * from user'; $result = mysql_query($sql); while ($user_res = mysql_fetch_array($result)) { $redis->set('user:uid:username:'******'uid'], $user_res['username']); $redis->set('user:uid:password:'******'uid'], $user_res['password']); $redis->set('user:uid:mobile:' . $user_res['mobile'], $user_res['mobile']); echo 'user_res' . $user_res['uid'] . 'update success' . PHP_EOL; } mysql_free_result($result); echo "table user update success" . PHP_EOL;
/** * Delete a job from the queue * * @param string $jobId the id of the job */ public function delete($jobId) { // remove from redis $this->_redis->lRemove($this->_daemonStructName, $jobId, 0); $this->_redis->delete($this->_dataStructName . ":" . $jobId); }
/** * Delete a key from the cache * * @param string $key Identifier for the data * @return bool True if the value was successfully deleted, false if it didn't exist or couldn't be removed */ public function delete($key) { $key = $this->_key($key); return $this->_Redis->delete($key) > 0; }
protected function deleteValue($key) { return $this->redis->delete($key); }
/** * Delete a key from the cache * * @param string $key Identifier for the data * @return bool True if the value was successfully deleted, false if it didn't exist or couldn't be removed */ public function delete($key) { return $this->_Redis->delete($key) > 0; }
/** * Delete from cache * * @param string Cache key * @return bool */ public function delete($key) { return $this->_redis->delete($key) === 1; }