こちらで定めた仕様を満たすサーバーサイドのプログラムです。
Nginx + fcgiwrap で動作を確認しました。
Redis の WebAPI を作成
redis_read.rb
#! /usr/bin/ruby
# -*- coding: utf-8 -*-
# ---------------------------------------------------------------------
# redis_read.ruby
#
# Jan/16/2020
#
# ---------------------------------------------------------------------
require 'redis'
require "cgi"
require "json"
#
STDERR.puts "*** 開始 ***"
#
$cgi=CGI.new
key = $cgi["key"]
# key = "t1852"
redis = Redis.new(:host => "localhost", :port => 6379)
value = redis.get key
puts "Content-type: text/json; charset=UTF-8\n\n"
puts value
#
STDERR.puts "*** 終了 ***"
# ---------------------------------------------------------------------
redis_insert.rb
#! /usr/bin/ruby
# -*- coding: utf-8 -*-
# ---------------------------------------------------------------------
# redis_insert.ruby
#
# Jan/16/2020
#
# ---------------------------------------------------------------------
require 'redis'
require "cgi"
require "json"
#
STDERR.puts "*** 開始 ***"
#
$cgi=CGI.new
key = $cgi["key"]
value = $cgi["value"]
redis = Redis.new(:host => "localhost", :port => 6379)
redis.set key,value
puts "Content-type: text/json; charset=UTF-8\n\n"
#
puts value
#
STDERR.puts "*** 終了 ***"
redis_list.rb
#! /usr/bin/ruby
# -*- coding: utf-8 -*-
# ---------------------------------------------------------------------
# redis_list.ruby
#
# Jan/16/2020
#
# ---------------------------------------------------------------------
require 'redis'
require 'json'
#
STDERR.puts "*** 開始 ***"
#
redis = Redis.new(:host => "localhost", :port => 6379)
keys = redis.keys
json_str = JSON.pretty_generate(keys)
puts "Content-type: text/json; charset=UTF-8\n\n"
puts json_str
#
STDERR.puts "*** 終了 ***"
# ---------------------------------------------------------------------