github.com/deemoprobe/k8s-first-commit@v0.0.0-20230430165612-a541f1982be3/examples/guestbook/index.php (about) 1 <? 2 3 set_include_path('.:/usr/share/php:/usr/share/pear:/vendor/predis'); 4 5 error_reporting(E_ALL); 6 ini_set('display_errors', 1); 7 8 require 'predis/autoload.php'; 9 10 if (isset($_GET['cmd']) === true) { 11 header('Content-Type: application/json'); 12 if ($_GET['cmd'] == 'set') { 13 $client = new Predis\Client([ 14 'scheme' => 'tcp', 15 'host' => getenv('SERVICE_HOST'), 16 'port' => getenv('REDISMASTER_SERVICE_PORT'), 17 ]); 18 $client->set($_GET['key'], $_GET['value']); 19 print('{"message": "Updated"}'); 20 } else { 21 $read_port = getenv('REDISMASTER_SERVICE_PORT'); 22 23 if (isset($_ENV['REDISSLAVE_SERVICE_PORT'])) { 24 $read_port = getenv('REDISSLAVE_SERVICE_PORT'); 25 } 26 $client = new Predis\Client([ 27 'scheme' => 'tcp', 28 'host' => getenv('SERVICE_HOST'), 29 'port' => $read_port, 30 ]); 31 32 $value = $client->get($_GET['key']); 33 print('{"data": "' . $value . '"}'); 34 } 35 } else { 36 phpinfo(); 37 } ?>