public function index() { \Predis\Autoloader::register(); $redis = new \Predis\Client(); $feedList = M('Feed')->alias('f')->field('f.feedid,f.posttime,f.show,f.content,f.picpath,f.appid,u.avator,u.nickname')->join(array('__USERS__ AS u ON f.userid = u.userid '))->where('f.userid = ' . ACPopedom::getID())->select(); foreach ($feedList as $key => $value) { $feedList[$key]['posttime'] = beforeTime($value['posttime']); if ($value['picpath']) { $feedList[$key]['picpath'] = explode('#$', $value['picpath']); $feedList[$key]['pic-col'] = count($feedList[$key]['picpath']) > 4 ? 3 : 12 / count($feedList[$key]['picpath']); } //取出点赞数 $praise = $redis->hget('feed:' . $value['feedid'], 'praise'); $feedList[$key]['praise'] = $praise ? $praise : 0; } //var_dump($feedList); $this->assign('feedlist', $feedList); $this->assign('userinfo', ACPopedom::getUserInfo()); $this->display(); }
include "./blog/predis.php"; $redis = new Predis\Client(''); // init vars $domain = $_SERVER['HTTP_HOST']; $url = "http://" . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']; $url = str_replace('?r=y', '', $url); $url = str_replace('?c=y', '', $url); $dkey = md5($domain); $ukey = md5($url); $_SERVER['HTTP_CACHE_CONTROL'] == 'max-age=0' ? $submit = 1 : ($submit = 0); // check if logged in to wp $cookie = var_export($_COOKIE, true); $loggedin = preg_match("/blog/wordpress_logged_in/", $cookie); // check if a cache of the page exists if ($redis->hexists($dkey, $ukey) && !$loggedin && !$submit) { echo $redis->hget($dkey, $ukey); 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->set('foo', 'baz'); $value = $redis->get('foo'); echo $value . "\n"; // Here we go incrementing unset values. No need to run messy UPSERT stuff. echo "You've run this script " . $redis->incr('counter') . " times btw.\n"; // Tom is a simple associative array $tom = array('name' => 'Thomas Hunter', 'age' => 27, 'height' => 165); // The predis library makes setting hashes easy $redis->hmset('tom', $tom); // Now lets load that hash $tom = $redis->hgetall('tom'); // As you can see, the object is exactly the same var_dump($tom); echo "\n"; // We can get a single field from our hash if we want $tomsage = $redis->hget('tom', 'age'); echo "Tom is {$tomsage} years old.\n"; // We can increment a single field from the hash as well $redis->hincrby('tom', 'age', '10'); $tom = $redis->hgetall('tom'); var_dump($tom); echo "\n"; // Here's another simple associative array $jessica = array('name' => 'Jessica Rabbit', 'age' => 30, 'height' => 140); // Lets convert it into a JSON string $jessica_json = json_encode($jessica); // I'm just going to set it like any other string $redis->set('jessica', $jessica_json); // Now, lets load it, and JSON decode it (as an array not an stdClass, thanks to the second argument) $new_jessica = json_decode($redis->get('jessica'), TRUE); var_dump($new_jessica);