mirror of
https://github.com/jimeh/redistat.git
synced 2026-02-19 13:26:39 +00:00
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.
39 lines
686 B
Ruby
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 |