Files
redistat/lib/redistat/label.rb
Jim Myhrberg 18e6125c6a Added support for connection_ref's down throughout
the code, so models can connect to specific Redis
servers.

I believe a lot of the code needs some
restructuring at some point down the line to
handle multiple connections in a cleaner way, but
for now it'll do.
2010-11-28 11:47:26 +00:00

39 lines
686 B
Ruby

module Redistat
class Label
include Database
attr_reader :raw
attr_reader :connection_ref
def initialize(str, options = {})
@options = options
@raw = str.to_s
end
def db
super(@options[:connection_ref])
end
def name
@options[:hashed_label] ? hash : @raw
end
def hash
@hash ||= Digest::SHA1.hexdigest(@raw)
end
def save
@saved = (db.set("#{KEY_LEBELS}#{hash}", @raw) == "OK") if @options[:hashed_label]
self
end
def saved?
@saved ||= false
end
def self.create(name, options = {})
self.new(name, options).save
end
end
end