function redis_session_destroy($id) { global $redisServer, $redisTargetPrefix; $redisConnection = new \Predis\Client($redisServer); $redisConnection->del($redisTargetPrefix . $id); $unpacked = $redisConnection->keys($redisTargetPrefix . $id . ":*"); foreach ($unpacked as $unp) { $redisConnection->del($unp); } }
/** * Remove and return all members of a set * * @param string $key * @return string[] */ public function sFlush($key) { $this->_redis->multi(); $this->_redis->sMembers($key); $this->_redis->del($key); return $this->_redis->exec()[0]; }
public function testGetApc() { $redis = new \Predis\Client(array("scheme" => "tcp", "host" => 'localhost', "port" => 6379)); $client = new LDClient("BOGUS_API_KEY", array('feature_requester_class' => '\\LaunchDarkly\\ApcLDDFeatureRequester', 'apc_expiration' => 1)); $builder = new LDUserBuilder(3); $user = $builder->build(); $redis->del("launchdarkly:features"); $this->assertEquals("jim", $client->toggle('foo', $user, 'jim')); $redis->hset("launchdarkly:features", 'foo', $this->gen_feature("foo", "bar")); $this->assertEquals("bar", $client->toggle('foo', $user, 'jim')); # cached value so not updated $redis->hset("launchdarkly:features", 'foo', $this->gen_feature("foo", "baz")); $this->assertEquals("bar", $client->toggle('foo', $user, 'jim')); apc_delete("launchdarkly:features.foo"); $this->assertEquals("baz", $client->toggle('foo', $user, 'jim')); }
if (!$debug) { exit(0); } $msg = 'this is a cache'; // if a comment was submitted or clear page cache request was made delete cache of page } else { if ($submit || substr($_SERVER['REQUEST_URI'], -4) == '?r=y') { require './blog/wp-blog-header.php'; $redis->hdel($dkey, $ukey); $msg = 'cache of page deleted'; // delete entire cache, works only if logged in } else { if ($loggedin && substr($_SERVER['REQUEST_URI'], -4) == '?c=y') { require './blog/wp-blog-header.php'; if ($redis->exists($dkey)) { $redis->del($dkey); $msg = 'domain cache flushed'; } else { $msg = 'no cache to flush'; } // if logged in don't cache anything } else { if ($loggedin) { require './blog/wp-blog-header.php'; $msg = 'not cached'; // cache the page } else { // turn on output buffering ob_start(); require './blog/wp-blog-header.php'; // get contents of output buffer
// executed on a Redis instance storing millions of keys. These commands are: // // - SCAN (iterates over the keyspace) // - SSCAN (iterates over members of a set) // - ZSCAN (iterates over members and ranks of a sorted set) // - HSCAN (iterates over fields and values of an hash). // Predis provides a specialized abstraction for each command based on standard // SPL iterators making it possible to easily consume SCAN-based iterations in // your PHP code. // // See http://redis.io/commands/scan for more details. // // Create a client using `2.8` as a server profile (needs Redis 2.8!) $client = new Predis\Client($single_server, array('profile' => '2.8')); // Prepare some keys for our example $client->del('predis:set', 'predis:zset', 'predis:hash'); for ($i = 0; $i < 5; $i++) { $client->sadd('predis:set', "member:{$i}"); $client->zadd('predis:zset', -$i, "member:{$i}"); $client->hset('predis:hash', "field:{$i}", "value:{$i}"); } // === Keyspace iterator based on SCAN === echo 'Scan the keyspace matching only our prefixed keys:', PHP_EOL; foreach (new Iterator\Keyspace($client, 'predis:*') as $key) { echo " - {$key}", PHP_EOL; } /* OUTPUT Scan the keyspace matching only our prefixed keys: - predis:zset - predis:set - predis:hash
/** * Remove the item from the cache. * * @param string $key The key under which to store the value. * @param string $group The group value appended to the $key. * @return bool Returns TRUE on success or FALSE on failure. */ public function delete($key, $group = 'default') { $derived_key = $this->build_key($key, $group); $result = false; if (isset($this->cache[$derived_key])) { unset($this->cache[$derived_key]); $result = true; } if ($this->redis_status() && !in_array($group, $this->no_redis_groups)) { $result = $this->parse_predis_response($this->redis->del($derived_key)); } return $result; }
// Check entry value. echo ">>> Value for 'k1': " . $redis->get('k1') . "\n"; // Change entry's value. if ($redis->set('k1', 'new_value')) { echo ">>> Successfully put entry in cache. \n"; } // Check entry value. echo ">>> Value for 'k1': " . $redis->get('k1') . "\n"; // Put entry to cache. if ($redis->set('k2', '2')) { echo ">>> Successfully put entry in cache. \n"; } // Check entry value. echo ">>> Value for 'k2': " . $redis->get('k2') . "\n"; // Get two entries. $val = $redis->mget('k1', 'k2'); echo ">>> Value for 'k1' and 'k2': " . var_dump($val) . "\n"; // Delete on entry. if ($redis->del('k1')) { echo ">>> Successfully deleted 'k1'. \n"; } // Db size. echo ">>> Db size: " . $redis->dbsize() . "\n"; // Increment. echo ">>> Incremented: " . $redis->incr("inc_k") . "\n"; // Increment by 5. echo ">>> Incremented: " . $redis->incrby("inc_k", 5) . "\n"; } catch (Exception $e) { echo ">>> Couldn't connected to Redis."; echo $e->getMessage(); }
public static function zsetAddAndReturn(Predis\Client $client, $keyName, array $values, $wipeOut = 0) { // $values: array(SCORE => VALUE, ...); if ($wipeOut == true) { $client->del($keyName); } foreach ($values as $value => $score) { $client->zadd($keyName, $score, $value); } return $values; }
/** * Performs the test. * * @return \Jyxo\Beholder\Result */ public function run() { // The redis extension or Predis library is required if (!extension_loaded('redis') && !class_exists('\\Predis\\Client')) { return new \Jyxo\Beholder\Result(\Jyxo\Beholder\Result::NOT_APPLICABLE, 'Extension redis or Predis library required'); } $random = md5(uniqid(time(), true)); $key = 'beholder-' . $random; $value = $random; // Status label $description = (false !== filter_var($this->host, FILTER_VALIDATE_IP) ? gethostbyaddr($this->host) : $this->host) . ':' . $this->port . '?database=' . $this->database; // Connection if (extension_loaded('redis')) { $redis = new \Redis(); if (false === $redis->connect($this->host, $this->port, 2)) { return new \Jyxo\Beholder\Result(\Jyxo\Beholder\Result::FAILURE, sprintf('Connection error %s', $description)); } } else { $redis = new \Predis\Client(array('host' => $this->host, 'port' => $this->port)); if (false === $redis->connect()) { return new \Jyxo\Beholder\Result(\Jyxo\Beholder\Result::FAILURE, sprintf('Connection error %s', $description)); } } // Select database if (false === $redis->select($this->database)) { return new \Jyxo\Beholder\Result(\Jyxo\Beholder\Result::FAILURE, sprintf('Database error %s', $description)); } // Saving if (false === $redis->set($key, $value)) { if ($redis instanceof \Redis) { $redis->close(); } else { $redis->quit(); } return new \Jyxo\Beholder\Result(\Jyxo\Beholder\Result::FAILURE, sprintf('Write error %s', $description)); } // Check $check = $redis->get($key); if (false === $check || $check !== $value) { if ($redis instanceof \Redis) { $redis->close(); } else { $redis->quit(); } return new \Jyxo\Beholder\Result(\Jyxo\Beholder\Result::FAILURE, sprintf('Read error %s', $description)); } // Deleting if (false === $redis->del($key)) { if ($redis instanceof \Redis) { $redis->close(); } else { $redis->quit(); } return new \Jyxo\Beholder\Result(\Jyxo\Beholder\Result::FAILURE, sprintf('Delete error %s', $description)); } // Disconnect if ($redis instanceof \Redis) { $redis->close(); } else { $redis->quit(); } // OK return new \Jyxo\Beholder\Result(\Jyxo\Beholder\Result::SUCCESS, $description); }
<?php include_once '../../common.php'; include_once S_ROOT . './source/function_space.php'; include_once 'verify.php'; $uid = $_SGLOBAL['supe_uid']; require 'Predis/Autoloader.php'; Predis\Autoloader::register(); $client = new Predis\Client(); $keyT = 'ihome_T' . $uid; $keyR = 'ihome_R' . $uid; $value = $client->decr($keyT); if ($value <= 0) { $client->del($keyT); $client->del($keyR); }
$helpSessionKey = $redisResponse; if (empty($helpSessionKey)) { // The queue was empty $app->response->setStatus(204); } else { $redisResponse = $redis->hgetall($helpSessionKey); if (!handleRedisError($redisResponse, $app, 'Não foi possível ler a sessão de vídeo chat.')) { return; } $helpSessionData = $redisResponse; $responseData = array('apiKey' => $config->opentok('key'), 'sessionId' => $helpSessionData['sessionId'], 'token' => $opentok->generateToken($helpSessionData['sessionId']), 'customerName' => $helpSessionData['customerName'], 'problemText' => $helpSessionData['problemText']); // Once the help session is dequeued, we also clean it out of the storage. // If keeping the history of this help session is important, we could mark it as dequeued // instead. If we had authentication for the representative, then we could also mark the // help session with the identity of the representative. $redisResponse = $redis->del($helpSessionKey); if (!handleRedisError($redisResponse, $app, 'Não foi possível remover a sessão após a retirada da fila.')) { return; } $app->response->headers->set('Content-Type', 'application/json'); $app->response->setBody(json_encode($responseData)); } }); // Customer dequeues by cancelling or leaving the page // // Dequeue the specific help session from the help queue. $app->delete('/help/queue/:queueId', function ($queueId) use($app, $redis) { $redisResponse = $redis->lrem(HELP_QUEUE_KEY, 0, $queueId); if (!handleRedisError($redisResponse, $app, 'Não foi possível remover a sessão da fila de atendimento.')) { return; }
<?php require_once 'vendor/autoload.php'; require_once 'classes/service/DisruptionService.php'; $disruptionService = new DisruptionService(); $redisClient = new Predis\Client(getenv('DB_PORT')); $targetStation = getenv('APP_STATION'); $disruption = $disruptionService->getDisruption(); $listId = "dis-" . $targetStation; $redisClient->del($listId); foreach ($disruption as $disruptionDetail) { $stoppingPoints = $disruptionDetail->stoppingPoints; if (in_array($targetStation, $stoppingPoints)) { $redisClient->rpush($listId, json_encode($disruptionDetail)); } //echo $disruptionDetail . "\n"; }
/** * Remove the item from the cache. * * @param string $key The key under which to store the value. * @param string $group The group value appended to the $key. * @return bool Returns TRUE on success or FALSE on failure. */ public function delete($key, $group = 'default') { $derived_key = $this->build_key($key, $group); // Remove from no_redis_groups array if (in_array($group, $this->no_redis_groups) || !$this->can_redis()) { if (isset($this->cache[$derived_key])) { unset($this->cache[$derived_key]); return true; } else { return false; } } $result = $this->parse_predis_response($this->redis->del($derived_key)); unset($this->cache[$derived_key]); return $result; }
/** * 清除缓存,按需重载 * @param string $cachename * @return boolean */ protected function removeCache($cachename) { //TODO: remove cache implementation \Predis\Autoloader::register(); $redis = new \Predis\Client(); if ($redis->del($cachename)) { return true; } return false; }
/** */ public function unlock($key) { $this->_predis->del($this->hkey($key) . self::LOCK_SUFFIX); unset($this->_locks[$key]); }
<?php //ini_set('session.serialize_handler', 'wddx'); require_once __DIR__ . '/../redis-session.php'; $redis = new Predis\Client(); array_map(function ($key) use(&$redis) { //var_dump($redis->get($key)); $redis->del($key); }, $redis->keys("session:php:*")); RedisSession::start(); $_SESSION['test'] = "ohai"; $_SESSION['md'] = array('test2' => array('multidimensional' => 'array')); $_SESSION['more'] = new stdClass();