Module: ConfigManager::Settings::Querying::ClassMethods

Defined in:
lib/config_manager/settings/querying.rb

Instance Method Summary collapse

Instance Method Details

#allObject



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/config_manager/settings/querying.rb', line 21

def all
	keys = $redis.smembers(global_key)
	return [] if keys.empty?

	values = $redis.mget(*keys)

	# remove deleted keys
	obsolete_keys = Range.new(0, keys.size, true).inject([]) do |memo, i|
		values.at(i) ? memo : (memo << keys.at(i))
	end

	unless obsolete_keys.empty?
		Rails.logger.info("DELETING OBSOLETE KEYS IN GLOBAL INDEX: #{obsolete_keys}")
		$redis.srem(global_key, obsolete_keys)
		keys = keys - obsolete_keys
		values.compact!
	end

	# get tags
	ids = keys.map {|k| k.gsub("#{prefix}:", '') }
	tag_keys = ids.map {|id| generate_tags_key(id) }
	tags = tag_keys.map {|key| $redis.smembers(key) }

	ids.zip(values, tags).map do |i,v, t|
		Setting.new(i, v, t)
	end
end

#find(id, with_tags = false) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
# File 'lib/config_manager/settings/querying.rb', line 9

def find(id, with_tags=false)
	key = generate_key(id)
	value = $redis.get(key)

	return nil unless value

	index = generate_tags_key(id)
	tags = with_tags ? $redis.smembers(index) : []

	new(id, value, tags)
end

#tagsObject



49
50
51
# File 'lib/config_manager/settings/querying.rb', line 49

def tags
	$redis.smembers(tag_global_key)
end