mirror of
https://github.com/gofiber/storage.git
synced 2025-10-05 16:48:25 +08:00
Update README and examples
This commit is contained in:
@@ -17,7 +17,7 @@ func (s *Storage) Set(key string, val []byte, exp time.Duration) error
|
|||||||
func (s *Storage) Delete(key string) error
|
func (s *Storage) Delete(key string) error
|
||||||
func (s *Storage) Reset() error
|
func (s *Storage) Reset() error
|
||||||
func (s *Storage) Close() error
|
func (s *Storage) Close() error
|
||||||
func (s *Storage) Conn() *redis.Client
|
func (s *Storage) Conn() redis.UniversalClient
|
||||||
```
|
```
|
||||||
### Installation
|
### Installation
|
||||||
Redis is tested on the 2 last [Go versions](https://golang.org/dl/) with support for modules. So make sure to initialize one first if you didn't do that yet:
|
Redis is tested on the 2 last [Go versions](https://golang.org/dl/) with support for modules. So make sure to initialize one first if you didn't do that yet:
|
||||||
@@ -46,21 +46,21 @@ store := redis.New(redis.Config{
|
|||||||
Port: 6379,
|
Port: 6379,
|
||||||
Username: "",
|
Username: "",
|
||||||
Password: "",
|
Password: "",
|
||||||
URL: "",
|
|
||||||
Database: 0,
|
Database: 0,
|
||||||
Reset: false,
|
Reset: false,
|
||||||
TLSConfig: nil,
|
TLSConfig: nil,
|
||||||
PoolSize: 10 * runtime.GOMAXPROCS(0),
|
PoolSize: 10 * runtime.GOMAXPROCS(0),
|
||||||
})
|
})
|
||||||
|
|
||||||
// Initialize Redis Sentinel Server Client
|
// Initialize Redis Failover Client
|
||||||
store := redis.New(redis.Config{
|
store := redis.New(redis.Config{
|
||||||
EnableFailover: true,
|
|
||||||
MasterName: "master-name",
|
MasterName: "master-name",
|
||||||
SentinelHosts: []string{":6379", ":6380", ":6381"},
|
Addrs: []string{":6379"},
|
||||||
ClientName: "",
|
})
|
||||||
SentinelUsername: "",
|
|
||||||
SentinelPassword: "",
|
// Initialize Redis Cluster Client
|
||||||
|
store := redis.New(redis.Config{
|
||||||
|
Addrs: []string{":6379", ":6380"},
|
||||||
})
|
})
|
||||||
|
|
||||||
// or just the url with all information
|
// or just the url with all information
|
||||||
@@ -98,12 +98,37 @@ type Config struct {
|
|||||||
// Optional. Default is 0
|
// Optional. Default is 0
|
||||||
Database int
|
Database int
|
||||||
|
|
||||||
// URL the standard format redis url to parse all other options. If this is set all other config options, Host, Port, Username, Password, Database have no effect.
|
// URL standard format Redis URL. If this is set all other config options, Host, Port, Username, Password, Database have no effect.
|
||||||
//
|
//
|
||||||
// Example: redis://<user>:<pass>@localhost:6379/<db>
|
// Example: redis://<user>:<pass>@localhost:6379/<db>
|
||||||
// Optional. Default is ""
|
// Optional. Default is ""
|
||||||
URL string
|
URL string
|
||||||
|
|
||||||
|
// Either a single address or a seed list of host:port addresses, this enables FailoverClient and ClusterClient
|
||||||
|
//
|
||||||
|
// Optional. Default is []string{}
|
||||||
|
Addrs []string
|
||||||
|
|
||||||
|
// MasterName is the sentinel master's name
|
||||||
|
//
|
||||||
|
// Optional. Default is ""
|
||||||
|
MasterName string
|
||||||
|
|
||||||
|
// ClientName will execute the `CLIENT SETNAME ClientName` command for each conn.
|
||||||
|
//
|
||||||
|
// Optional. Default is ""
|
||||||
|
ClientName string
|
||||||
|
|
||||||
|
// SentinelUsername
|
||||||
|
//
|
||||||
|
// Optional. Default is ""
|
||||||
|
SentinelUsername string
|
||||||
|
|
||||||
|
// SentinelPassword
|
||||||
|
//
|
||||||
|
// Optional. Default is ""
|
||||||
|
SentinelPassword string
|
||||||
|
|
||||||
// Reset clears any existing keys in existing Collection
|
// Reset clears any existing keys in existing Collection
|
||||||
//
|
//
|
||||||
// Optional. Default is false
|
// Optional. Default is false
|
||||||
@@ -118,52 +143,25 @@ type Config struct {
|
|||||||
//
|
//
|
||||||
// Optional. Default is 10 connections per every available CPU as reported by runtime.GOMAXPROCS.
|
// Optional. Default is 10 connections per every available CPU as reported by runtime.GOMAXPROCS.
|
||||||
PoolSize int
|
PoolSize int
|
||||||
|
|
||||||
// EnableFailover to use redis FailoverClient with Sentinel instead of the standard redis Client
|
|
||||||
//
|
|
||||||
// Optional. Default is false
|
|
||||||
EnableFailover bool
|
|
||||||
|
|
||||||
// MasterName is the sentinel master's name
|
|
||||||
//
|
|
||||||
// Optional. Default is ""
|
|
||||||
MasterName string
|
|
||||||
|
|
||||||
// SentinelHosts where the Redis Sentinel is hosted
|
|
||||||
//
|
|
||||||
// Optional. Default is []string{}
|
|
||||||
SentinelHosts []string
|
|
||||||
|
|
||||||
// SentinelUsername
|
|
||||||
//
|
|
||||||
// Optional. Default is ""
|
|
||||||
SentinelUsername string
|
|
||||||
|
|
||||||
// SentinelPassword
|
|
||||||
//
|
|
||||||
// Optional. Default is ""
|
|
||||||
SentinelPassword string
|
|
||||||
}
|
}
|
||||||
|
|
||||||
```
|
```
|
||||||
|
|
||||||
### Default Config
|
### Default Config
|
||||||
```go
|
```go
|
||||||
var ConfigDefault = Config{
|
var ConfigDefault = Config{
|
||||||
Host: "127.0.0.1",
|
Host: "127.0.0.1",
|
||||||
Port: 6379,
|
Port: 6379,
|
||||||
Username: "",
|
Username: "",
|
||||||
Password: "",
|
Password: "",
|
||||||
URL: "",
|
URL: "",
|
||||||
Database: 0,
|
Database: 0,
|
||||||
Reset: false,
|
Reset: false,
|
||||||
TLSConfig: nil,
|
TLSConfig: nil,
|
||||||
PoolSize: 10 * runtime.GOMAXPROCS(0),
|
PoolSize: 10 * runtime.GOMAXPROCS(0),
|
||||||
EnableFailover: false,
|
Addrs: []string{},
|
||||||
MasterName: "",
|
MasterName: "",
|
||||||
SentinelHosts: []string{},
|
ClientName: "",
|
||||||
ClientName: "",
|
SentinelUsername: "",
|
||||||
SentinelUsername: "",
|
SentinelPassword: "",
|
||||||
SentinelPassword: "",
|
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
@@ -81,20 +81,20 @@ type Config struct {
|
|||||||
|
|
||||||
// ConfigDefault is the default config
|
// ConfigDefault is the default config
|
||||||
var ConfigDefault = Config{
|
var ConfigDefault = Config{
|
||||||
Host: "127.0.0.1",
|
Host: "127.0.0.1",
|
||||||
Port: 6379,
|
Port: 6379,
|
||||||
Username: "",
|
Username: "",
|
||||||
Password: "",
|
Password: "",
|
||||||
URL: "",
|
URL: "",
|
||||||
Database: 0,
|
Database: 0,
|
||||||
Reset: false,
|
Reset: false,
|
||||||
TLSConfig: nil,
|
TLSConfig: nil,
|
||||||
PoolSize: 10 * runtime.GOMAXPROCS(0),
|
PoolSize: 10 * runtime.GOMAXPROCS(0),
|
||||||
Addrs: []string{},
|
Addrs: []string{},
|
||||||
MasterName: "",
|
MasterName: "",
|
||||||
ClientName: "",
|
ClientName: "",
|
||||||
SentinelUsername: "",
|
SentinelUsername: "",
|
||||||
SentinelPassword: "",
|
SentinelPassword: "",
|
||||||
}
|
}
|
||||||
|
|
||||||
// Helper function to set default values
|
// Helper function to set default values
|
||||||
|
@@ -195,7 +195,7 @@ func Test_Redis_Initalize_WithURL_TLS(t *testing.T) {
|
|||||||
func Test_Redis_Universal_Addrs(t *testing.T) {
|
func Test_Redis_Universal_Addrs(t *testing.T) {
|
||||||
// This should failover and create a Single Node connection.
|
// This should failover and create a Single Node connection.
|
||||||
testStoreUniversal := New(Config{
|
testStoreUniversal := New(Config{
|
||||||
Addrs: []string{"localhost:6379"},
|
Addrs: []string{"localhost:6379"},
|
||||||
})
|
})
|
||||||
|
|
||||||
var (
|
var (
|
||||||
@@ -220,8 +220,8 @@ func Test_Redis_Universal_With_URL_Undefined(t *testing.T) {
|
|||||||
// This should failover to creating a regular *redis.Client
|
// This should failover to creating a regular *redis.Client
|
||||||
// The URL should get ignored since it's empty
|
// The URL should get ignored since it's empty
|
||||||
testStoreUniversal := New(Config{
|
testStoreUniversal := New(Config{
|
||||||
URL: "",
|
URL: "",
|
||||||
Addrs: []string{"localhost:6379"},
|
Addrs: []string{"localhost:6379"},
|
||||||
})
|
})
|
||||||
|
|
||||||
var (
|
var (
|
||||||
@@ -246,8 +246,8 @@ func Test_Redis_Universal_With_URL_Defined(t *testing.T) {
|
|||||||
// This should failover to creating a regular *redis.Client
|
// This should failover to creating a regular *redis.Client
|
||||||
// The Addrs field should get ignored since URL is defined
|
// The Addrs field should get ignored since URL is defined
|
||||||
testStoreUniversal := New(Config{
|
testStoreUniversal := New(Config{
|
||||||
URL: "redis://localhost:6379",
|
URL: "redis://localhost:6379",
|
||||||
Addrs: []string{"localhost:6355"},
|
Addrs: []string{"localhost:6355"},
|
||||||
})
|
})
|
||||||
|
|
||||||
var (
|
var (
|
||||||
@@ -272,9 +272,9 @@ func Test_Redis_Universal_With_HostPort(t *testing.T) {
|
|||||||
// This should failover to creating a regular *redis.Client
|
// This should failover to creating a regular *redis.Client
|
||||||
// The Host and Port should get ignored since Addrs is defined
|
// The Host and Port should get ignored since Addrs is defined
|
||||||
testStoreUniversal := New(Config{
|
testStoreUniversal := New(Config{
|
||||||
Host: "localhost",
|
Host: "localhost",
|
||||||
Port: 6388,
|
Port: 6388,
|
||||||
Addrs: []string{"localhost:6379"},
|
Addrs: []string{"localhost:6379"},
|
||||||
})
|
})
|
||||||
|
|
||||||
var (
|
var (
|
||||||
@@ -299,10 +299,10 @@ func Test_Redis_Universal_With_HostPort_And_URL(t *testing.T) {
|
|||||||
// This should failover to creating a regular *redis.Client
|
// This should failover to creating a regular *redis.Client
|
||||||
// The Host and Port should get ignored since Addrs is defined
|
// The Host and Port should get ignored since Addrs is defined
|
||||||
testStoreUniversal := New(Config{
|
testStoreUniversal := New(Config{
|
||||||
URL: "redis://localhost:6379",
|
URL: "redis://localhost:6379",
|
||||||
Host: "localhost",
|
Host: "localhost",
|
||||||
Port: 6388,
|
Port: 6388,
|
||||||
Addrs: []string{"localhost:6399"},
|
Addrs: []string{"localhost:6399"},
|
||||||
})
|
})
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
Reference in New Issue
Block a user