Redis的WebAPI(Ruby CGI)
这是一个满足指定要求的服务器端程序。
经过 Nginx + fcgiwrap 的确认以确保正常运行。
创建了一个 Redis 的 WebAPI。
#! /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 "*** 終了 ***"
# ---------------------------------------------------------------------
#! /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 "*** 終了 ***"
#! /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 "*** 終了 ***"
# ---------------------------------------------------------------------