Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Merge pull request #76 from NZKoz/redis_connection_options

Allow users to specify different connection options for the redis store
  • Loading branch information...
commit 99329b08aa0d31a84d5f6fec78c48fd2991d85c1 2 parents 8330b41 + 63e0b9c
Sam SamSaffron authored
6 Ruby/lib/mini_profiler/storage/redis_store.rb
@@ -5,8 +5,8 @@ class RedisStore < AbstractStore
5 5 EXPIRE_SECONDS = 60 * 60 * 24
6 6
7 7 def initialize(args)
8   - args ||= {}
9   - @prefix = args[:prefix] || 'MPRedisStore'
  8 + @args = args || {}
  9 + @prefix = @args.delete(:prefix) || 'MPRedisStore'
10 10 end
11 11
12 12 def save(page_struct)
@@ -36,7 +36,7 @@ def get_unviewed_ids(user)
36 36
37 37 def redis
38 38 require 'redis' unless defined? Redis
39   - Redis.new
  39 + Redis.new @args
40 40 end
41 41
42 42 end
22 Ruby/spec/components/redis_store_spec.rb
@@ -6,6 +6,28 @@
6 6
7 7 describe Rack::MiniProfiler::RedisStore do
8 8
  9 + context 'establishing a connection to something other than the default' do
  10 + before do
  11 + @store = Rack::MiniProfiler::RedisStore.new(:db=>2)
  12 + end
  13 +
  14 + describe "connection" do
  15 + it 'can still store the resulting value' do
  16 + page_struct = Rack::MiniProfiler::PageTimerStruct.new({})
  17 + page_struct['Id'] = "XYZ"
  18 + page_struct['Random'] = "random"
  19 + @store.save(page_struct)
  20 + end
  21 +
  22 + it 'uses the correct db' do
  23 + # redis is private, and possibly should remain so?
  24 + underlying_client = @store.send(:redis).client
  25 +
  26 + underlying_client.db.should == 2
  27 + end
  28 + end
  29 + end
  30 +
9 31 context 'page struct' do
10 32
11 33 before do

0 comments on commit 99329b0

Please sign in to comment.
Something went wrong with that request. Please try again.