Redis の WebAPI (PHP CGI)


こちらで定めた仕様を満たすサーバーサイドのプログラムです。
Nginx + php-fpm で動作を確認しました。
Redis の WebAPI を作成

redis_read.php
<?php
// ---------------------------------------------------------------------
//  redis_read.php
//
//                  Jan/15/2020
//
// ---------------------------------------------------------------------
if (isset ($_POST['key']))
    {
    $key = $_POST['key'];
    try
        {
        $redis = new Redis();
        $redis->connect('localhost', 6379);
        $json_str = $redis->get ($key);
        echo $json_str;
        }
    catch  (PDOException $e)
        {
        print('Error:'.$e->getMessage());
        }
    }
// ---------------------------------------------------------------------
?>
redis_insert.php
<?php
// ---------------------------------------------------------------------
//  redis_insert.php
//
//                  Jan/15/2020
//
// ---------------------------------------------------------------------
if (isset ($_POST['key']))
    {
    $key = $_POST['key'];
    $json_str = $_POST['value'];
    try
        {
        $redis = new Redis();
        $redis->connect('localhost', 6379);
        $redis->set ($key,$json_str);
        echo $json_str;
        }
    catch  (PDOException $e)
        {
        print('Error:'.$e->getMessage());
        }
    }
// ---------------------------------------------------------------------
?>
redis_list.php
<?php
// ---------------------------------------------------------------------
//  redis_list.php
//
//                  Jan/15/2020
//
// ---------------------------------------------------------------------
    try
        {
        $redis = new Redis();
        $redis->connect('localhost', 6379);
        $keys = $redis->keys ('*');
        $json_str = json_encode ($keys);
        echo $json_str;
        }
    catch  (PDOException $e)
        {
        print('Error:'.$e->getMessage());
        }
// ---------------------------------------------------------------------
?>

サーバーの状況 (Ubuntu 19.10)

$ sudo systemctl status php7.3-fpm
● php7.3-fpm.service - The PHP 7.3 FastCGI Process Manager
   Loaded: loaded (/lib/systemd/system/php7.3-fpm.service; enabled; vendor prese
   Active: active (running) since Wed 2020-01-15 15:42:34 JST; 2h 9min ago
     Docs: man:php-fpm7.3(8)
 Main PID: 1171 (php-fpm7.3)
   Status: "Processes active: 0, idle: 2, Requests: 25, slow: 0, Traffic: 0req/s
    Tasks: 3 (limit: 4417)
   Memory: 16.5M
   CGroup: /system.slice/php7.3-fpm.service
           ├─1171 php-fpm: master process (/etc/php/7.3/fpm/php-fpm.conf)
           ├─1442 php-fpm: pool www
           └─1443 php-fpm: pool www