<commit_before>class Redis
  class Store < self
    module Namespace
      def set(key, val, options = nil)
        namespace(key) { |key| super(key, val, options) }
      end

      def setnx(key, val, options = nil)
        namespace(key) { |key| super(key, val, options) }
      end

      def get(key, options = nil)
        namespace(key) { |key| super(key, options) }
      end

      def exists(key)
        namespace(key) { |key| super(key) }
      end

      def incrby(key, increment)
        namespace(key) { |key| super(key, increment) }
      end

      def decrby(key, increment)
        namespace(key) { |key| super(key, increment) }
      end

      def keys(pattern = "*")
        namespace(pattern) { |pattern| super(pattern).map{|key| strip_namespace(key) } }
      end

      def del(*keys)
        super *keys.map {|key| interpolate(key) } if keys.any?
      end

      def mget(*keys)
        super *keys.map {|key| interpolate(key) } if keys.any?
      end
      
      def expire(key, ttl)
         namespace(key) { |key| super(key, ttl) }
      end

      def to_s
        "#{super} with namespace #{@namespace}"
      end

      def flushdb
        del *keys
      end

      private
        def namespace(key)
          yield interpolate(key)
        end

        def interpolate(key)
          key.match(namespace_regexp) ? key : "#{@namespace}:#{key}"
        end

        def strip_namespace(key)
          key.gsub namespace_regexp, ""
        end

        def namespace_regexp
          @namespace_regexp ||= %r{^#{@namespace}\:}
        end
    end
  end
end
<commit_msg>Added TTL method too<commit_after>class Redis
  class Store < self
    module Namespace
      def set(key, val, options = nil)
        namespace(key) { |key| super(key, val, options) }
      end

      def setnx(key, val, options = nil)
        namespace(key) { |key| super(key, val, options) }
      end

      def get(key, options = nil)
        namespace(key) { |key| super(key, options) }
      end

      def exists(key)
        namespace(key) { |key| super(key) }
      end

      def incrby(key, increment)
        namespace(key) { |key| super(key, increment) }
      end

      def decrby(key, increment)
        namespace(key) { |key| super(key, increment) }
      end

      def keys(pattern = "*")
        namespace(pattern) { |pattern| super(pattern).map{|key| strip_namespace(key) } }
      end

      def del(*keys)
        super *keys.map {|key| interpolate(key) } if keys.any?
      end

      def mget(*keys)
        super *keys.map {|key| interpolate(key) } if keys.any?
      end
      
      def expire(key, ttl)
         namespace(key) { |key| super(key, ttl) }
      end
      
      def ttl(key)
         namespace(key) { |key| super(key) }
      end

      def to_s
        "#{super} with namespace #{@namespace}"
      end

      def flushdb
        del *keys
      end

      private
        def namespace(key)
          yield interpolate(key)
        end

        def interpolate(key)
          key.match(namespace_regexp) ? key : "#{@namespace}:#{key}"
        end

        def strip_namespace(key)
          key.gsub namespace_regexp, ""
        end

        def namespace_regexp
          @namespace_regexp ||= %r{^#{@namespace}\:}
        end
    end
  end
end

{'fraction_non_alphanumeric': 0.11893203883495146, 'fraction_numerical': 0.0, 'mean_word_length': 1.8870402802101576, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, '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': '7433232', 'n_tokens_mistral': 1065, 'n_tokens_neox': 1032, 'n_words': 269}