<commit_before>#-  Ruby source code

#-  defs-redis.rb ~~
#                                                       ~~ (c) SRW, 03 Feb 2015
#                                                   ~~ last updated 03 Feb 2015

require 'json'
require 'redis'

module QM

    class RedisApiStore

        def close()
          # This method documentation.
            @db.quit if defined?(@db)
            return
        end

        def connect(opts = {})
          # This method needs documentation.
            if opts.has_key?(:redis) then
                @db ||= Redis.new({url: opts[:redis]})
                STDOUT.puts 'API: Redis storage is ready.'
            end<commit_msg>Attempt to use "hiredis" C extension if available<commit_after>#-  Ruby source code

#-  defs-redis.rb ~~
#                                                       ~~ (c) SRW, 03 Feb 2015
#                                                   ~~ last updated 04 Feb 2015

require 'json'
require 'redis'

module QM

    class RedisApiStore

        def close()
          # This method documentation.
            @db.quit if defined?(@db)
            return
        end

        def connect(opts = {})
          # This method needs documentation.
            if opts.has_key?(:redis) then
              # Try to use the "hiredis" driver to boost performance, and fall
              # back to a non-native driver. This is the same strategy that the
              # Node.js version uses.
                begin
                    @db ||= Redis.new({
                        driver: 'hiredis'.to_sym,
                        url: opts[:redis]
                    })
                rescue RuntimeError
                  # The  "hiredis" driver was not available, either because the
                  # gem was not included in the app's Gemfile or else because
                  # this Ruby engine cannot use native C extensions.
                    @db ||= Redis.new({
                        url: opts[:redis]
                    })
                end
                STDOUT.puts 'API: Redis storage is ready.'
            end
{'fraction_non_alphanumeric': 0.07931199235547062, 'fraction_numerical': 0.011466794075489728, 'mean_word_length': 1.1024096385542168, 'pattern_counts': {'":': 0, '<': 3, '<?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': 8, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2444496', 'n_tokens_mistral': 545, 'n_tokens_neox': 501, 'n_words': 176}