Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save yuiseki/289049 to your computer and use it in GitHub Desktop.
Save yuiseki/289049 to your computer and use it in GitHub Desktop.
require 'rubygems'
require 'sinatra'
require 'tokyotyrant'
include TokyoTyrant
helpers do
def get_recents()
rdb = RDBTBL::new
rdb.open('localhost', 1978)
qry = RDBQRY::new(rdb)
qry.setorder('', RDBQRY::QONUMDESC) # 主キーを数値型と想定し降順でソート
qry.setlimit(10, 0) # 取得上限件数、オフセット数
qry.searchget
end
end
get '/' do
@records = get_recents()
result = []
@records.each do |r|
r.each_pair{|key, value|result.push "<b>#{key.to_s}</b>: #{value.to_s}<br />"}
result.push "<br />"
end
result.join("")
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment