Пример #1
0
<?php

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
/**
 * Description of hashes
 *
 * @author changdi
 */
require "../shared.php";
$predis = new Predis\Client($single_server);
//some common 常见的
/*
var_dump($predis->hmset('hash-key',array('k1'=>'v1','k2'=>'v2','k3'=>'v3')));
var_dump($predis->hmget('hash-key',array ('k2','k3')));

var_dump($predis->hlen('hash-key'));
var_dump($predis->hdel('hash-key',array('k1','k3')));
*/
//some more advanced 更高级的
var_dump($predis->hmset('hash-key2', array('short' => 'hello', 'long' => 1000 * '1')));
var_dump($predis->hkeys('hash-key2'));
var_dump($predis->hexists('hash-key2', 'num'));
//var_dump($predis->hincrby('hash-key2','num'));
var_dump($predis->hexists('hash-key2', 'num'));
Пример #2
0
// init predis
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';
Пример #3
0
// init predis
include "./predis.php";
$redis = new Predis\Client(array('host' => $_SERVER['CACHE1_HOST'], 'port' => $_SERVER['CACHE1_PORT']));
// 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);
isset($_SERVER['HTTP_CACHE_CONTROL']) && $_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("/wordpress_logged_in/", $cookie);
// check if a cache of the page exists
if ($redis->hexists($dkey, $ukey) && !$loggedin && !$submit && !strpos($url, '/feed/')) {
    echo $redis->hget($dkey, $ukey);
    $cached = 1;
    $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 './wordpress/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 './wordpress/wp-blog-header.php';
            if ($redis->exists($dkey)) {
                $redis->del($dkey);