Permalink
Browse files

prepare redis

  • Loading branch information...
sorah committed Oct 22, 2017
1 parent 914510d commit 2030f9a0f574ac8379dcdc8a894e4d4ed28cebbc
Showing with 14 additions and 1 deletion.
  1. +1 −0 env.sh
  2. +2 −0 isubata/webapp/ruby/Gemfile
  3. +5 −1 isubata/webapp/ruby/Gemfile.lock
  4. +6 −0 isubata/webapp/ruby/app.rb
View
1 env.sh
@@ -1,3 +1,4 @@
ISUBATA_DB_HOST=db
ISUBATA_DB_USER=isucon
ISUBATA_DB_PASSWORD=isucon
ISUBATA_REDIS_URL=redis://db:6379/0
@@ -4,3 +4,5 @@ gem 'mysql2'
gem 'puma'
gem 'sinatra'
gem 'sinatra-contrib'
gem 'hiredis'
gem 'redis'
@@ -2,13 +2,15 @@ GEM
remote: https://rubygems.org/
specs:
backports (3.9.1)
hiredis (0.6.1)
multi_json (1.12.2)
mustermann (1.0.1)
mysql2 (0.4.9)
puma (3.10.0)
rack (2.0.3)
rack-protection (2.0.0)
rack
redis (3.3.3)
sinatra (2.0.0)
mustermann (~> 1.0)
rack (~> 2.0)
@@ -27,10 +29,12 @@ PLATFORMS
ruby
DEPENDENCIES
hiredis
mysql2
puma
redis
sinatra
sinatra-contrib
BUNDLED WITH
1.13.7
1.15.4
@@ -1,6 +1,8 @@
require 'digest/sha1'
require 'mysql2'
require 'sinatra/base'
require 'hiredis'
require 'redis'
class App < Sinatra::Base
configure do
@@ -352,6 +354,10 @@ def icons_dir
@icons_dir ||= "#{ENV['HOME']}/public/icons"
end
def redis
Thread.current[:isubata_redis] ||= Redis.new(url: ENV.fetch('ISUBATA_REDIS_URL', 'redis://localhost:6379/0'))
end
def db
Thread.current[:isubata_db] ||= Mysql2::Client.new(
host: ENV.fetch('ISUBATA_DB_HOST') { 'localhost' },

0 comments on commit 2030f9a

Please sign in to comment.