Created
December 13, 2011 18:55
-
-
Save flexd/1473351 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require "cinch/storage" | |
require "redis" | |
require "redis/objects" | |
require "redis/hash_key" | |
module Cinch | |
class Storage | |
class Redis < Storage | |
def initialize(options, plugin) | |
# New Redis object, thread safe by default since 2.2.0 | |
redis = Redis.new(:host => 'localhost', :port => 6379) | |
@hash = Redis::HashKey.new(plugin.name, redis) | |
@options = options | |
# Do we need a mutex like the yaml plugin? Thread safe and all. | |
end | |
def has_key?(key) | |
@hash.has_key?(key) | |
end | |
alias_method :include?, :has_key? | |
alias_method :key?, :has_key? | |
alias_method :member?, :has_key? | |
def delete(key) | |
@hash.delete(key) | |
end | |
def each | |
@hash.each | |
end | |
def each_value | |
@hash.each_value | |
end | |
def each_key | |
@hash.each_key | |
end | |
def [](key) | |
@hash[key] | |
end | |
def []=(key, value) | |
@hash[key] = value | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment