Update README and examples

This commit is contained in:
Juan Calderon-Perez
2023-04-09 21:24:25 -07:00
parent e3320c4084
commit 78849085f0
3 changed files with 74 additions and 76 deletions

View File

@@ -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,33 +143,7 @@ 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
@@ -159,9 +158,8 @@ var ConfigDefault = Config{
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: "",