mirror of
https://github.com/gofiber/storage.git
synced 2025-10-16 21:51:22 +08:00
Add example for using Redis with TLS
This commit is contained in:

committed by
GitHub

parent
6c53b6664f
commit
bbbcbd2b23
@@ -35,7 +35,7 @@ Import the storage package.
|
|||||||
import "github.com/gofiber/storage/redis/v2"
|
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
|
```go
|
||||||
// Initialize default config
|
// Initialize default config
|
||||||
store := redis.New()
|
store := redis.New()
|
||||||
@@ -63,6 +63,16 @@ store := redis.New(redis.Config{
|
|||||||
Addrs: []string{":6379", ":6380"},
|
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
|
// or just the url with all information
|
||||||
store = redis.New(redis.Config{
|
store = redis.New(redis.Config{
|
||||||
URL: "redis://<user>:<pass>@127.0.0.1:6379/<db>",
|
URL: "redis://<user>:<pass>@127.0.0.1:6379/<db>",
|
||||||
|
@@ -149,6 +149,35 @@ func Test_Redis_Initalize_WithURL(t *testing.T) {
|
|||||||
utils.AssertEqual(t, nil, testStoreUrl.Close())
|
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) {
|
func Test_Redis_Initalize_WithURL_TLS(t *testing.T) {
|
||||||
cer, err := tls.LoadX509KeyPair("./tests/tls/client.crt", "./tests/tls/client.key")
|
cer, err := tls.LoadX509KeyPair("./tests/tls/client.crt", "./tests/tls/client.key")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
Reference in New Issue
Block a user