LoginSignup
0
0

More than 3 years have passed since last update.

Redis の WebAPI (Ruby CGI)

Posted at

こちらで定めた仕様を満たすサーバーサイドのプログラムです。
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 "*** 終了 ***"
# ---------------------------------------------------------------------
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0