public function testHashes() { $this->assertEquals(1, $this->credis->hSet('hash', 'field1', 'foo')); $this->assertEquals(0, $this->credis->hSet('hash', 'field1', 'foo')); $this->assertEquals('foo', $this->credis->hGet('hash', 'field1')); $this->assertEquals(NULL, $this->credis->hGet('hash', 'x')); $this->assertTrue($this->credis->hMSet('hash', array('field2' => 'Hello', 'field3' => 'World'))); $this->assertEquals(array('foo', 'Hello', FALSE), $this->credis->hMGet('hash', array('field1', 'field2', 'nilfield'))); $this->assertEquals(array(), $this->credis->hGetAll('nohash')); $this->assertEquals(array('field1' => 'foo', 'field2' => 'Hello', 'field3' => 'World'), $this->credis->hGetAll('hash')); }
/** * @param string $id * @return array * @throws Exception */ public function _inspectSession($id) { if (!$this->_useRedis) { throw new Exception('Not connected to redis!'); } $sessionId = 'sess_' . $id; $this->_redis->select($this->_dbNum); $data = $this->_redis->hGetAll($sessionId); if ($data && isset($data['data'])) { $data['data'] = $this->_decodeData($data['data']); } return $data; }
public function testHashes() { $this->assertEquals(1, $this->credis->hSet('hash', 'field1', 'foo')); $this->assertEquals(0, $this->credis->hSet('hash', 'field1', 'foo')); $this->assertEquals('foo', $this->credis->hGet('hash', 'field1')); $this->assertEquals(NULL, $this->credis->hGet('hash', 'x')); $this->assertTrue($this->credis->hMSet('hash', array('field2' => 'Hello', 'field3' => 'World'))); $this->assertEquals(array('foo', 'Hello', FALSE), $this->credis->hMGet('hash', array('field1', 'field2', 'nilfield'))); $this->assertEquals(array(), $this->credis->hGetAll('nohash')); $this->assertEquals(array('field1' => 'foo', 'field2' => 'Hello', 'field3' => 'World'), $this->credis->hGetAll('hash')); // Test long hash values $longString = str_repeat(md5('asd'), 4096); // 128k (redis.h REDIS_INLINE_MAX_SIZE = 64k) $this->assertEquals(1, $this->credis->hMSet('long_hash', array('count' => 1, 'data' => $longString)), 'Set long hash value'); $this->assertEquals($longString, $this->credis->hGet('long_hash', 'data'), 'Get long hash value'); }
/** * @param string $id * @return array * @throws \Exception */ public function _inspectSession($id) { $sessionId = strpos($id, 'sess_') === 0 ? $id : 'sess_' . $id; $this->_redis->select($this->_dbNum); $data = $this->_redis->hGetAll($sessionId); if ($data && isset($data['data'])) { $data['data'] = $this->_decodeData($data['data']); } return $data; }
$vcl = $varnish->vcl_list(); if ($vcl["code"] != Nexcessnet_Turpentine_Model_Varnish_Admin_Socket::CODE_OK) { die("Unable to read VCLs from Varnish"); } $vcl = explode("\n", trim($vcl["text"]))[0]; $vcl = explode(" ", $vcl); $vcl = $vcl[sizeof($vcl) - 1]; $vcl = $varnish->vcl_show($vcl); if ($vcl["code"] != Nexcessnet_Turpentine_Model_Varnish_Admin_Socket::CODE_OK) { die("Unable to read latest VCL from Varnish"); } $vcl = $vcl["text"]; $vcl = preg_replace("/#AUTOGENERATED_START.*#AUTOGENERATED_END/ms", "#AUTOGENERATED_START\n#AUTOGENERATED_END", $vcl); $vcl = explode("\n", $vcl); $apaches = array(); $hosts = array_keys($redis->hGetAll("fb_apache_containers")); foreach ($hosts as $host) { $hostname = "apache_" . str_replace(".", "_", $host); $apaches[$hostname] = $host; } ksort($apaches); $hosts_to_add_to_vcl = ""; foreach ($apaches as $name => $ip) { $hosts_to_add_to_vcl .= "backend {$name} {\n\t.host = \"{$ip}\";\n\t.port = \"80\";\n\t.probe = {.url = \"{$probe_file}\";.timeout = 1s;.interval = 5s;.window = 1;.threshold = 1;}\n}\n"; } $hosts_to_add_to_vcl .= "sub vcl_init {\n\tnew cluster1 = directors.round_robin();\n"; foreach ($apaches as $name => $ip) { $hosts_to_add_to_vcl .= "\tcluster1.add_backend({$name});\n"; } $hosts_to_add_to_vcl .= "}\n"; $hosts_to_add_to_vcl .= "sub vcl_recv {set req.backend_hint = cluster1.backend();}\n";