コード例 #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
ファイル: check_doc.php プロジェクト: rmoorman/web-bench
<?php

require '../php/predis/lib/Predis.php';
// simple set and get scenario
$single_server = array('host' => '10.174.178.235', 'port' => 6379, 'database' => 0);
$redis = new Predis_Client($single_server);
$result = $redis->get('user_data_2');
echo strlen($result) . "\n";
コード例 #3
0
     if ($debug) {
         echo "<!-- manual refresh was required -->\n";
     }
     $redis->del($redis_key);
     $redis->del("ssl_" . $redis_key);
     require $wp_blog_header_path;
     //$unlimited = get_option('wp-redis-cache-debug',false);
     $seconds_cache_redis = get_option('wp-redis-cache-seconds', 86400);
     // This page is cached, lets display it
 } else {
     if ($redis->exists($redis_key)) {
         if ($debug) {
             echo "<!-- serving page from cache: key: {$redis_key} -->\n";
         }
         $cache = true;
         $html_of_page = $redis->get($redis_key);
         if ($compress) {
             $html_of_page = gzuncompress($html_of_page);
         }
         echo $html_of_page;
         // If the cache does not exist lets display the user the normal page without cache, and then fetch a new cache page
     } else {
         if ($_SERVER['REMOTE_ADDR'] != $websiteIp && strstr($current_url, 'preview=true') == false) {
             if ($debug) {
                 echo "<!-- displaying page without cache -->\n";
             }
             $isPOST = $_SERVER['REQUEST_METHOD'] === 'POST' ? 1 : 0;
             $loggedIn = preg_match("/wordpress_logged_in/", var_export($_COOKIE, true));
             if (!$isPOST && !$loggedIn) {
                 ob_start();
                 $level = ob_get_level();
コード例 #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
ファイル: 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
*/
コード例 #6
0
 /**
  * @see sfCache
  */
 public function getLastModified($key)
 {
     return $this->redis->get($this->getKey($key, '_lastmodified'));
 }