Add example for using Redis with TLS

This commit is contained in:
Juan Calderon-Perez
2023-06-17 20:43:45 -04:00
committed by GitHub
parent 6c53b6664f
commit bbbcbd2b23
2 changed files with 40 additions and 1 deletions

View File

@@ -35,7 +35,7 @@ Import the storage package.
import "github.com/gofiber/storage/redis/v2"
```
You can use the following possibilities to create a storage:
You can use the one of the following options to create a Redis Storage:
```go
// Initialize default config
store := redis.New()
@@ -63,6 +63,16 @@ store := redis.New(redis.Config{
Addrs: []string{":6379", ":6380"},
})
// Create a client with support for TLS
tlsCfg := &tls.Config{
MinVersion: tls.VersionTLS12,
}
store = redis.New(redis.Config{
URL: "redis://<user>:<pass>@127.0.0.1:6379/<db>",
TLSConfig: tlsCfg,
Reset: false,
})
// or just the url with all information
store = redis.New(redis.Config{
URL: "redis://<user>:<pass>@127.0.0.1:6379/<db>",

View File

@@ -149,6 +149,35 @@ func Test_Redis_Initalize_WithURL(t *testing.T) {
utils.AssertEqual(t, nil, testStoreUrl.Close())
}
func Test_Redis_Initalize_WithURL_TLS_Without_x509Pair(t *testing.T) {
tlsCfg := &tls.Config{
MinVersion: tls.VersionTLS12,
InsecureSkipVerify: true,
}
testStoreUrl := New(Config{
URL: "redis://localhost:6380",
TLSConfig: tlsCfg,
})
var (
key = "clark"
val = []byte("kent")
)
err = testStoreUrl.Set(key, val, 0)
utils.AssertEqual(t, nil, err)
result, err := testStoreUrl.Get(key)
utils.AssertEqual(t, nil, err)
utils.AssertEqual(t, val, result)
err = testStoreUrl.Delete(key)
utils.AssertEqual(t, nil, err)
utils.AssertEqual(t, nil, testStoreUrl.Close())
}
func Test_Redis_Initalize_WithURL_TLS(t *testing.T) {
cer, err := tls.LoadX509KeyPair("./tests/tls/client.crt", "./tests/tls/client.key")
if err != nil {