コード例 #1
0
            }
        }
        return $newArray;
    }
    public function remove($node)
    {
        $this->_nodes = self::array_remove($this->_nodes, $node);
        $this->_nodesCount = count($this->_nodes);
    }
    public function get($key)
    {
        $count = $this->_nodesCount;
        if ($count === 0) {
            throw new RuntimeException('No connections');
        }
        return $this->_nodes[$count > 1 ? abs(crc32($key) % $count) : 0];
    }
    public function generateKey($value)
    {
        return crc32($value);
    }
}
$options = array('key_distribution' => new NaiveDistributionStrategy());
$redis = new Predis_Client($multiple_servers, $options);
for ($i = 0; $i < 100; $i++) {
    $redis->set("key:{$i}", str_pad($i, 4, '0', 0));
    $redis->get("key:{$i}");
}
$server1 = $redis->getClientFor('first')->info();
$server2 = $redis->getClientFor('second')->info();
printf("Server '%s' has %d keys while server '%s' has %d keys.\n", 'first', $server1['db15']['keys'], 'second', $server2['db15']['keys']);
コード例 #2
0
                     ob_end_flush();
                 }
                 $html_of_page = ob_get_clean();
                 // ob_get_clean also closes the OB
                 echo $html_of_page;
                 if (!is_numeric($seconds_cache_redis)) {
                     $seconds_cache_redis = 86400;
                 }
                 if ($compress) {
                     $html_of_page = gzcompress($html_of_page, 1);
                 }
                 // When a page displays after an "HTTP 404: Not Found" error occurs, do not cache
                 // When the search was used, do not cache
                 if (!is_404() and !is_search()) {
                     if ($unlimited) {
                         $redis->set($redis_key, $html_of_page);
                     } else {
                         $redis->setex($redis_key, $seconds_cache_redis, $html_of_page);
                     }
                 }
             } else {
                 //either the user is logged in, or is posting a comment, show them uncached
                 require $wp_blog_header_path;
             }
         } else {
             if ($_SERVER['REMOTE_ADDR'] != $websiteIp && strstr($current_url, 'preview=true') == true) {
                 require $wp_blog_header_path;
             }
         }
     }
 }
コード例 #3
0
ファイル: SimpleSetAndGet.php プロジェクト: aadl/locum
<?php

require_once 'SharedConfigurations.php';
// simple set and get scenario
$redis = new Predis_Client($single_server);
$redis->set('library', 'predis');
$retval = $redis->get('library');
print_r($retval);
/* OUTPUT
predis
*/
コード例 #4
0
ファイル: index.php プロジェクト: rmoorman/web-bench
<?php

require 'predis/lib/Predis.php';
// simple set and get scenario
$single_server = array('host' => '10.174.178.235', 'port' => 6379, 'database' => 15);
$redis = new Predis_Client($single_server);
$retval = $redis->get('user_data');
/*
$raw = gzuncompress($retval);
$document = json_decode($raw, true);
$document['TWIDDLE'] = mt_rand(0, 10000);
for($i = 0; $i < 100; $i++){
	for($j = 0; $j < 100; $j++){
		$k = sin($i) * tan($j);
	}
}
*/
//echo "Len: " . strlen($raw) . " new val : " . $document['TWIDDLE'];
//print_r(json_encode($document));
//$retval = $redis->set('user_data', gzcompress(json_encode($document)));
$redis->set('user_data', $retval);
echo "OK\n";
//print_r($retval);
コード例 #5
0
ファイル: load_doc.php プロジェクト: rmoorman/web-bench
<?php

require '../php/predis/lib/Predis.php';
//$document = json_decode(file_get_contents("tiny.json"), true);
$document = json_decode(file_get_contents("document.json"), true);
// simple set and get scenario
$single_server = array('host' => '10.174.178.235', 'port' => 6379, 'database' => 0);
$redis = new Predis_Client($single_server);
//print_r($document);
$redis->set('user_data_node', json_encode($document));
//print_r($retval);