-
-
Save devblueray/6257900 to your computer and use it in GitHub Desktop.
require "redis" | |
require "json" | |
require "sinatra" | |
$redis = Redis.new(:host => "127.0.0.1", :port => 6379) | |
ONE_WEEK_IN_SECONDS = 7 * 86400 | |
def article(aid,poster,title,atext) | |
artstuff = {:title => title, :poster => poster,:atext => atext} | |
$redis.hmset(aid,*artstuff ) | |
end | |
def get_articles(*nums) | |
puts "nums: " + nums.class.to_s | |
nums.each do |r| | |
puts "r: " + r.class.to_s | |
myjson = $redis.hmget(r,"title", "poster", "atext").to_json | |
parsed_json = JSON.parse(myjson) | |
puts "Title: " + parsed_json[0].to_s + "\n" | |
print "Author: " + parsed_json[1].to_s + "\n" | |
print "Text: " + parsed_json[2].to_s + "\n" | |
end | |
end | |
set :environment, :production | |
get '/' do | |
get_articles(1,2) | |
end |
ruby insert.rb
[2013-08-17 18:42:09] INFO WEBrick 1.3.1
[2013-08-17 18:42:09] INFO ruby 1.9.3 (2013-06-27) [x86_64-linux]
== Sinatra/1.4.3 has taken the stage on 4567 for production with backup from WEBrick
[2013-08-17 18:42:09] INFO WEBrick::HTTPServer#start: pid=6646 port=4567
nums: Array
r: Fixnum
Title: Day in the life.of..
Author: Jason
Text: A day of the life of me
r: Fixnum
Title: This is the...
Author: Bob
Text: Pickles!
68.71.240.137 - - [17/Aug/2013 18:42:13] "GET / HTTP/1.1" 1 - 0.0044
[2013-08-17 18:42:13] ERROR NoMethodError: undefined method each' for 2:Fixnum /usr/local/lib64/ruby/gems/1.9.1/gems/rack-1.5.2/lib/rack/body_proxy.rb:31:in
each'
/usr/local/lib64/ruby/gems/1.9.1/gems/rack-1.5.2/lib/rack/handler/webrick.rb:72:in service' /usr/lib64/ruby/1.9.1/webrick/httpserver.rb:138:in
service'
/usr/lib64/ruby/1.9.1/webrick/httpserver.rb:94:in run' /usr/lib64/ruby/1.9.1/webrick/server.rb:191:in
block in start_thread'
ip - - [17/Aug/2013:18:42:13 PDT] "GET / HTTP/1.1" 500 318
- -> /
[2013-08-17 18:42:13] ERROR NoMethodError: undefined method each' for 2:Fixnum
/usr/local/lib64/ruby/gems/1.9.1/gems/rack-1.5.2/lib/rack/body_proxy.rb:31:ineach'
/usr/local/lib64/ruby/gems/1.9.1/gems/rack-1.5.2/lib/rack/handler/webrick.rb:72:in service'
/usr/lib64/ruby/1.9.1/webrick/httpserver.rb:138:inservice'
/usr/lib64/ruby/1.9.1/webrick/httpserver.rb:94:in run'
/usr/lib64/ruby/1.9.1/webrick/server.rb:191:inblock in start_thread'
ip - - [17/Aug/2013:18:42:13 PDT] "GET / HTTP/1.1" 500 318
ruby insert.rb
[2013-08-17 18:38:28] INFO WEBrick 1.3.1
[2013-08-17 18:38:28] INFO ruby 1.9.3 (2013-06-27) [x86_64-linux]
== Sinatra/1.4.3 has taken the stage on 4567 for production with backup from WEBrick
[2013-08-17 18:38:28] INFO WEBrick::HTTPServer#start: pid=6618 port=4567
nums: Array
r: Fixnum
Title: This is the...
Author: Bob
Text: Pickles!
68.71.240.137 - - [17/Aug/2013 18:38:33] "GET / HTTP/1.1" 2 - 0.0040
ip- - - [17/Aug/2013:18:38:33 PDT] "GET / HTTP/1.1" 2 0