File tree Expand file tree Collapse file tree 2 files changed +24
-2
lines changed
lib/classifier-reborn/backends Expand file tree Collapse file tree 2 files changed +24
-2
lines changed Original file line number Diff line number Diff line change 66module ClassifierReborn
77 # This class provides Redis as the storage backend for the classifier data structures
88 class BayesRedisBackend
9- # The class can be created with the same arguments that the redis gem accepts
9+ # The class can be given an existing redis connection, or it can create
10+ # a new connection for you with the same arguments that the
11+ # {redis gem}[https://github.com/redis/redis-rb] accepts
1012 # E.g.,
1113 # b = ClassifierReborn::BayesRedisBackend.new
1214 # b = ClassifierReborn::BayesRedisBackend.new host: "10.0.1.1", port: 6380, db: 2
1315 # b = ClassifierReborn::BayesRedisBackend.new url: "redis://:secret@10.0.1.1:6380/2"
1416 #
1517 # Options available are:
18+ # redis_conn: an existing redis connection
1619 # url: lambda { ENV["REDIS_URL"] }
1720 # scheme: "redis"
1821 # host: "127.0.0.1"
@@ -33,7 +36,7 @@ def initialize(options = {})
3336 raise NoRedisError
3437 end
3538
36- @redis = Redis . new ( options )
39+ @redis = options . fetch ( :redis_conn , Redis . new ( options ) )
3740 @redis . setnx ( :total_words , 0 )
3841 @redis . setnx ( :total_trainings , 0 )
3942 end
Original file line number Diff line number Diff line change 1+ require File . dirname ( __FILE__ ) + '/../test_helper'
2+ require 'redis'
3+ require_relative './backend_common_tests'
4+
5+ class BackendRedisInjectedTest < Minitest ::Test
6+ include BackendCommonTests
7+
8+ def setup
9+ redis = Redis . new
10+ @backend = ClassifierReborn ::BayesRedisBackend . new ( redis_conn : redis )
11+ redis . config ( :set , 'save' , '' )
12+ rescue Redis ::CannotConnectError => e
13+ skip ( e )
14+ end
15+
16+ def teardown
17+ @backend . reset if defined? @backend
18+ end
19+ end
You can’t perform that action at this time.
0 commit comments