Class: VK::SET

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



539
540
541
# File 'lib/valkey/objects.rb', line 539

def & k
  VK.redis.call("SINTER", key, k.key)
end

#<<(i) ⇒ Object



533
534
535
# File 'lib/valkey/objects.rb', line 533

def << i
  VK.redis.call("SADD", key, i)
end

#[](k) ⇒ Object



545
546
547
548
549
# File 'lib/valkey/objects.rb', line 545

def [] k
  r, h = Regexp.new(k), {}
  VK.redis.call("SMEMBERS", key).each { |e| if m = r.match(e); h[e] = m; end; }
  return h
end

#include?(k) ⇒ Boolean

Returns:

  • (Boolean)


523
524
525
526
527
528
529
# File 'lib/valkey/objects.rb', line 523

def include? k
  if VK.redis.call("SMISMEMBER", key, k)[0] == 0
    return false
  else
    return true
  end
end

#lengthObject



530
531
532
# File 'lib/valkey/objects.rb', line 530

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

#rm(i) ⇒ Object



536
537
538
# File 'lib/valkey/objects.rb', line 536

def rm i
  VK.redis.call("SREM", key, i)
end

#to_aObject



550
551
552
# File 'lib/valkey/objects.rb', line 550

def to_a
    VK.redis.call("SMEMBERS", key)
end

#value(&b) ⇒ Object



509
510
511
512
513
514
515
516
517
518
519
520
521
522
# File 'lib/valkey/objects.rb', line 509

def value &b
  a = Set.new
  VK.redis.call("SMEMBERS", key).each_with_index { |e, i|
    if block_given?
      a << b.call(i, e)
    else
      a << e
    end
  }
  if @opts.has_key?(:flush) == true
    delete!
  end
  return a
end

#|(k) ⇒ Object



542
543
544
# File 'lib/valkey/objects.rb', line 542

def | k
  VK.redis.call("SUNION", key, k.key)
end