Class: Familia::List
Instance Attribute Summary
Attributes inherited from RedisObject
#cache, #name, #parent, #redis
Instance Method Summary
collapse
Methods inherited from RedisObject
#class?, #clear_cache, #db, #dump_method, #echo, #exists?, #expire, #expireat, #from_redis, inherited, #initialize, #load_method, #move, #multi_from_redis, #parent?, #persist, #qstamp, #realttl, #rediskey, register, registration, #rename, #renamenx, #to_redis, #ttl, #type, #update_expiration
Instance Method Details
#<<(v) ⇒ Object
Also known as:
add
363
364
365
|
# File 'lib/familia/redisobject.rb', line 363
def << v
push v
end
|
#[](idx, count = nil) ⇒ Object
Also known as:
slice
384
385
386
387
388
389
390
391
392
393
394
395
396
|
# File 'lib/familia/redisobject.rb', line 384
def [] idx, count=nil
if idx.is_a? Range
range idx.first, idx.last
elsif count
case count <=> 0
when 1 then range(idx, idx + count - 1)
when 0 then []
when -1 then nil
end
else
at idx
end
end
|
#at(idx) ⇒ Object
464
465
466
|
# File 'lib/familia/redisobject.rb', line 464
def at idx
from_redis redis.lindex(rediskey, idx)
end
|
#collect(&blk) ⇒ Object
448
449
450
|
# File 'lib/familia/redisobject.rb', line 448
def collect &blk
range.collect &blk
end
|
#collectraw(&blk) ⇒ Object
456
457
458
|
# File 'lib/familia/redisobject.rb', line 456
def collectraw &blk
rangeraw.collect &blk
end
|
#delete(v, count = 0) ⇒ Object
Also known as:
remove, rem, del
399
400
401
|
# File 'lib/familia/redisobject.rb', line 399
def delete v, count=0
redis.lrem rediskey, count, to_redis(v)
end
|
#each(&blk) ⇒ Object
def revmembers count=1 #TODO
range -count, 0
end
432
433
434
|
# File 'lib/familia/redisobject.rb', line 432
def each &blk
range.each &blk
end
|
#each_with_index(&blk) ⇒ Object
436
437
438
|
# File 'lib/familia/redisobject.rb', line 436
def each_with_index &blk
range.each_with_index &blk
end
|
#eachraw(&blk) ⇒ Object
440
441
442
|
# File 'lib/familia/redisobject.rb', line 440
def eachraw &blk
rangeraw.each &blk
end
|
#eachraw_with_index(&blk) ⇒ Object
444
445
446
|
# File 'lib/familia/redisobject.rb', line 444
def eachraw_with_index &blk
rangeraw.each_with_index &blk
end
|
#empty? ⇒ Boolean
351
352
353
|
# File 'lib/familia/redisobject.rb', line 351
def empty?
size == 0
end
|
#first ⇒ Object
468
469
470
|
# File 'lib/familia/redisobject.rb', line 468
def first
at 0
end
|
#last ⇒ Object
472
473
474
|
# File 'lib/familia/redisobject.rb', line 472
def last
at -1
end
|
#members(count = -1) ⇒ Object
Also known as:
all, to_a
415
416
417
418
419
|
# File 'lib/familia/redisobject.rb', line 415
def members count=-1
echo :members, caller[0] if Familia.debug
count -= 1 if count > 0
range 0, count
end
|
#membersraw(count = -1) ⇒ Object
423
424
425
426
|
# File 'lib/familia/redisobject.rb', line 423
def membersraw count=-1
count -= 1 if count > 0
rangeraw 0, count
end
|
#pop ⇒ Object
376
377
378
|
# File 'lib/familia/redisobject.rb', line 376
def pop
from_redis redis.rpop(rediskey)
end
|
#push(*values) ⇒ Object
355
356
357
358
359
360
361
|
# File 'lib/familia/redisobject.rb', line 355
def push *values
echo :push, caller[0] if Familia.debug
values.flatten.compact.each { |v| redis.rpush rediskey, to_redis(v) }
redis.ltrim rediskey, -@opts[:maxlength], -1 if @opts[:maxlength]
update_expiration
self
end
|
#range(sidx = 0, eidx = -1) ⇒ Object
406
407
408
409
|
# File 'lib/familia/redisobject.rb', line 406
def range sidx=0, eidx=-1
el = rangeraw sidx, eidx
multi_from_redis *el
end
|
#rangeraw(sidx = 0, eidx = -1) ⇒ Object
411
412
413
|
# File 'lib/familia/redisobject.rb', line 411
def rangeraw sidx=0, eidx=-1
redis.lrange(rediskey, sidx, eidx)
end
|
#select(&blk) ⇒ Object
452
453
454
|
# File 'lib/familia/redisobject.rb', line 452
def select &blk
range.select &blk
end
|
#selectraw(&blk) ⇒ Object
460
461
462
|
# File 'lib/familia/redisobject.rb', line 460
def selectraw &blk
rangeraw.select &blk
end
|
#shift ⇒ Object
380
381
382
|
# File 'lib/familia/redisobject.rb', line 380
def shift
from_redis redis.lpop(rediskey)
end
|
#size ⇒ Object
Also known as:
length
346
347
348
|
# File 'lib/familia/redisobject.rb', line 346
def size
redis.llen rediskey
end
|
#unshift(*values) ⇒ Object
368
369
370
371
372
373
374
|
# File 'lib/familia/redisobject.rb', line 368
def unshift *values
values.flatten.compact.each { |v| redis.lpush rediskey, to_redis(v) }
redis.ltrim rediskey, 0, @opts[:maxlength] - 1 if @opts[:maxlength]
update_expiration
self
end
|