<commit_before>require 'socket'

class Redis
  VERSION = "2.0.0.rc3"

  class ProtocolError < RuntimeError
    def initialize(reply_type)
      super("Protocol error, got '#{reply_type}' as initial reply byte")
    end
  end

  def self.deprecate(message, trace = caller[0])
    $stderr.puts "\n#{message} (in #{trace})"
  end

  attr :client

  def self.connect(options = {})
    require "uri"

    url = URI(options.delete(:url) || ENV["REDIS_URL"] || "redis://127.0.0.1:6379/0")

    options[:host]     = url.host
    options[:port]     = url.port
    options[:password] = <PASSWORD>
    options[:db]       = url.path[1..-1].to_i

    new(options)
  end

  def initialize(options = {})
    if options[:thread_safe]
      @client = Client::ThreadSafe.new(options)
    else
      @client = Client.new(options)
    end
  end

  def select(db)
    @client.db = db
    @client.call(:select, db)
  end

  def info
    Hash[*@client.call(:info).split(/:|\r\n/)]
  end

  def flushdb
    @client.call(:flushdb)
  end

  def save
    @client.call(:save)
  end

  def bgsave
    @client.call(:bgsave)
  end

  def get(key)
    @client.call(:get, key)
  end

  def getset(key, value)
    @client.call(:getset, key, value)
  end

  def mget(*keys)
    @client.call(:mget, *keys)
  end

  def append(key, value)
    @client.call(:append, key, value)
  end

  def hgetall(key)
    Hash[*@client.call(:hgetall, key)]
  end

  def hget(key, field)
    @client.call(:hget, key, field)
  end

  def hdel(key, field)
    @client.call(:hdel, key, field)
  end

  def hkeys(key)
    @client.call(:hkeys, key)
  end

  def keys(pattern = "*")
    @client.call(:keys, pattern)
  end

  def randomkey
    @client.call(:randomkey)
  end

  def echo(value)
    @client.call(:echo, value)
  end

  def ping
    @client.call(:ping)
  end

  def lastsave
    @client.call(:lastsave)
  end

  def dbsize
    @client.call(:dbsize)
  end

  def exists(key)
    _bool @client.call(:exists, key)
  end

  def llen(key)
    @client.call(:llen, key)
  end

  def lrange(key, start, stop)
    @client.call(:lrange, key, start, stop)
  end

  def ltrim(key, start, stop)
    @client.call(:ltrim, key, start, stop)
  end

  def lindex(key, index)
    @client.call(:lindex, key, index)
  end

  def lset(key, index, value)
    @client.call(:lset, key, index, value)
  end

  def lrem(key, count, value)
    @client.call(:lrem, key, count, value)
  end

  def rpush(key, value)
    @client.call(:rpush, key, value)
  end

  def lpush(key, value)
    @client.call(:lpush, key, value)
  end

  def rpop(key)
    @client.call(:rpop, key)
  end

  def blpop(key, timeout)
    @client.call_without_timeout(:blpop, key, timeout)
  end

  def brpop(key, timeout)
    @client.call_without_timeout(:brpop, key, timeout)
  end

  def rpoplpush(source, destination)
    @client.call(:rpoplpush, source, destination)
  end

  def lpop(key)
    @client.call(:lpop, key)
  end

  def smembers(key)
    @client.call(:smembers, key)
  end

  def sismember(key, member)
    _bool @client.call(:sismember, key, member)
  end

  def sadd(key, value)
    _bool @client.call(:sadd, key, value)
  end

  def srem(key, value)
    _bool @client.call(:srem, key, value)
  end

  def smove(source, destination, member)
    _bool @client.call(:smove, source, destination, member)
  end

  def spop(key)
    @client.call(:spop, key)
  end

  def scard(key)
    @client.call(:scard, key)
  end

  def sinter(*keys)
    @client.call(:sinter, *keys)
  end

  def sinterstore(destination, *keys)
    @client.call(:sinterstore, destination, *keys)
  end

  def sunion(*keys)
    @client.call(:sunion, *keys)
  end

  def sunionstore(destination, *keys)
    @client.call(:sunionstore, destination, *keys)
  end

  def sdiff(*keys)
    @client.call(:sdiff, *keys)
  end

  def sdiffstore(destination, *keys)
    @client.call(:sdiffstore, destination, *keys)
  end

  def srandmember(key)
    @client.call(:srandmember, key)
  end

  def zadd(key, score, member)
    _bool @client.call(:zadd, key, score, member)
  end

  def zincrby(key, increment, member)
    @client.call(:zincrby, key, increment, member)
  end

  def zcard(key)
    @client.call(:zcard, key)
  end

  def zrange(key, start, stop, options = {})
    command = CommandOptions.new(options) do |c|
      c.bool :with_scores
    end

    @client.call(:zrange, key, start, stop, *command.to_a)
  end

  def zrangebyscore(key, min, max, options = {})
    command = CommandOptions.new(options) do |c|
      c.splat :limit
      c.bool  :with_scores
    end

    @client.call(:zrangebyscore, key, min, max, *command.to_a)<commit_msg>Add explicit definition for ZRANK.<commit_after>require 'socket'

class Redis
  VERSION = "2.0.0.rc3"

  class ProtocolError < RuntimeError
    def initialize(reply_type)
      super("Protocol error, got '#{reply_type}' as initial reply byte")
    end
  end

  def self.deprecate(message, trace = caller[0])
    $stderr.puts "\n#{message} (in #{trace})"
  end

  attr :client

  def self.connect(options = {})
    require "uri"

    url = URI(options.delete(:url) || ENV["REDIS_URL"] || "redis://127.0.0.1:6379/0")

    options[:host]     = url.host
    options[:port]     = url.port
    options[:password] = url.password
    options[:db]       = url.path[1..-1].to_i

    new(options)
  end

  def initialize(options = {})
    if options[:thread_safe]
      @client = Client::ThreadSafe.new(options)
    else
      @client = Client.new(options)
    end
  end

  def select(db)
    @client.db = db
    @client.call(:select, db)
  end

  def info
    Hash[*@client.call(:info).split(/:|\r\n/)]
  end

  def flushdb
    @client.call(:flushdb)
  end

  def save
    @client.call(:save)
  end

  def bgsave
    @client.call(:bgsave)
  end

  def get(key)
    @client.call(:get, key)
  end

  def getset(key, value)
    @client.call(:getset, key, value)
  end

  def mget(*keys)
    @client.call(:mget, *keys)
  end

  def append(key, value)
    @client.call(:append, key, value)
  end

  def hgetall(key)
    Hash[*@client.call(:hgetall, key)]
  end

  def hget(key, field)
    @client.call(:hget, key, field)
  end

  def hdel(key, field)
    @client.call(:hdel, key, field)
  end

  def hkeys(key)
    @client.call(:hkeys, key)
  end

  def keys(pattern = "*")
    @client.call(:keys, pattern)
  end

  def randomkey
    @client.call(:randomkey)
  end

  def echo(value)
    @client.call(:echo, value)
  end

  def ping
    @client.call(:ping)
  end

  def lastsave
    @client.call(:lastsave)
  end

  def dbsize
    @client.call(:dbsize)
  end

  def exists(key)
    _bool @client.call(:exists, key)
  end

  def llen(key)
    @client.call(:llen, key)
  end

  def lrange(key, start, stop)
    @client.call(:lrange, key, start, stop)
  end

  def ltrim(key, start, stop)
    @client.call(:ltrim, key, start, stop)
  end

  def lindex(key, index)
    @client.call(:lindex, key, index)
  end

  def lset(key, index, value)
    @client.call(:lset, key, index, value)
  end

  def lrem(key, count, value)
    @client.call(:lrem, key, count, value)
  end

  def rpush(key, value)
    @client.call(:rpush, key, value)
  end

  def lpush(key, value)
    @client.call(:lpush, key, value)
  end

  def rpop(key)
    @client.call(:rpop, key)
  end

  def blpop(key, timeout)
    @client.call_without_timeout(:blpop, key, timeout)
  end

  def brpop(key, timeout)
    @client.call_without_timeout(:brpop, key, timeout)
  end

  def rpoplpush(source, destination)
    @client.call(:rpoplpush, source, destination)
  end

  def lpop(key)
    @client.call(:lpop, key)
  end

  def smembers(key)
    @client.call(:smembers, key)
  end

  def sismember(key, member)
    _bool @client.call(:sismember, key, member)
  end

  def sadd(key, value)
    _bool @client.call(:sadd, key, value)
  end

  def srem(key, value)
    _bool @client.call(:srem, key, value)
  end

  def smove(source, destination, member)
    _bool @client.call(:smove, source, destination, member)
  end

  def spop(key)
    @client.call(:spop, key)
  end

  def scard(key)
    @client.call(:scard, key)
  end

  def sinter(*keys)
    @client.call(:sinter, *keys)
  end

  def sinterstore(destination, *keys)
    @client.call(:sinterstore, destination, *keys)
  end

  def sunion(*keys)
    @client.call(:sunion, *keys)
  end

  def sunionstore(destination, *keys)
    @client.call(:sunionstore, destination, *keys)
  end

  def sdiff(*keys)
    @client.call(:sdiff, *keys)
  end

  def sdiffstore(destination, *keys)
    @client.call(:sdiffstore, destination, *keys)
  end

  def srandmember(key)
    @client.call(:srandmember, key)
  end

  def zadd(key, score, member)
    _bool @client.call(:zadd, key, score, member)
  end

  def zrank(key, member)
    @client.call(:zrank, key, member)
  end

  def zincrby(key, increment, member)
    @client.call(:zincrby, key, increment, member)
  end

  def zcard(key)
    @client.call(:zcard, key)
  end

  def zrange(key, start, stop, options = {})
    command = CommandOptions.new(options) do |c|
      c.bool :with_scores
    end

    @client.call(:zrange, key, start, stop, *command.to_a)
  end

  def zrangebyscore(key, min, max, options = {})
    command = CommandOptions.new(options) do |c|
      c.splat :limit
      c.bool  :with_scores
    end

    @client.call(:zrangebyscore, key, min, max, *command.to_a)
{'fraction_non_alphanumeric': 0.1414336226293796, 'fraction_numerical': 0.003857280617164899, 'mean_word_length': 3.0512152777777777, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 4, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 2, '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': '1717871', 'n_tokens_mistral': 3616, 'n_tokens_neox': 3477, 'n_words': 826}