Created
December 13, 2011 19:37
-
-
Save flexd/1473542 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" | |
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 | |
@options = options | |
# Do we need a mutex like the yaml plugin? Thread safe and all. | |
end | |
def has_key?(key) | |
@redis.hexists(plugin.name, key) | |
end | |
alias_method :include?, :has_key? | |
alias_method :key?, :has_key? | |
alias_method :member?, :has_key? | |
def delete(key) | |
# redis.hdel returns the number of fields removed from the hash. | |
return true if @redis.hdel(plugin.name,key) >= 1 | |
return false | |
end | |
def each | |
@redis.hgetall plugin.name # Untested! | |
end | |
def each_value | |
@redis.hvals plugin.name | |
end | |
def each_key | |
@redis.hkeys plugin.name | |
end | |
def [](key) | |
@redis.hget(plugin.name, key) | |
end | |
def []=(key, value) | |
@redis.hset(plugin.name, key, value) | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment