Class: Testcontainers::RedisContainer
- Inherits:
-
DockerContainer
- Object
- DockerContainer
- Testcontainers::RedisContainer
- Defined in:
- lib/testcontainers/redis.rb
Overview
RedisContainer class is used to manage containers that run a Redis database
Constant Summary collapse
- REDIS_DEFAULT_PORT =
Default port used by the container
6379
- REDIS_DEFAULT_IMAGE =
Default image used by the container
"redis:latest"
Instance Method Summary collapse
-
#initialize(image = REDIS_DEFAULT_IMAGE, **kwargs) ⇒ RedisContainer
constructor
Initializes a new instance of RedisContainer.
-
#port ⇒ Integer
Returns the port used by the container.
-
#redis_url(protocol: "redis", db: 0) ⇒ String
(also: #database_url)
Returns the Redis connection url (e.g. redis://:password@localhost:6379/0).
-
#start ⇒ RedisContainer
Starts the container.
Constructor Details
#initialize(image = REDIS_DEFAULT_IMAGE, **kwargs) ⇒ RedisContainer
Initializes a new instance of RedisContainer
19 20 21 22 |
# File 'lib/testcontainers/redis.rb', line 19 def initialize(image = REDIS_DEFAULT_IMAGE, **kwargs) super(image, **kwargs) @wait_for ||= add_wait_for(:logs, /Ready to accept connections/) end |
Instance Method Details
#port ⇒ Integer
Returns the port used by the container
35 36 37 |
# File 'lib/testcontainers/redis.rb', line 35 def port REDIS_DEFAULT_PORT end |
#redis_url(protocol: "redis", db: 0) ⇒ String Also known as: database_url
Returns the Redis connection url (e.g. redis://:password@localhost:6379/0)
45 46 47 48 49 50 51 |
# File 'lib/testcontainers/redis.rb', line 45 def redis_url(protocol: "redis", db: 0) if @password.nil? || @password.empty? "#{protocol}://#{host}:#{mapped_port(port)}/#{db}" else "#{protocol}://:#{password}@#{host}:#{mapped_port(port)}/#{db}" end end |
#start ⇒ RedisContainer
Starts the container
27 28 29 30 |
# File 'lib/testcontainers/redis.rb', line 27 def start with_exposed_ports(port) super end |