Skip to content

Instantly share code, notes, and snippets.

@flexd
Created December 13, 2011 18:55
Show Gist options
  • Save flexd/1473351 to your computer and use it in GitHub Desktop.
Save flexd/1473351 to your computer and use it in GitHub Desktop.
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