Skip to content

Instantly share code, notes, and snippets.

@Gazler
Created March 23, 2012 09:38
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 Gazler/2169022 to your computer and use it in GitHub Desktop.
Save Gazler/2169022 to your computer and use it in GitHub Desktop.
ActiveRedis
class User
@redis = Redis.new
def method_missing(m, * args, &block)
return @data[m.to_s] if @data.has_key?(m.to_s)
super
end
def initialize(data)
@data = data
end
class << self
def find(id)
response = @redis.get(id)
return nil unless response
self.new(JSON.parse(response))
end
def create(id, options)
@redis.set(id, options.to_json)
end
end
end
#Usage
#
#user = User.find(KEY)
#
#User.create(KEY, {:name => "Gazler"}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment