Class: VK::VECTOR

Inherits:
O
  • Object
show all
Includes:
Amatch
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

#<<(i) ⇒ Object



398
399
400
401
402
# File 'lib/valkey/objects.rb', line 398

def << i
  kk = %[#{@key}-#{VK.redis.call("LLEN",@key)}]
  VK.redis.call("SET", kk, i);
  VK.redis.call("RPUSH", key, kk)
end

#[](k) ⇒ Object



395
396
397
# File 'lib/valkey/objects.rb', line 395

def [] k
  VK.redis.call("GET", "#{@key}-#{k}");
end

#[]=(k, v) ⇒ Object



403
404
405
406
407
# File 'lib/valkey/objects.rb', line 403

def []= k,v
  kk = %[#{@key}-#{k}]
	  VK.redis.call("SET", kk, v)
	  VK.redis.call("RPUSH", key, kk);
end

#nearest(p) ⇒ Object



408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
# File 'lib/valkey/objects.rb', line 408

def nearest p
  h = {}
  value { |i,v|
    h[i] = {
            value: v,
            levenshtein: p.levenshtein_similar(v),
            damerau: p.damerau_levenshtein_similar(v),
            hamming: p.hamming_similar(v),
            distance: p.pair_distance_similar(v),
            subsequence: p.longest_subsequence_similar(v),
            substring: p.longest_substring_similar(v),
            jaro: p.jaro_similar(v),
            winkler: p.jarowinkler_similar(v)
          }
  }
  return h
end

#value(&b) ⇒ Object



378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
# File 'lib/valkey/objects.rb', line 378

def value &b
  a = []
  VK.redis.call("LRANGE", key, 0, -1).each_with_index { |e, i|                                                                                    
    if block_given?
      a << b.call(i, VK.redis.call("GET", e))
    else
      a << 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