Redispot

Gem Version Build Status Code Climate Test Coverage

Launching the redis-server instance which is available only within a scope. It is useful when you want to test your code.

It is a Ruby clone of Test::RedisServer.

Synopsis

require 'redis'
require 'redispot'

# Using redis-server instance within a block
redis = nil
Redispot::Server.new do |connect_info|
  redis = Redis.new(connect_info)
  redis.ping  # => "PONG"
end

redis.ping  # => Error!

# or start it manually

redispot     = Redispot::Server.new
connect_info = redispot.start
begin
  redis = Redis.new(connect_info)
  redis.ping  # => "PONG"
ensure
  redispot.stop
end
redis.ping  # => Error!

Methods

Redispot::Server.new(options)

Create a new instance, and start redis-server if block given.

redispot = Redispot::Server.new(options)

# or

Redispot::Server.new(options) do |connect_info|
  redis = Redis.new(connect_info)
  # ...
end

Available options are:

  • [Hash] config

    This is a redis.conf key value pair. You can use any key-value pair(s) that redis-server supports.

    If you want to use this redis.conf:

    port 9999
    databases 16
    save 900 1
    

    Your conf parameter will be:

    Redispot::Server.new(config: {
        port:      9999,
        databases: 16,
        save:      '900 1',
    })
    
  • [Fixnum] timeout (Default: 3)

    Timeout seconds for detecting if redis-server is awake or not.

  • [String] tmpdir

    Temporal directory, where redis config will be stored.

Redispot::Server#start

Start redis-server instance manually.

redispot = Redispot::Server.new

redispot.start do |connect_info|
  redis = Redis.new(connect_info)
  redis.ping  # => "PONG"
end

# or

connect_info = redispot.start
begin
  redis = Redis.new(connect_info)
  # ... do anything
ensure
  redispot.stop
end

Redispot::Server#stop

Stop redis-server instance.

This method is automatically called from object destructor.

Redispot::Server#connect_info

Return connection info for client library to connect this redis-server instance.

This parameter is designed to pass directly to Redis module.

redispot = Redispot::Server.new
redis    = Redis.new(redispot.connect_info)

Installation

Add this line to your application's Gemfile:

gem 'redispot'

And then execute:

$ bundle

Or install it yourself as:

$ gem install redispot

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/hatyuki/redispot-rb.

License

The gem is available as open source under the terms of the MIT License.