Class: VK::HASHLIST

Inherits:
O
  • Object
show all
Defined in:
lib/valkey/objects.rb

Instance Attribute Summary

Attributes inherited from O

#key

Instance Method Summary collapse

Methods inherited from O

#delete!, #expire, #initialize

Constructor Details

This class inherits a constructor from VK::O

Instance Method Details

#[](k) ⇒ Object



638
639
640
641
# File 'lib/valkey/objects.rb', line 638

def [] k
  hx = %[#{key}-#{k}]
  JSON.parse(VK.redis.call("GET", hx));      
end

#firstObject



648
649
650
# File 'lib/valkey/objects.rb', line 648

def first
    VK.redis.call("LRANGE", key, 0, 0)[0]
end

#lastObject



651
652
653
# File 'lib/valkey/objects.rb', line 651

def last
    VK.redis.call("LRANGE", key, -1, -1)[0]
end

#lengthObject



635
636
637
# File 'lib/valkey/objects.rb', line 635

def length
  VK.redis.call("LLEN", key)
end

#push(h = {}) ⇒ Object



642
643
644
645
646
647
# File 'lib/valkey/objects.rb', line 642

def push h={}
  hx = %[#{key}-#{length}]
  VK.redis.call("SET", hx, JSON.generate(h));
  VK.redis.call("RPUSH", key, hx)
  return hx
end

#value(&b) ⇒ Object



618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
# File 'lib/valkey/objects.rb', line 618

def value &b
  a = []
  VK.redis.call("LRANGE", key, 0, -1).each_with_index { |e, i|
    if block_given?
      a << b.call(i, JSON.parse(VK.redis.call("GET", e)))
    else
      a << JSON.parse(VK.redis.call("GET", e))
    end
    if @opts.has_key?(:flush) == true
      VK.redis.call("DEL", e)
    end
  }
  if @opts.has_key?(:flush) == true
    delete!
  end
  return a
end