class Relix::MultiIndex
Public Instance Methods
deindex(r, pk, old_value)
click to toggle source
# File lib/relix/indexes/multi.rb, line 18 def deindex(r, pk, old_value) r.zrem(key_for(old_value), pk) deindex_value(r, old_value) if index_values? end
deindex_value(r, old_value)
click to toggle source
# File lib/relix/indexes/multi.rb, line 59 def deindex_value(r, old_value) r.eval %( if(redis.call("ZCARD", KEYS[2]) == 0) then return redis.call("SREM", KEYS[1], ARGV[1]) end return "OK" ), [values_key, key_for(old_value)], [old_value] end
destroy(r, pk, old_value)
click to toggle source
# File lib/relix/indexes/multi.rb, line 23 def destroy(r, pk, old_value) r.del(key_for(old_value)) r.destroy_values(r) if index_values? end
destroy_value(r)
click to toggle source
# File lib/relix/indexes/multi.rb, line 68 def destroy_value(r) r.del(values_key) end
eq(r, value, options={})
click to toggle source
# File lib/relix/indexes/multi.rb, line 28 def eq(r, value, options={}) r.zrange(key_for(value), *range_from_options(r, options, value)) end
index(r, pk, object, value, old_value)
click to toggle source
# File lib/relix/indexes/multi.rb, line 11 def index(r, pk, object, value, old_value) r.zadd(key_for(value), score(object, value), pk) index_value(r, value) if index_values? deindex(r, pk, old_value) end
index_value(r, value)
click to toggle source
# File lib/relix/indexes/multi.rb, line 55 def index_value(r, value) r.sadd(values_key, value) end
index_values?()
click to toggle source
# File lib/relix/indexes/multi.rb, line 42 def index_values? @options[:index_values] end
key_for(value)
click to toggle source
# File lib/relix/indexes/multi.rb, line 38 def key_for(value) @set.keyer.component(name, value) end
position(r, pk, value)
click to toggle source
# File lib/relix/indexes/multi.rb, line 32 def position(r, pk, value) position = r.zrank(key_for(value), pk) raise MissingIndexValueError, "Cannot find key #{pk} in index for #{value}" unless position position end
values(r)
click to toggle source
# File lib/relix/indexes/multi.rb, line 50 def values(r) raise ValuesNotIndexedError.new("Value indexing not enabled for #{name}.") unless index_values? r.smembers(values_key) end
values_key()
click to toggle source
# File lib/relix/indexes/multi.rb, line 46 def values_key @set.keyer.component(name, "_values") end
watch_keys(*values)
click to toggle source
# File lib/relix/indexes/multi.rb, line 5 def watch_keys(*values) keys = values.compact.map { |v| key_for(v) } keys << values_key if index_values? keys end