ruby 灵魂伴侣装载机

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了ruby 灵魂伴侣装载机相关的知识,希望对你有一定的参考价值。

require 'soulmate'

module Soulmate
  class Loader < Base
    def load_without_reset(items)
      items.each_with_index do |item, i|
        puts item["id"]
        add(item, :skip_duplicate_check => true)
      end
    end

    def reset
      # delete the sorted sets for this type
      phrases = Soulmate.redis.smembers(base)
      Soulmate.redis.pipelined do
        phrases.each do |p|
          Soulmate.redis.del("#{base}:#{p}")
        end
        Soulmate.redis.del(base)
      end

      # Redis can continue serving cached requests for this type while the reload is
      # occuring. Some requests may be cached incorrectly as empty set (for requests
      # which come in after the above delete, but before the loading completes). But
      # everything will work itself out as soon as the cache expires again.

      # delete the data stored for this type
      Soulmate.redis.del(database)
    end
  end
end


#files = ["./xaa", "./xab", "./xac", "./xad", "./xae", "./xaf", "./xag", "./xah", "./xai", "./xaj", "./xak"]
#files = ["./laa", "./xae", "./xaf", "./xag", "./xah", "./xai", "./xaj", "./xak"]
#files = ["./lab", "./xag", "./xah", "./xai", "./xaj", "./xak"]
files = ["./xai", "./xaj", "./xak"]
type = "hacker"
#loader = Soulmate::Loader.new(type)
#loader.reset

files.each do |filename|
  puts "Loading items of type #{type} from file #{filename}..."
  file = File.open(filename, "r")
  items = file.read.split("\n").map{|l| MultiJson.decode(l) }
  loader = Soulmate::Loader.new(type)
  loaded = loader.load_without_reset(items)
  puts "Loaded a total of #{loaded.size} items"
  file.close
end

puts "loading done"

以上是关于ruby 灵魂伴侣装载机的主要内容,如果未能解决你的问题,请参考以下文章

NLP悦读 | 什么样的人才是灵魂伴侣?

调色灵魂工具,详解HSL色彩原理+使用方法+应用效果|VSCO教程10

男人来自火星,女人来自金星2 恋爱篇

ruby 装载订单栏杆4

ViewPager2&TabLayout:拓展出一个文本选中放大效果

气韵动人-自学成才的全职妈妈ruby可可笔下的灵魂有温度