Created
March 23, 2012 09:38
-
-
Save Gazler/2169022 to your computer and use it in GitHub Desktop.
ActiveRedis
This file contains hidden or 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
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