<commit_before>module Rack
  module Cache
    class EntityStore
      class RedisBase < EntityStore
        # The underlying ::Redis instance used to communicate with the Redis daemon.
        attr_reader :cache

        extend Rack::Utils

        def open(key)
          data = read(key)
          data && [data]
        end

        def self.resolve(uri)
          db = uri.path.sub(/^\//, '')
          db = "0" if db.empty?
          server = { :host => uri.host, :port => uri.port || "6379", :db => db }
          new server
        end
      end

      class Redis < RedisBase
        def initialize(server, options = {})
          @cache = ::Redis::Factory.create server
        end

        def exist?(key)
          cache.exists key
        end

        def read(key)
          cache.get key
        end

        def write(body)
          buf = StringIO.new
          key, size = slurp(body){|part| buf.write(part) }
          [key, size] if cache.set(key, buf.string)
        end

        def purge(key)<commit_msg>Let Rack::Cache entity store to use plain Redis client<commit_after>module Rack
  module Cache
    class EntityStore
      class RedisBase < EntityStore
        # The underlying ::Redis instance used to communicate with the Redis daemon.
        attr_reader :cache

        extend Rack::Utils

        def open(key)
          data = read(key)
          data && [data]
        end

        def self.resolve(uri)
          db = uri.path.sub(/^\//, '')
          db = "0" if db.empty?
          server = { :host => uri.host, :port => uri.port || "6379", :db => db }
          new server
        end
      end

      class Redis < RedisBase
        def initialize(server, options = {})
          @cache = ::Redis.new server
        end

        def exist?(key)
          cache.exists key
        end

        def read(key)
          cache.get key
        end

        def write(body)
          buf = StringIO.new
          key, size = slurp(body){|part| buf.write(part) }
          [key, size] if cache.set(key, buf.string)
        end

        def purge(key)
{'fraction_non_alphanumeric': 0.10283517539644402, 'fraction_numerical': 0.004805382027871216, 'mean_word_length': 1.5421245421245422, 'pattern_counts': {'":': 0, '<': 7, '<?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': '4651077', 'n_tokens_mistral': 617, 'n_tokens_neox': 597, 'n_words': 181}