<commit_before>module NetzkeRedisPersistence
  class Store
    attr_accessor :redis, :custom_key

    def initialize(custom_key)
      @redis = Redis.new
      @custom_key = custom_key
    end

    def []=(key, val)
      val = Marshal.dump(val)
      redis.set(scoped_key(key), val)
    end

    def [](key)
      v = redis.get(scoped_key(key))
      begin
      v && Marshal.load(v)
      rescue => e
        r = e.message.match(/undefined class\/module (.*)/)
        if r[1]
          r[1].constantize.class
          self[key]
        end
      end
    end

    def delete(key)
    end

    def clear
    end

    def scoped_key(key)
      "#{session_key}_#{key}"
    end
    
    def session_key
      "netzke_states_#{@custom_key}"
    end
  end

end<commit_msg>add delete and clear methods<commit_after>module NetzkeRedisPersistence
  class Store
    attr_accessor :redis, :custom_key

    def initialize(custom_key)
      @redis = Redis.new
      @custom_key = custom_key
    end

    def []=(key, val)
      val = Marshal.dump(val)
      redis.set(scoped_key(key), val)
    end

    def [](key)
      v = redis.get(scoped_key(key))
      begin
        v && Marshal.load(v)
      rescue => e
        r = e.message.match(/undefined class\/module (.*)/)
        if r[1]
          r[1].constantize.class
          self[key]
        end
      end
    end

    def delete(key)
      @redis.del key
    end

    def clear
      keys = @redis.keys "#{session_key}*"
      keys.each do |key|
        self.delete key
      end
    end

    def scoped_key(key)
      "#{session_key}_#{key}"
    end

    def session_key
      "netzke_states_#{@custom_key}"
    end
  end

end
{'fraction_non_alphanumeric': 0.11051373954599761, 'fraction_numerical': 0.0023894862604540022, 'mean_word_length': 1.8929188255613125, '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': '7375316', 'n_tokens_mistral': 594, 'n_tokens_neox': 588, 'n_words': 128}