-
-
Notifications
You must be signed in to change notification settings - Fork 515
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Added valkey module * Revert commit to only add valkey module * Switched client to valkey-go * Added docs using scaffolding * Add ConnectionString doc Co-authored-by: Manuel de la Peña <[email protected]> * Format imports Co-authored-by: Manuel de la Peña <[email protected]> * Handle query error Co-authored-by: Manuel de la Peña <[email protected]> * Fix linting Co-authored-by: Manuel de la Peña <[email protected]> --------- Co-authored-by: Manuel de la Peña <[email protected]>
- Loading branch information
1 parent
361d21d
commit 70b90cc
Showing
13 changed files
with
3,112 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
# Valkey | ||
|
||
Not available until the next release of testcontainers-go <a href="https://github.com/testcontainers/testcontainers-go"><span class="tc-version">:material-tag: main</span></a> | ||
|
||
## Introduction | ||
|
||
The Testcontainers module for Valkey. | ||
|
||
## Adding this module to your project dependencies | ||
|
||
Please run the following command to add the Valkey module to your Go dependencies: | ||
|
||
``` | ||
go get github.com/testcontainers/testcontainers-go/modules/valkey | ||
``` | ||
|
||
## Usage example | ||
|
||
<!--codeinclude--> | ||
[Creating a Valkey container](../../modules/valkey/examples_test.go) inside_block:runValkeyContainer | ||
<!--/codeinclude--> | ||
|
||
## Module Reference | ||
|
||
### Run function | ||
|
||
- Not available until the next release of testcontainers-go <a href="https://github.com/testcontainers/testcontainers-go"><span class="tc-version">:material-tag: main</span></a> | ||
|
||
!!!info | ||
The `RunContainer(ctx, opts...)` function is deprecated and will be removed in the next major release of _Testcontainers for Go_. | ||
|
||
The Valkey module exposes one entrypoint function to create the Valkey container, and this function receives three parameters: | ||
|
||
```golang | ||
func Run(ctx context.Context, img string, opts ...testcontainers.ContainerCustomizer) (*ValkeyContainer, error) | ||
``` | ||
|
||
- `context.Context`, the Go context. | ||
- `string`, the Docker image to use. | ||
- `testcontainers.ContainerCustomizer`, a variadic argument for passing options. | ||
|
||
### Container Options | ||
|
||
When starting the Valkey container, you can pass options in a variadic way to configure it. | ||
|
||
#### Image | ||
|
||
If you need to set a different Valkey Docker image, you can set a valid Docker image as the second argument in the `Run` function. | ||
E.g. `Run(context.Background(), "valkey/valkey:7.2.5")`. | ||
|
||
{% include "../features/common_functional_options.md" %} | ||
|
||
#### Snapshotting | ||
|
||
By default Valkey saves snapshots of the dataset on disk, in a binary file called dump.rdb. You can configure Valkey to have it save the dataset every `N` seconds if there are at least `M` changes in the dataset. E.g. `WithSnapshotting(10, 1)`. | ||
|
||
#### Log Level | ||
|
||
You can easily set the valkey logging level. E.g. `WithLogLevel(LogLevelDebug)`. | ||
|
||
#### Valkey configuration | ||
|
||
In the case you have a custom config file for Valkey, it's possible to copy that file into the container before it's started. E.g. `WithConfigFile(filepath.Join("testdata", "valkey.conf"))`. | ||
|
||
### Container Methods | ||
|
||
The Valkey container exposes the following methods: | ||
|
||
#### ConnectionString | ||
|
||
This method returns the connection string to connect to the Valkey container, using the default `6379` port. | ||
|
||
<!--codeinclude--> | ||
[Get connection string](../../modules/valkey/valkey_test.go) inside_block:connectionString | ||
<!--/codeinclude--> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
include ../../commons-test.mk | ||
|
||
.PHONY: test | ||
test: | ||
$(MAKE) test-valkey |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package valkey_test | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"log" | ||
"path/filepath" | ||
|
||
"github.com/testcontainers/testcontainers-go/modules/valkey" | ||
) | ||
|
||
func ExampleRun() { | ||
// runValkeyContainer { | ||
ctx := context.Background() | ||
|
||
valkeyContainer, err := valkey.Run(ctx, | ||
"docker.io/valkey/valkey:7.2.5", | ||
valkey.WithSnapshotting(10, 1), | ||
valkey.WithLogLevel(valkey.LogLevelVerbose), | ||
valkey.WithConfigFile(filepath.Join("testdata", "valkey7.conf")), | ||
) | ||
if err != nil { | ||
log.Fatalf("failed to start container: %s", err) | ||
} | ||
|
||
// Clean up the container | ||
defer func() { | ||
if err := valkeyContainer.Terminate(ctx); err != nil { | ||
log.Fatalf("failed to terminate container: %s", err) | ||
} | ||
}() | ||
// } | ||
|
||
state, err := valkeyContainer.State(ctx) | ||
if err != nil { | ||
log.Fatalf("failed to get container state: %s", err) // nolint:gocritic | ||
} | ||
|
||
fmt.Println(state.Running) | ||
|
||
// Output: | ||
// true | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
module github.com/testcontainers/testcontainers-go/modules/valkey | ||
|
||
go 1.21 | ||
|
||
require ( | ||
github.com/google/uuid v1.6.0 | ||
github.com/stretchr/testify v1.9.0 | ||
github.com/testcontainers/testcontainers-go v0.32.0 | ||
github.com/valkey-io/valkey-go v1.0.41 | ||
) | ||
|
||
replace github.com/testcontainers/testcontainers-go => ../.. | ||
|
||
require ( | ||
dario.cat/mergo v1.0.0 // indirect | ||
github.com/Azure/go-ansiterm v0.0.0-20230124172434-306776ec8161 // indirect | ||
github.com/Microsoft/go-winio v0.6.2 // indirect | ||
github.com/cenkalti/backoff/v4 v4.3.0 // indirect | ||
github.com/containerd/containerd v1.7.19 // indirect | ||
github.com/containerd/log v0.1.0 // indirect | ||
github.com/containerd/platforms v0.2.1 // indirect | ||
github.com/cpuguy83/dockercfg v0.3.1 // indirect | ||
github.com/davecgh/go-spew v1.1.1 // indirect | ||
github.com/distribution/reference v0.6.0 // indirect | ||
github.com/docker/docker v27.0.3+incompatible // indirect | ||
github.com/docker/go-connections v0.5.0 // indirect | ||
github.com/docker/go-units v0.5.0 // indirect | ||
github.com/felixge/httpsnoop v1.0.4 // indirect | ||
github.com/go-logr/logr v1.4.2 // indirect | ||
github.com/go-logr/stdr v1.2.2 // indirect | ||
github.com/go-ole/go-ole v1.3.0 // indirect | ||
github.com/gogo/protobuf v1.3.2 // indirect | ||
github.com/klauspost/compress v1.17.9 // indirect | ||
github.com/kr/pretty v0.3.1 // indirect | ||
github.com/lufia/plan9stats v0.0.0-20240513124658-fba389f38bae // indirect | ||
github.com/magiconair/properties v1.8.7 // indirect | ||
github.com/moby/docker-image-spec v1.3.1 // indirect | ||
github.com/moby/patternmatcher v0.6.0 // indirect | ||
github.com/moby/sys/sequential v0.5.0 // indirect | ||
github.com/moby/sys/user v0.1.0 // indirect | ||
github.com/moby/term v0.5.0 // indirect | ||
github.com/morikuni/aec v1.0.0 // indirect | ||
github.com/opencontainers/go-digest v1.0.0 // indirect | ||
github.com/opencontainers/image-spec v1.1.0 // indirect | ||
github.com/pkg/errors v0.9.1 // indirect | ||
github.com/pmezard/go-difflib v1.0.0 // indirect | ||
github.com/power-devops/perfstat v0.0.0-20240221224432-82ca36839d55 // indirect | ||
github.com/shirou/gopsutil/v3 v3.24.5 // indirect | ||
github.com/shoenig/go-m1cpu v0.1.6 // indirect | ||
github.com/sirupsen/logrus v1.9.3 // indirect | ||
github.com/tklauser/go-sysconf v0.3.14 // indirect | ||
github.com/tklauser/numcpus v0.8.0 // indirect | ||
github.com/yusufpapurcu/wmi v1.2.4 // indirect | ||
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.53.0 // indirect | ||
go.opentelemetry.io/otel v1.28.0 // indirect | ||
go.opentelemetry.io/otel/metric v1.28.0 // indirect | ||
go.opentelemetry.io/otel/trace v1.28.0 // indirect | ||
golang.org/x/crypto v0.25.0 // indirect | ||
golang.org/x/net v0.26.0 // indirect | ||
golang.org/x/sys v0.22.0 // indirect | ||
google.golang.org/genproto/googleapis/api v0.0.0-20240318140521-94a12d6c2237 // indirect | ||
google.golang.org/genproto/googleapis/rpc v0.0.0-20240318140521-94a12d6c2237 // indirect | ||
gopkg.in/yaml.v3 v3.0.1 // indirect | ||
) |
Oops, something went wrong.