Module: RedisTest
- Defined in:
- lib/redis_test.rb,
lib/redis_test/version.rb
Constant Summary collapse
- VERSION =
"0.0.2"
Class Method Summary collapse
- .cache_path ⇒ Object
- .clear ⇒ Object
- .configure(*options) ⇒ Object
- .db_filename ⇒ Object
- .pidfile ⇒ Object
- .pids_path ⇒ Object
- .port ⇒ Object
- .server_url ⇒ Object
- .start ⇒ Object
- .stop ⇒ Object
Class Method Details
.cache_path ⇒ Object
13 14 15 |
# File 'lib/redis_test.rb', line 13 def cache_path "#{Rails.root}/tmp/cache/#{port}/" end |
.clear ⇒ Object
96 97 98 |
# File 'lib/redis_test.rb', line 96 def clear Redis.current.flushdb end |
.configure(*options) ⇒ Object
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 |
# File 'lib/redis_test.rb', line 67 def configure(*) .flatten.each do |option| case option when :default Redis.current = Redis.new when :sidekiq Sidekiq.configure_server do |config| config.redis = { url: server_url, namespace: 'sidekiq' } end Sidekiq.configure_client do |config| config.redis = { url: server_url, namespace: 'sidekiq' } end when :ohm Ohm.redis = Redic.new(server_url) when :resque Resque.configure do |config| config.redis = "#{server_url}/resque" end else raise "Unable to configure #{option}" end end end |
.db_filename ⇒ Object
9 10 11 |
# File 'lib/redis_test.rb', line 9 def db_filename "redis-test-#{port}.rdb" end |
.pidfile ⇒ Object
21 22 23 |
# File 'lib/redis_test.rb', line 21 def pidfile "#{pids_path}/redis-test-#{port}.pid" end |
.pids_path ⇒ Object
17 18 19 |
# File 'lib/redis_test.rb', line 17 def pids_path "#{Rails.root}/tmp/pids" end |
.port ⇒ Object
5 6 7 |
# File 'lib/redis_test.rb', line 5 def port (ENV['TEST_REDIS_PORT'] || 9736).to_i end |
.server_url ⇒ Object
63 64 65 |
# File 'lib/redis_test.rb', line 63 def server_url "redis://localhost:#{port}" end |
.start ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/redis_test.rb', line 25 def start FileUtils.mkdir_p cache_path FileUtils.mkdir_p pids_path = { "daemonize" => 'yes', "pidfile" => pidfile, "port" => port, "timeout" => 300, "dbfilename" => db_filename, "dir" => cache_path, "databases" => 16 }.map { |k, v| "#{k} #{v}" }.join('\n') `echo '#{}' | redis-server -` wait_time_remaining = 5 begin TCPSocket.open("localhost", port) success = true rescue Exception => e if wait_time_remaining > 0 wait_time_remaining -= 0.1 sleep 0.1 else raise "Cannot start redis server in 5 seconds. Pinging server yield\n#{e.inspect}" end end while(!success) ENV['REDIS_URL'] = server_url end |
.stop ⇒ Object
56 57 58 59 60 61 |
# File 'lib/redis_test.rb', line 56 def stop %x{ cat #{pidfile} | xargs kill -QUIT rm -f #{cache_path}#{db_filename} } end |