<commit_before>require 'casbah/service/abstract_store'

module Casbah
  module Service
    class RedisStore < AbstractStore

      def fetch( id )
        raise ServiceNotFoundError unless redis.exists( id )

        obj = {}

        serialize(@model.new).keys.each do |k|
          obj[k.to_sym] = redis.hget( id, k.to_sym )
        end

        deserialize obj
      end

      def register( obj )
        service = deserialize( obj )

        redis.pipelined do
          serialize( service ).each do |k, v|
            redis.hset service.id, k.to_sym, v
          end
        end
      end

      def delete( id )
        redis.del id
      end

      def services
        redis.keys('service.*').map{|id| fetch(id) }
      end

      def registered?( id )
        redis.exists id
      end

      def clear!<commit_msg>Improved RedisStore record retrieval<commit_after>require 'casbah/service/abstract_store'

module Casbah
  module Service
    class RedisStore < AbstractStore

      def fetch( id )
        raise ServiceNotFoundError unless redis.exists( id )

        obj = redis.hgetall( id )

        deserialize obj
      end

      def register( obj )
        service = deserialize( obj )

        redis.pipelined do
          serialize( service ).each do |k, v|
            redis.hset service.id, k.to_sym, v
          end
        end
      end

      def delete( id )
        redis.del id
      end

      def services
        redis.keys('service.*').map{|id| fetch(id) }
      end

      def registered?( id )
        redis.exists id
      end

      def clear!
{'fraction_non_alphanumeric': 0.08116677235256817, 'fraction_numerical': 0.0, 'mean_word_length': 1.6745762711864407, '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': '4533237', 'n_tokens_mistral': 492, 'n_tokens_neox': 465, 'n_words': 134}