Skip to content

Instantly share code, notes, and snippets.

@raa0121
Created January 13, 2015 15:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save raa0121/dbdd5e0b797cc286fb6c to your computer and use it in GitHub Desktop.
Save raa0121/dbdd5e0b797cc286fb6c to your computer and use it in GitHub Desktop.
# encoding: utf-8
require 'java'
require 'singleton'
import 'redis.clients.jedis.Jedis'
import 'redis.clients.jedis.JedisPool'
import 'redis.clients.jedis.JedisPoolConfig'
module Rukkit
class Redis
class << self
include Singleton
def initialize(db = 666)
@pool = JedisPool.new(JedisPoolConfig.new, "localhost")
@jedis = @pool.getResource
@connection = @jedis.select(db)
end
def connect(db)
begin
@jedis.select(db)
rescue Exception => e
puts e.message
puts e.backtrace.inspect
else
# other exception
ensure
# always executed
end
end
def set(key, value)
begin
@jedis.set(key, value)
rescue Exception => e
puts e.message
puts e.backtrace.inspect
else
# other exception
ensure
# always executed
end
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment