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)); } }
/** *@author: JJyy *@todo: get the indirect transform number for the user_id * less than 30 days *@param: * **/ function o_indirect_tsf($user_id, $channel_name, $timeset, $db) { $sql = "select count(order_id) as cn from order_info where order_status=1 and pay_status=2 and confirm_time>" . $timeset . " and confirm_time<" . ($timeset + 3600 * 30); $row = $db->query($sql); $cn = $row['cn']; if ($cn == 0) { //if within 30 days no order return 0; } else { $rds = new Redis(); //get the keys for the user_id $keys = $rds->keys("*:" . $user_id); //string like: li9t209jm7mc6m4vmn88o5a7j0:1454035403.8093:10.10.10.29:baidu:0 $num = 0; foreach ($keys as $k => $v) { //the time must after timeset //same user_id and different channel_name and time after than timeset if ($v[1] > $timeset && $v[3] != $channel_name && $v[4] == $user_id) { $sql = "select count(order_id) as cn from order_info where order_status=1 and pay_status=2 and confirm_time>" . $timeset . " and confirm_time<" . ($timeset + 3600 * 2); $row = $db->query($sql); $cn = $row['cn']; $num += $cn; } } return $num; } }
/** *@author: JJyy *@todo: get the indirect user_id *@param: *@return: * **/ function r_indirect_tsf($sessid_arr) { $rds = new Redis(); $tmp = array(); $num = 0; /** * if get the keys is more than two, just check the second key user_id value * if the value is 0, no reg, if not, registed * every channel_name for every client( sessid ) just have one indirect_reg * at most **/ foreach ($sessid_arr as $k => $v) { $tmp[] = $rds->keys($v . "*"); //two-dimemsion array } foreach ($tmp as $k => $v) { if (count($v) > 1) { //get the check time $tmp_check_time = explode(':', $v[0]); $check_time = $tmp_check_time[1]; $indirect_key = $v[1]; //the second key is indirect_key //key like: li9t209jm7mc6m4vmn88o5a7j0:1454035403.8093:10.10.10.29:baidu:0 $key_arr = explode(':', $indirect_key); if ($key_arr[4] != 0 && $key_arr[1] < $check_time + 3600 * 30) { //the user_id !=0 and the time is less than 30 days $num += 1; } } } //end foreach return $num; }
public static function refresh() { $posts = collect(self::wp_get('get_posts')['posts']); $posts->each(function ($item) { //delete all previous posts if (\Config('cache.default') == 'redis') { Redis::pipeline(function ($pipe) { foreach (Redis::keys('laravel:a440:wordpress:posts_*') as $key) { $pipe->del($key); } }); } Cache::forever('a440:wordpress:posts_' . $item['id'], $item); }); Cache::forever('a440:wordpress:posts', $posts->transform(function ($item) { unset($item['content']); unset($item['url']); unset($item['status']); unset($item['title_plain']); unset($item['modified']); unset($item['categories']); unset($item['comments']); unset($item['attachments']); unset($item['comment_count']); unset($item['comment_status']); unset($item['thumbnail']); unset($item['custom_fields']); unset($item['thumbnail_size']); unset($item['thumbnail_images']['full']); unset($item['thumbnail_images']['thumbnail']); unset($item['thumbnail_images']['post-thumbnail']); return $item; })); Cache::forever('a440:wordpress:categories', collect(self::wp_get('get_category_index')['categories'])); }
/** * 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); } }
/** * @param string $keyPattern * @param int|null $limit * * @return array|ProvidesKeyInformation[] */ public function getKeyInfoObjects($keyPattern, $limit) { $keys = $this->redis->keys($keyPattern); if (!is_null($limit)) { $keys = array_slice($keys, 0, $limit); } return array_map([$this, 'getKeyInfoObject'], $keys); }
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)); } }
public function postDeleteNode() { $node = \Input::get('node'); foreach (\Redis::keys('*') as $key) { if (starts_with($key, $node)) { \Redis::del($key); } } }
/** * @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(); }
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); }
/** * 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 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; }
public function keys($prefix) { return parent::keys($this->generateUniqueKey($prefix)); }
<?php $redis = new \Redis(); $ok = $redis->connect('127.0.0.1'); $redis->select(9); if (!$ok) { die("redis connect failed"); } $redis->select(9); var_dump($key = $redis->keys("*")[0]); //$redis->setTimeout($key, 1000); var_dump($redis->ttl($key));
protected function tearDown() { foreach ($this->redis->keys(REDIS_NAMESPACE . '*') as $key) { $this->redis->delete($key); } }
/** * Flush all objects * * @return int */ function flush() { return $this->object->del($this->object->keys($this->prefix . '*')); }
echo "Using KEYS.\n"; } $count = 0; $total = 0; $entries = 0; echo "==============\n"; // check if phpredis and redis-server supports SCAN if (scan_command_available()) { $total = $redis->dbsize(); $it = NULL; $redis->setOption(Redis::OPT_SCAN, Redis::SCAN_RETRY); while ($keys = $redis->scan($it)) { copy_keys($keys); } } else { $keys = $redis->keys('*'); $total = count($keys); copy_keys($keys); } echo date('Y-m-d H:i:s') . " {$total} keys, {$entries} entries copied.\n"; echo "==============\n"; echo "Done.\n"; echo "\n"; function copy_keys($keys) { global $redis, $ssdb, $count, $total, $entries; foreach ($keys as $key) { copy_key($key); if (++$count % 100 == 1) { echo date('Y-m-d H:i:s') . " {$count}/{$total} entries: {$entries}\n"; }
/** * 获取所有的Redis队列 * * 获取所有以“house_updown_count_”开头的队列 * * @return array */ public function queues() { $pattern = self::QUEUE_PREFIX . '*'; return $this->redis->keys($pattern); }
/** * Clean cache for the current scope * * @param const $scope Cache::LOCAL_SCOPE or Cache::GLOBAL_SCOPE * for local or global scoping of the cache item * @return bool TRUE on success, FALSE on failureå */ public function clean($scope = Cache::LOCAL_SCOPE) { return $this->_redis->delete($this->_redis->keys($this->unique_key('', $scope) . '*')) === 1; }
public function keys($pattern) { return $this->connection->keys($pattern); }
private function checkSerializer($mode) { $this->redis->delete('key'); $this->assertTrue($this->redis->getOption(Redis::OPT_SERIALIZER) === Redis::SERIALIZER_NONE); // default $this->assertTrue($this->redis->setOption(Redis::OPT_SERIALIZER, $mode) === TRUE); // set ok $this->assertTrue($this->redis->getOption(Redis::OPT_SERIALIZER) === $mode); // get ok // lPush, rPush $a = array('hello world', 42, TRUE, array('<tag>' => 1729)); $this->redis->delete('key'); $this->redis->lPush('key', $a[0]); $this->redis->rPush('key', $a[1]); $this->redis->rPush('key', $a[2]); $this->redis->rPush('key', $a[3]); // lGetRange $this->assertTrue($a === $this->redis->lGetRange('key', 0, -1)); // lGet $this->assertTrue($a[0] === $this->redis->lGet('key', 0)); $this->assertTrue($a[1] === $this->redis->lGet('key', 1)); $this->assertTrue($a[2] === $this->redis->lGet('key', 2)); $this->assertTrue($a[3] === $this->redis->lGet('key', 3)); // lRemove $this->assertTrue($this->redis->lRemove('key', $a[3]) === 1); $this->assertTrue(array_slice($a, 0, 3) === $this->redis->lGetRange('key', 0, -1)); // lSet $a[0] = array('k' => 'v'); // update $this->assertTrue(TRUE === $this->redis->lSet('key', 0, $a[0])); $this->assertTrue($a[0] === $this->redis->lGet('key', 0)); // lInsert $this->assertTrue($this->redis->lInsert('key', Redis::BEFORE, $a[0], array(1, 2, 3)) === 4); $this->assertTrue($this->redis->lInsert('key', Redis::AFTER, $a[0], array(4, 5, 6)) === 5); $a = array(array(1, 2, 3), $a[0], array(4, 5, 6), $a[1], $a[2]); $this->assertTrue($a === $this->redis->lGetRange('key', 0, -1)); // sAdd $this->redis->delete('key'); $s = array(1, 'a', array(1, 2, 3), array('k' => 'v')); $this->assertTrue(1 === $this->redis->sAdd('key', $s[0])); $this->assertTrue(1 === $this->redis->sAdd('key', $s[1])); $this->assertTrue(1 === $this->redis->sAdd('key', $s[2])); $this->assertTrue(1 === $this->redis->sAdd('key', $s[3])); // variadic sAdd $this->redis->delete('k'); $this->assertTrue(3 === $this->redis->sAdd('k', 'a', 'b', 'c')); $this->assertTrue(1 === $this->redis->sAdd('k', 'a', 'b', 'c', 'd')); // sRemove $this->assertTrue(1 === $this->redis->sRemove('key', $s[3])); $this->assertTrue(0 === $this->redis->sRemove('key', $s[3])); // variadic $this->redis->delete('k'); $this->redis->sAdd('k', 'a', 'b', 'c', 'd'); $this->assertTrue(2 === $this->redis->sRem('k', 'a', 'd')); $this->assertTrue(2 === $this->redis->sRem('k', 'b', 'c', 'e')); $this->assertTrue(FALSE === $this->redis->exists('k')); // sContains $this->assertTrue(TRUE === $this->redis->sContains('key', $s[0])); $this->assertTrue(TRUE === $this->redis->sContains('key', $s[1])); $this->assertTrue(TRUE === $this->redis->sContains('key', $s[2])); $this->assertTrue(FALSE === $this->redis->sContains('key', $s[3])); unset($s[3]); // sMove $this->redis->delete('tmp'); $this->redis->sMove('key', 'tmp', $s[0]); $this->assertTrue(FALSE === $this->redis->sContains('key', $s[0])); $this->assertTrue(TRUE === $this->redis->sContains('tmp', $s[0])); unset($s[0]); // sorted sets $z = array('z0', array('k' => 'v'), FALSE, NULL); $this->redis->delete('key'); // zAdd $this->assertTrue(1 === $this->redis->zAdd('key', 0, $z[0])); $this->assertTrue(1 === $this->redis->zAdd('key', 1, $z[1])); $this->assertTrue(1 === $this->redis->zAdd('key', 2, $z[2])); $this->assertTrue(1 === $this->redis->zAdd('key', 3, $z[3])); // zDelete $this->assertTrue(1 === $this->redis->zDelete('key', $z[3])); $this->assertTrue(0 === $this->redis->zDelete('key', $z[3])); unset($z[3]); // check that zDelete doesn't crash with a missing parameter (GitHub issue #102): $this->assertTrue(FALSE === @$this->redis->zDelete('key')); // variadic $this->redis->delete('k'); $this->redis->zAdd('k', 0, 'a'); $this->redis->zAdd('k', 1, 'b'); $this->redis->zAdd('k', 2, 'c'); $this->assertTrue(2 === $this->redis->zDelete('k', 'a', 'c')); $this->assertTrue(1.0 === $this->redis->zScore('k', 'b')); $this->assertTrue($this->redis->zRange('k', 0, -1, true) == array('b' => 1.0)); // zRange $this->assertTrue($z === $this->redis->zRange('key', 0, -1)); // zScore $this->assertTrue(0.0 === $this->redis->zScore('key', $z[0])); $this->assertTrue(1.0 === $this->redis->zScore('key', $z[1])); $this->assertTrue(2.0 === $this->redis->zScore('key', $z[2])); // zRank $this->assertTrue(0 === $this->redis->zRank('key', $z[0])); $this->assertTrue(1 === $this->redis->zRank('key', $z[1])); $this->assertTrue(2 === $this->redis->zRank('key', $z[2])); // zRevRank $this->assertTrue(2 === $this->redis->zRevRank('key', $z[0])); $this->assertTrue(1 === $this->redis->zRevRank('key', $z[1])); $this->assertTrue(0 === $this->redis->zRevRank('key', $z[2])); // zIncrBy $this->assertTrue(3.0 === $this->redis->zIncrBy('key', 1.0, $z[2])); $this->assertTrue(3.0 === $this->redis->zScore('key', $z[2])); $this->assertTrue(5.0 === $this->redis->zIncrBy('key', 2.0, $z[2])); $this->assertTrue(5.0 === $this->redis->zScore('key', $z[2])); $this->assertTrue(2.0 === $this->redis->zIncrBy('key', -3.0, $z[2])); $this->assertTrue(2.0 === $this->redis->zScore('key', $z[2])); // mset $a = array('k0' => 1, 'k1' => 42, 'k2' => NULL, 'k3' => FALSE, 'k4' => array('a' => 'b')); $this->assertTrue(TRUE === $this->redis->mset($a)); foreach ($a as $k => $v) { $this->assertTrue($this->redis->get($k) === $v); } $a = array('k0' => 1, 'k1' => 42, 'k2' => NULL, 'k3' => FALSE, 'k4' => array('a' => 'b')); // hSet $this->redis->delete('key'); foreach ($a as $k => $v) { $this->assertTrue(1 === $this->redis->hSet('key', $k, $v)); } // hGet foreach ($a as $k => $v) { $this->assertTrue($v === $this->redis->hGet('key', $k)); } // hGetAll $this->assertTrue($a === $this->redis->hGetAll('key')); $this->assertTrue(TRUE === $this->redis->hExists('key', 'k0')); $this->assertTrue(TRUE === $this->redis->hExists('key', 'k1')); $this->assertTrue(TRUE === $this->redis->hExists('key', 'k2')); $this->assertTrue(TRUE === $this->redis->hExists('key', 'k3')); $this->assertTrue(TRUE === $this->redis->hExists('key', 'k4')); // hMSet $this->redis->delete('key'); $this->redis->hMSet('key', $a); foreach ($a as $k => $v) { $this->assertTrue($v === $this->redis->hGet('key', $k)); } // hMget $hmget = $this->redis->hMget('key', array_keys($a)); foreach ($hmget as $k => $v) { $this->assertTrue($v === $a[$k]); } // getMultiple $this->redis->set('a', NULL); $this->redis->set('b', FALSE); $this->redis->set('c', 42); $this->redis->set('d', array('x' => 'y')); $this->assertTrue(array(NULL, FALSE, 42, array('x' => 'y')) === $this->redis->getMultiple(array('a', 'b', 'c', 'd'))); // pipeline $this->sequence(Redis::PIPELINE); // multi-exec $this->sequence(Redis::MULTI); // keys $this->assertTrue(is_array($this->redis->keys('*'))); // issue #62, hgetall $this->redis->del('hash1'); $this->redis->hSet('hash1', 'data', 'test 1'); $this->redis->hSet('hash1', 'session_id', 'test 2'); $data = $this->redis->hGetAll('hash1'); $this->assertTrue($data['data'] === 'test 1'); $this->assertTrue($data['session_id'] === 'test 2'); // issue #145, serializer with objects. $this->redis->set('x', array(new stdClass(), new stdClass())); $x = $this->redis->get('x'); $this->assertTrue(is_array($x)); $this->assertTrue(is_object($x[0]) && get_class($x[0]) === 'stdClass'); $this->assertTrue(is_object($x[1]) && get_class($x[1]) === 'stdClass'); // revert $this->assertTrue($this->redis->setOption(Redis::OPT_SERIALIZER, Redis::SERIALIZER_NONE) === TRUE); // set ok $this->assertTrue($this->redis->getOption(Redis::OPT_SERIALIZER) === Redis::SERIALIZER_NONE); // get ok }
<?php define('IPC_REDIS_IP', 'zpushredis'); define('IPC_REDIS_PORT', 6379); $redis = new Redis(); $connected = $redis->connect(IPC_REDIS_IP, IPC_REDIS_PORT); printf("Connected? %s\n", $connected); $keys = $redis->keys("ZP_TOP|" . "*"); print_r($keys); printf("Keys is_array? %d, Count %d\n", is_array($keys), count($keys)); $values = $redis->mGet($keys); print_r($values); printf("Values is_array? %d, Count %d\n", is_array($values), count($values));
/** * Get cache * * @param string like *$key* * @return array(hash) */ public function keys($key) { return $this->_redis->keys($key); }
if ($msg['type'] == 'join') { echo 'join'; $client = new RouterClient('127.0.0.1', 9010); $sid = $_SERVER['SESSIONID']; $msg['id'] = $sid; $msg['x'] = mt_rand(0, 600 - 48); $msg['y'] = mt_rand(0, 520 - 64); //write to db $redis = new Redis(); $key = 'role:' . $sid; $redis->connect('localhost', 6379); $redis->hMset($key, array('id' => $msg['id'], 'x' => $msg['x'], 'y' => $msg['y'], 'name' => $msg['name'])); //join ok $client->sendMsg($sid, json_encode(array('type' => 'joinok', 'id' => $sid, 'name' => $msg['name']))); //sync $keys = $redis->keys('role:*'); $list = array(); foreach ($keys as $k) { $data = $redis->hgetAll($k); if ($k == $key) { continue; } $data['type'] = 'join'; $client->sendMsg($sid, json_encode($data)); echo "sync-->" . $data['id'] . "\n"; } //send all $client->sendAllMsg(json_encode($msg)); } else { if ($msg['type'] == 'popo') { $redis = new Redis();
<?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;
<?php require_once "db-pingshu.inc"; $dbhost = "127.0.0.1"; $db = new DBPingShu($dbhost); $mdb = new Redis(); $mdb->connect('127.0.0.1', 6379); $keys = $mdb->keys("ts-server-hot-pingshu8-book-*"); foreach ($keys as $key) { $bookid = substr($key, strlen("ts-server-hot-pingshu8-book-")); if (count(explode("_", $bookid)) > 1) { $siteid = 1; } else { $siteid = 2; } $value = $mdb->get($key); // print_r("item($siteid, $bookid) $key: $value\n"); $sql = sprintf('update books set hot=%d where siteid=%d and bookid="%s"', (int) $value, $siteid, $bookid); $db->exec($sql); }
// 2) Load MQTT and redis require "phpMQTT.php"; $mqtt = new phpMQTT("127.0.0.1", 1883, "Control"); $redis = new Redis(); $redis->connect("127.0.0.1"); // 3) Parse query string $q = $_GET['q']; $parts = explode("/", $q); switch ($parts[0]) { case "nodes": switch (count($parts)) { case 1: // if length = 1: load all nodes // http://localhost/api/nodes -> {"room":{"battery":3.12,"temperature":18.12}} $nodes = array(); foreach ($redis->keys("node:*") as $key) { $keyparts = explode(":", $key); $nodename = $keyparts[1]; $varname = $keyparts[2]; if (!isset($nodes[$nodename])) { $nodes[$nodename] = array(); } $nodes[$nodename][$varname] = $redis->get($key) * 1; } print json_encode($nodes); break; case 2: // if length = 2: load all variables for node // http://localhost/api/nodes/room -> {"battery":3.12,"temperature":18.12} $node = array(); foreach ($redis->keys("node:" . $parts[1] . ":*") as $key) {
} } $test = new test(); $Signfork = new Signfork(); //查询队列名称和av $rds = new Redis(); $rds->connect('172.16.2.3', 6379); //fork------------ while (true) { // $keys = array('test/send_mail##0##49'); // $keys = array('send_mail_act'); echo ".........................waitting for queue........................\n"; //查询队列名称和av $rds->select(10); //查询 10 队列里面的动作 $keys = $rds->keys('*'); print_r($keys); // exit(); foreach ($keys as $k) { // $str = $rds->get('send_mail_act'); $rds->select(10); $str = $rds->get($k); echo $str . "\n"; $arr = explode('##', $str); $av = $arr[1]; $offset = $arr[2] - 1; $fir_av = $av; //记录一开始要删除的av, 因为是多进程,不能一段一段的删除,必须全部处理之后,一次过删除所有处理过的key,所以要记录初始av $fir_offset = $offset; //获取要处理的队列名字 $q_name_arr = explode('_', $k);
/** * @param string $pattern * @return array */ public function keys($pattern) { return parent::keys($pattern); }
$redis->move('x', 1); // move to DB 1 $redis->select(1); // switch to DB 1 $redis->get('x'); // will return 42 $redis->set('x', '42'); $now = time(NULL); // current timestamp $redis->expireAt('x', $now + 3); // x will disappear in 3 seconds. sleep(5); // wait 5 seconds $redis->get('x'); // will return `FALSE`, as 'x' has expired. $allKeys = $redis->keys('*'); // all keys will match this. $keyWithUserPrefix = $redis->keys('user*'); $redis->object("encoding", "l"); // → ziplist $redis->object("refcount", "l"); // → 1 $redis->object("idletime", "l"); // → 400 (in seconds, with a precision of 10 seconds). $redis->type('key'); $redis->set('key', 'value1'); $redis->append('key', 'value2'); /* 12 */ $redis->get('key'); /* 'value1value2' */ $redis->set('key', 'string value');