Skip to content

Changing the Defaults

Paul Bergeron edited this page May 2, 2013 · 2 revisions

Configuration

To configure Rhod's defaults, just overwrite the default profile with any changes you'd like to make. If you're on Rails, a good place for your profiles is config/initializers/rhod.rb

Rhod.create_profile(:default, retries: 10)
# => {:retries=>10,
#  :backoffs=>#<Rhod::Backoffs::Logarithmic:0x007f89afaeb4c0 @state=1.3>,
#  :fallback=>nil,
#  :pool=>
#   #<ConnectionPool:0x007f89afaeb470
#    @available=
#     #<ConnectionPool::TimedStack:0x007f89afaeb3d0
#      @mutex=#<Mutex:0x007f89afaeb358>,
#      @que=[nil],
#      @resource=
#       #<ConditionVariable:0x007f89afaeb330
#        @waiters={},
#        @waiters_mutex=#<Mutex:0x007f89afaeb2e0>>>,
#    @key=:"current-70114667354600",
#    @size=1,
#    @timeout=0>,
#  :exceptions=>[Exception, StandardError]}

Creating a new profile will copy from the default profile any unspecified options:

Rhod.create_profile(:redis,
  retries: 10,
  backoffs: :^,
  pool: ConnectionPool.new(size: 3, timeout: 10) { Redis.new },
  exceptions: [Redis::BaseError])

Rhod.with_redis("1") {|r, a| r.set('test',a)}
# => "OK"
Rhod.with_redis {|r| r.get('test')}
# => "1"

Creating new profiles creates the Rhod.with_* command which will allow you to use the profile.