/** *Benchmarks tcp vs unix sockets */ function connection() { global $redis; $redis = new \RWKY\Redis\Redis(); $redis->config("PORT", 6379); echo "Benchmarking tcp vs unix socket using pipelining" . PHP_EOL; $redis->flushdb(); $nonPipe = microtime(true); $redis->pipe(); for ($i = 0; $i < 10000; $i++) { $redis->set("key{$i}", $i); } $redis->drain(); echo "TCP time to set 10,000 times = " . (microtime(true) - $nonPipe) . " seconds" . PHP_EOL; sleep(1); $redis = new \RWKY\Redis\Redis(); $redis->config("UNIX_SOCKET", "/tmp/redis-test.sock"); $redis->flushdb(); echo "Unix socket..." . PHP_EOL; $pipe = microtime(true); $redis->pipe(); for ($i = 0; $i < 10000; $i++) { $redis->set("key{$i}", $i); } $redis->drain(); echo "UNIX Socket time to set 10,000 times = " . (microtime(true) - $pipe) . " seconds" . PHP_EOL; $redis->flushdb(); $redis = new \RWKY\Redis\Redis(); $redis->config("PORT", 6379); echo "Benchmarking tcp vs unix socket without using pipelining" . PHP_EOL; $redis->flushdb(); $nonPipe = microtime(true); for ($i = 0; $i < 10000; $i++) { $redis->set("key{$i}", $i); } echo "TCP time to set 10,000 times = " . (microtime(true) - $nonPipe) . " seconds" . PHP_EOL; sleep(1); $redis = new \RWKY\Redis\Redis(); $redis->config("UNIX_SOCKET", "/tmp/redis-test.sock"); $redis->flushdb(); echo "Unix socket..." . PHP_EOL; $pipe = microtime(true); for ($i = 0; $i < 10000; $i++) { $redis->set("key{$i}", $i); } echo "UNIX Socket time to set 10,000 times = " . (microtime(true) - $pipe) . " seconds" . PHP_EOL; $redis->flushdb(); $redis = new \RWKY\Redis\Redis(); $redis->config("PORT", 6379); }
<?php require "rwky-redis.php"; $redis = new \RWKY\Redis\Redis(); $response = $redis->pipe()->set("Question", "What is your favourite colour?")->set("Answer", "Blue...no yellow..ARGHHHH")->get("Question")->get("Answer")->drain(); print_r($response);