<commit_before># Roulette.config([Redis.new(..), Redis.new(...)])
#
# r = Roulette.new([Redis.new(..), Redis.new(...)])
#
#
# Roulette.shard(:whatevs).sadd("key", "value")
# roulette = Roulette.new(REDIS, REDIS2, REDIS3, ...)
# roulette.set("key", "value")
# roulette.get("key")
# >> "value"

require 'digest/sha1'

class Roulette
  attr_accessor :stores

  def initialize(*stores)
    self.stores = stores.flatten
  end

  def method_missing(method_name, *args, &blk)
    Transaction.new(@stores, *args).fire(method_name)
  end

  class Transaction
    attr_accessor :key, :args, :stores


    def initialize(stores, *args)
      self.stores = stores
      self.args = *args
      extract_args
    end

    def extract_key
      # there is a 'bug' with something in the rails library that when loaded will
      # produce Roulette::Transaction.new([], "key") # => "k" instead of "key"
      # this is a fix for that, but i don't know what in rails env causes this discrepency
      self.key = args.is_a?(Array) ? args.first.to_s : args.to_s
    end

    def fire(method)
      select_store.send method.to_sym, *args
    end

    private
    def select_store
      val = Digest::SHA1.hexdigest(self.key).unpack('Q').join.to_i
      store_index = val % stores.count
      @stores[store_index]
    end<commit_msg>call extract_key method<commit_after># Roulette.config([Redis.new(..), Redis.new(...)])
#
# r = Roulette.new([Redis.new(..), Redis.new(...)])
#
#
# Roulette.shard(:whatevs).sadd("key", "value")
# roulette = Roulette.new(REDIS, REDIS2, REDIS3, ...)
# roulette.set("key", "value")
# roulette.get("key")
# >> "value"

require 'digest/sha1'

class Roulette
  attr_accessor :stores

  def initialize(*stores)
    self.stores = stores.flatten
  end

  def method_missing(method_name, *args, &blk)
    Transaction.new(@stores, *args).fire(method_name)
  end

  class Transaction
    attr_accessor :key, :args, :stores


    def initialize(stores, *args)
      self.stores = stores
      self.args = *args
      extract_key
    end

    def extract_key
      # there is a 'bug' with something in the rails library that when loaded will
      # produce Roulette::Transaction.new([], "key") # => "k" instead of "key"
      # this is a fix for that, but i don't know what in rails env causes this discrepency
      self.key = args.is_a?(Array) ? args.first.to_s : args.to_s
    end

    def fire(method)
      select_store.send method.to_sym, *args
    end

    private
    def select_store
      val = Digest::SHA1.hexdigest(self.key).unpack('Q').join.to_i
      store_index = val % stores.count
      @stores[store_index]
    end
{'fraction_non_alphanumeric': 0.14215127328012162, 'fraction_numerical': 0.003040668947168377, 'mean_word_length': 3.131868131868132, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5167590', 'n_tokens_mistral': 943, 'n_tokens_neox': 910, 'n_words': 221}