summaryrefslogtreecommitdiffhomepage
path: root/images/benchmarks/ruby/main.rb
blob: b998f004e8b509143ee9e81a8caca06cdbcc220e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
require "sinatra"
require "securerandom"
require "redis"

redis_host = ENV["HOST"]
$redis = Redis.new(host: redis_host)

def generateText
    for i in 0..99
        $redis.set(i, randomBody(1024))
    end
end

def randomBody(length)
    return SecureRandom.alphanumeric(length)
end

generateText
template = ERB.new(File.read('./index.erb'))

get "/" do
    texts = Array.new
    for i in 0..4
        texts.push($redis.get(rand(0..99)))
    end
    template.result_with_hash(text: texts)
end