class ActiveOrm::Redis::List < ActiveOrm::Redis def self.find(key, position=1) value = client.lindex(normalize_key(key), (position - 1)) value = metamorph(value) if evaluate? value end def self.first(key, limit=1) value = client.lrange(normalize_key(key), 0, -1) value = ((limit == 1) ? value.first : value.first(limit)) value = metamorph(value) if evaluate? value end def self.last(key, limit=1) value = client.lrange(normalize_key(key), 0, -1) value = ((limit == 1) ? value.last : value.last(limit)) value = metamorph(value) if evaluate? value end def self.between(key, start=1, finish=0) value = client.lrange(normalize_key(key), (start - 1), (finish - 1)) value = metatransform(value) value end def self.all(key) value = client.lrange(normalize_key(key), 0, -1) value = metatransform(value) value end def self.count(key) client.llen(normalize_key(key)) end def self.create(key, value, order=:prepend) append?(order) ? client.rpush(normalize_key(key), value) : client.lpush(normalize_key(key), value) end def self.create!(key, value, order=:prepend) append?(order) ? client.rpushx(normalize_key(key), value) : client.lpushx(normalize_key(key), value) end def self.create_limit(key, value, limit, order=:prepend) append?(order) ? client.rpush(normalize_key(key), value) : client.lpush(normalize_key(key), value) client.ltrim(normalize_key(key), 0, (limit - 1)) end def self.create_limit!(key, value, limit, order=:prepend) append?(order) ? client.rpushx(normalize_key(key), value) : client.lpushx(normalize_key(key), value) client.ltrim(normalize_key(key), 0, (limit - 1)) end def self.create_before(key, pivot, value) client.linsert(normalize_key(key), :before, pivot, value) end def self.create_after(key, pivot, value) client.linsert(normalize_key(key), :after, pivot, value) end def self.update(key, index, value) client.lset(normalize_key(key), index, value) end def self.move(key, desination) value = client.rpoplpush(normalize_key(key), normalize_key(desination)) value = metamorph(value) if evaluate? value end def self.move_blocking(key, desination, opts={}) value = brpoplpush(normalize_key(key), normalize_key(desination)) value = metamorph(value) if evaluate? value end def self.destroy(key, count, value) client.lrem(normalize_key(key), count, value) end def self.destroy_first(key, limit=1) client.ltrim(normalize_key(key), limit, -1) end def self.destroy_last(key, limit=1) client.ltrim(normalize_key(key), 0, -(limit + 1)) end def self.destroy_except(key, start, finish) client.ltrim(normalize_key(key), (start - 1), (finish - 1)) end def self.destroy_all(key) client.ltrim(normalize_key(key), -1, 0) end def self.pop(key, order=:prepend) value = append?(order) ? client.rpop(key) : client.lpop(key) value = metamorph(value) if evaluate? value end def self.pop_blocking(keys, opts={}) value = append?(opts.fetch(:order, :prepend)) ? client.brpop(keys, opts.fetch(:timeout, 0)) : client.blpop(keys, opts.fetch(:timeout, 0)) value = metamorph(value) if evaluate? value end end