<commit_before>require 'redis'

class RedisUserConnector
  def self.connect(hash)
    @connect = hash
  end

  def self.get(key)
    connection.hgetall("#{namespace}:#{key}")
  end

  def self.set(key, *attrs)
    connection.hmset("#{namespace}:#{key}", *(attrs.flatten))
  end

  def self.pub(channel, message)
    connection.publish(channel, message)
  end

  def self.sub(channel, &block)
    connection.subscribe(channel, &block)
  end

  private

  def self.connect_options
    raise "#{name}: Could not establish connection" if @connect.nil? || @connect.empty?

    @connect.merge :driver => :hiredis
  end

  def self.connection
    @connection ||= Redis.new(connect_options)
  end

  def self.namespace
    'user'
  end
end<commit_msg>Add another one connection for pubsub<commit_after>require 'redis'

class RedisUserConnector
  def self.connect(hash)
    @connect = hash
  end

  def self.get(key)
    connection.hgetall("#{namespace}:#{key}")
  end

  def self.set(key, *attrs)
    connection.hmset("#{namespace}:#{key}", *(attrs.flatten))
  end

  def self.pub(channel, message)
    pubsub_connection.publish(channel, message)
  end

  def self.sub(channel, &block)
    pubsub_connection.subscribe(channel, &block)
  end

  private

  def self.connect_options
    raise "#{name}: Could not establish connection" if @connect.nil? || @connect.empty?

    @connect.merge :driver => :hiredis
  end

  def self.connection
    @connection ||= Redis.new(connect_options)
  end

  def self.pubsub_connection
    @pubsub_connection ||= Redis.new(connect_options)
  end

  def self.namespace
    'user'
  end
end
{'fraction_non_alphanumeric': 0.1251548946716233, 'fraction_numerical': 0.0, 'mean_word_length': 3.792284866468843, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, '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': '4038906', 'n_tokens_mistral': 540, 'n_tokens_neox': 530, 'n_words': 123}