From 92da8e1d9085f8cc1eebe34e668335d2d9e26c96 Mon Sep 17 00:00:00 2001 From: Juan Calderon-Perez <835733+gaby@users.noreply.github.com> Date: Mon, 13 Oct 2025 13:13:36 -0400 Subject: [PATCH 1/9] Revert DisableStartupCheck changes for select drivers --- memcache/README.md | 6 ++++ memcache/config.go | 12 +++++-- memcache/memcache.go | 16 +++++---- memcache/memcache_test.go | 10 ++++++ mysql/README.md | 6 ++++ mysql/config.go | 28 +++++++++------- mysql/mysql.go | 40 ++++++++++++----------- mysql/mysql_test.go | 12 +++++++ postgres/README.md | 6 ++++ postgres/config.go | 22 ++++++++----- postgres/postgres.go | 68 +++++++++++++++++++++------------------ postgres/postgres_test.go | 12 +++++++ redis/README.md | 6 ++++ redis/config.go | 36 ++++++++++++--------- redis/redis.go | 18 ++++++----- redis/redis_test.go | 13 ++++++++ 16 files changed, 209 insertions(+), 102 deletions(-) diff --git a/memcache/README.md b/memcache/README.md index 21d39dee1..6d2daeec2 100644 --- a/memcache/README.md +++ b/memcache/README.md @@ -73,6 +73,11 @@ type Config struct { // // Optional. Default is false Reset bool + + // DisableStartupCheck skips the initial connection validation during New. + // + // Optional. Default is false + DisableStartupCheck bool } ``` @@ -80,5 +85,6 @@ type Config struct { ```go var ConfigDefault = Config{ Servers: "127.0.0.1:11211", + DisableStartupCheck: false, } ``` diff --git a/memcache/config.go b/memcache/config.go index 7e34e06c6..cb96483b1 100644 --- a/memcache/config.go +++ b/memcache/config.go @@ -15,6 +15,11 @@ type Config struct { // Optional. Default is false Reset bool + // DisableStartupCheck skips the initial connection validation during New. + // + // Optional. Default is false + DisableStartupCheck bool + // The socket read/write timeout. // // Optional. Default is 100 * time.Millisecond @@ -31,9 +36,10 @@ type Config struct { // ConfigDefault is the default config var ConfigDefault = Config{ - Servers: "127.0.0.1:11211", - timeout: 100 * time.Millisecond, - maxIdleConns: 2, + Servers: "127.0.0.1:11211", + timeout: 100 * time.Millisecond, + maxIdleConns: 2, + DisableStartupCheck: false, } // Helper function to set default values diff --git a/memcache/memcache.go b/memcache/memcache.go index 139da935a..5547c7348 100644 --- a/memcache/memcache.go +++ b/memcache/memcache.go @@ -30,15 +30,17 @@ func New(config ...Config) *Storage { db.Timeout = cfg.timeout db.MaxIdleConns = cfg.maxIdleConns - // Ping database to ensure a connection has been made - if err := db.Ping(); err != nil { - panic(err) - } - - if cfg.Reset { - if err := db.DeleteAll(); err != nil { + if !cfg.DisableStartupCheck { + // Ping database to ensure a connection has been made + if err := db.Ping(); err != nil { panic(err) } + + if cfg.Reset { + if err := db.DeleteAll(); err != nil { + panic(err) + } + } } // Create storage diff --git a/memcache/memcache_test.go b/memcache/memcache_test.go index a6449f28a..4af3cf5cd 100644 --- a/memcache/memcache_test.go +++ b/memcache/memcache_test.go @@ -178,6 +178,16 @@ func Test_Memcache_Reset(t *testing.T) { require.Zero(t, len(result)) } +func Test_Memcache_New_DisableStartupCheck(t *testing.T) { + require.NotPanics(t, func() { + store := New(Config{ + Servers: "127.0.0.1:11210", + DisableStartupCheck: true, + }) + require.NotNil(t, store) + }) +} + func Test_Memcache_Close(t *testing.T) { testStore := newTestStore(t) require.Nil(t, testStore.Close()) diff --git a/mysql/README.md b/mysql/README.md index 4c9bcdd6e..06da231d8 100644 --- a/mysql/README.md +++ b/mysql/README.md @@ -127,6 +127,11 @@ type Config struct { // Optional. Default is false Reset bool + // DisableStartupCheck skips the initial connection validation during New. + // + // Optional. Default is false + DisableStartupCheck bool + // Time before deleting expired keys // // Optional. Default is 10 * time.Second @@ -143,6 +148,7 @@ var ConfigDefault = Config{ Database: "fiber", Table: "fiber_storage", Reset: false, + DisableStartupCheck: false, GCInterval: 10 * time.Second, } ``` diff --git a/mysql/config.go b/mysql/config.go index d16349de6..7ae38af9e 100644 --- a/mysql/config.go +++ b/mysql/config.go @@ -53,6 +53,11 @@ type Config struct { // Optional. Default is false Reset bool + // DisableStartupCheck skips the initial connection validation during New. + // + // Optional. Default is false + DisableStartupCheck bool + // Time before deleting expired keys // // Optional. Default is 10 * time.Second @@ -69,17 +74,18 @@ type Config struct { // ConfigDefault is the default config var ConfigDefault = Config{ - Db: nil, - ConnectionURI: "", - Host: "127.0.0.1", - Port: 3306, - Database: "fiber", - Table: "fiber_storage", - Reset: false, - GCInterval: 10 * time.Second, - maxOpenConns: 100, - maxIdleConns: 100, - connMaxLifetime: 1 * time.Second, + Db: nil, + ConnectionURI: "", + Host: "127.0.0.1", + Port: 3306, + Database: "fiber", + Table: "fiber_storage", + Reset: false, + DisableStartupCheck: false, + GCInterval: 10 * time.Second, + maxOpenConns: 100, + maxIdleConns: 100, + connMaxLifetime: 1 * time.Second, } func (c Config) dsn() string { diff --git a/mysql/mysql.go b/mysql/mysql.go index ae0bfcd25..f1db737cb 100644 --- a/mysql/mysql.go +++ b/mysql/mysql.go @@ -63,26 +63,28 @@ func New(config ...Config) *Storage { db.SetConnMaxLifetime(cfg.connMaxLifetime) } - // Ping database to ensure a connection has been made - if err := db.Ping(); err != nil { - panic(err) - } - - // Drop table if Clear set to true - if cfg.Reset { - query := fmt.Sprintf(dropQuery, cfg.Table) - if _, err = db.Exec(query); err != nil { - _ = db.Close() + if !cfg.DisableStartupCheck { + // Ping database to ensure a connection has been made + if err := db.Ping(); err != nil { panic(err) } - } - // Init database queries - for _, query := range initQuery { - query = fmt.Sprintf(query, cfg.Table) - if _, err := db.Exec(query); err != nil { - _ = db.Close() - panic(err) + // Drop table if Clear set to true + if cfg.Reset { + query := fmt.Sprintf(dropQuery, cfg.Table) + if _, err = db.Exec(query); err != nil { + _ = db.Close() + panic(err) + } + } + + // Init database queries + for _, query := range initQuery { + query = fmt.Sprintf(query, cfg.Table) + if _, err := db.Exec(query); err != nil { + _ = db.Close() + panic(err) + } } } @@ -98,7 +100,9 @@ func New(config ...Config) *Storage { sqlGC: fmt.Sprintf("DELETE FROM %s WHERE e <= ? AND e != 0", cfg.Table), } - store.checkSchema(cfg.Table) + if !cfg.DisableStartupCheck { + store.checkSchema(cfg.Table) + } // Start garbage collector go store.gcTicker() diff --git a/mysql/mysql_test.go b/mysql/mysql_test.go index 19ee758d1..143646206 100644 --- a/mysql/mysql_test.go +++ b/mysql/mysql_test.go @@ -108,6 +108,18 @@ func Test_MYSQL_New(t *testing.T) { defer newConfigStore.Close() } +func Test_MYSQL_New_DisableStartupCheck(t *testing.T) { + require.NotPanics(t, func() { + store := New(Config{ + Host: "127.0.0.1", + Port: 3308, + DisableStartupCheck: true, + }) + require.NotNil(t, store) + defer store.Close() + }) +} + func Test_MYSQL_GC(t *testing.T) { testVal := []byte("doe") diff --git a/postgres/README.md b/postgres/README.md index a49479f2d..11ccd6f0a 100644 --- a/postgres/README.md +++ b/postgres/README.md @@ -117,6 +117,11 @@ type Config struct { // Optional. Default is false Reset bool + // DisableStartupCheck skips the initial connection validation during New. + // + // Optional. Default is false + DisableStartupCheck bool + // Time before deleting expired keys // // Optional. Default is 10 * time.Second @@ -135,6 +140,7 @@ var ConfigDefault = Config{ Table: "fiber_storage", SSLMode: "disable", Reset: false, + DisableStartupCheck: false, GCInterval: 10 * time.Second, } ``` diff --git a/postgres/config.go b/postgres/config.go index aecbfe973..d817b57e1 100644 --- a/postgres/config.go +++ b/postgres/config.go @@ -61,6 +61,11 @@ type Config struct { // Optional. Default is false Reset bool + // DisableStartupCheck skips the initial connection validation during New. + // + // Optional. Default is false + DisableStartupCheck bool + // Time before deleting expired keys // // Optional. Default is 10 * time.Second @@ -69,14 +74,15 @@ type Config struct { // ConfigDefault is the default config var ConfigDefault = Config{ - ConnectionURI: "", - Host: "127.0.0.1", - Port: 5432, - Database: "fiber", - Table: "fiber_storage", - SSLMode: "disable", - Reset: false, - GCInterval: 10 * time.Second, + ConnectionURI: "", + Host: "127.0.0.1", + Port: 5432, + Database: "fiber", + Table: "fiber_storage", + SSLMode: "disable", + Reset: false, + DisableStartupCheck: false, + GCInterval: 10 * time.Second, } func (c *Config) getDSN() string { diff --git a/postgres/postgres.go b/postgres/postgres.go index 3175906d3..0585b39d6 100644 --- a/postgres/postgres.go +++ b/postgres/postgres.go @@ -68,45 +68,47 @@ func New(config ...Config) *Storage { } } - // Ping database - if err := db.Ping(context.Background()); err != nil { - panic(err) - } - - // Parse out schema in config, if provided - schema := "public" - tableName := cfg.Table - if strings.Contains(cfg.Table, ".") { - schema = strings.Split(cfg.Table, ".")[0] - tableName = strings.Split(cfg.Table, ".")[1] - } - - // Drop table if set to true - if cfg.Reset { - if _, err := db.Exec(context.Background(), fmt.Sprintf(dropQuery, cfg.Table)); err != nil { - db.Close() + if !cfg.DisableStartupCheck { + // Ping database + if err := db.Ping(context.Background()); err != nil { panic(err) } - } - // Determine if table exists - tableExists := false - row := db.QueryRow(context.Background(), fmt.Sprintf(checkTableExistsQuery, schema, tableName)) - var count int - if err := row.Scan(&count); err != nil { - db.Close() - panic(err) - } - tableExists = count > 0 + // Parse out schema in config, if provided + schema := "public" + tableName := cfg.Table + if strings.Contains(cfg.Table, ".") { + schema = strings.Split(cfg.Table, ".")[0] + tableName = strings.Split(cfg.Table, ".")[1] + } - // Init database queries - if !tableExists { - for _, query := range initQuery { - if _, err := db.Exec(context.Background(), fmt.Sprintf(query, cfg.Table)); err != nil { + // Drop table if set to true + if cfg.Reset { + if _, err := db.Exec(context.Background(), fmt.Sprintf(dropQuery, cfg.Table)); err != nil { db.Close() panic(err) } } + + // Determine if table exists + tableExists := false + row := db.QueryRow(context.Background(), fmt.Sprintf(checkTableExistsQuery, schema, tableName)) + var count int + if err := row.Scan(&count); err != nil { + db.Close() + panic(err) + } + tableExists = count > 0 + + // Init database queries + if !tableExists { + for _, query := range initQuery { + if _, err := db.Exec(context.Background(), fmt.Sprintf(query, cfg.Table)); err != nil { + db.Close() + panic(err) + } + } + } } // Create storage @@ -121,7 +123,9 @@ func New(config ...Config) *Storage { sqlGC: fmt.Sprintf("DELETE FROM %s WHERE e <= $1 AND e != 0", cfg.Table), } - store.checkSchema(cfg.Table) + if !cfg.DisableStartupCheck { + store.checkSchema(cfg.Table) + } // Start garbage collector go store.gcTicker() diff --git a/postgres/postgres_test.go b/postgres/postgres_test.go index f20f8f1fd..4a711d0e1 100644 --- a/postgres/postgres_test.go +++ b/postgres/postgres_test.go @@ -202,6 +202,18 @@ func TestNoCreateUser(t *testing.T) { }) } + +func Test_Postgres_New_DisableStartupCheck(t *testing.T) { + require.NotPanics(t, func() { + store := New(Config{ + Host: "127.0.0.1", + Port: 65432, + DisableStartupCheck: true, + }) + require.NotNil(t, store) + defer store.Close() + }) +} func Test_Should_Panic_On_Wrong_Schema(t *testing.T) { testStore := newTestStore(t) defer testStore.Close() diff --git a/redis/README.md b/redis/README.md index 308262bef..974e8f4d7 100644 --- a/redis/README.md +++ b/redis/README.md @@ -180,6 +180,11 @@ type Config struct { // Optional. Default is false Reset bool + // DisableStartupCheck skips the initial connection validation during New. + // + // Optional. Default is false + DisableStartupCheck bool + // TLS Config to use. When set TLS will be negotiated. // // Optional. Default is nil @@ -208,6 +213,7 @@ var ConfigDefault = Config{ URL: "", Database: 0, Reset: false, + DisableStartupCheck: false, TLSConfig: nil, PoolSize: 10 * runtime.GOMAXPROCS(0), Addrs: []string{}, diff --git a/redis/config.go b/redis/config.go index 2f9f549e0..a7711b22f 100644 --- a/redis/config.go +++ b/redis/config.go @@ -68,6 +68,11 @@ type Config struct { // Optional. Default is false Reset bool + // DisableStartupCheck skips the initial connection validation during New. + // + // Optional. Default is false + DisableStartupCheck bool + // TLS Config to use. When set TLS will be negotiated. // // Optional. Default is nil @@ -87,21 +92,22 @@ type Config struct { // ConfigDefault is the default config var ConfigDefault = Config{ - Host: "127.0.0.1", - Port: 6379, - Username: "", - Password: "", - URL: "", - Database: 0, - Reset: false, - TLSConfig: nil, - PoolSize: 10 * runtime.GOMAXPROCS(0), - Addrs: []string{}, - MasterName: "", - ClientName: "", - SentinelUsername: "", - SentinelPassword: "", - IsClusterMode: false, + Host: "127.0.0.1", + Port: 6379, + Username: "", + Password: "", + URL: "", + Database: 0, + Reset: false, + DisableStartupCheck: false, + TLSConfig: nil, + PoolSize: 10 * runtime.GOMAXPROCS(0), + Addrs: []string{}, + MasterName: "", + ClientName: "", + SentinelUsername: "", + SentinelPassword: "", + IsClusterMode: false, } // Helper function to set default values diff --git a/redis/redis.go b/redis/redis.go index e2fc4b0fa..65f6d7c3d 100644 --- a/redis/redis.go +++ b/redis/redis.go @@ -65,16 +65,18 @@ func New(config ...Config) *Storage { IsClusterMode: cfg.IsClusterMode, }) - // Test connection - if err := db.Ping(context.Background()).Err(); err != nil { - panic(err) - } - - // Empty collection if Clear is true - if cfg.Reset { - if err := db.FlushDB(context.Background()).Err(); err != nil { + if !cfg.DisableStartupCheck { + // Test connection + if err := db.Ping(context.Background()).Err(); err != nil { panic(err) } + + // Empty collection if Clear is true + if cfg.Reset { + if err := db.FlushDB(context.Background()).Err(); err != nil { + panic(err) + } + } } // Create new store diff --git a/redis/redis_test.go b/redis/redis_test.go index d97126a7e..7f295aea2 100644 --- a/redis/redis_test.go +++ b/redis/redis_test.go @@ -198,6 +198,19 @@ func Test_Redis_Delete(t *testing.T) { require.Nil(t, keys) } +func Test_Redis_New_DisableStartupCheck(t *testing.T) { + require.NotPanics(t, func() { + store := New(Config{ + Host: "127.0.0.1", + Port: 6390, + Addrs: []string{"127.0.0.1:6390"}, + DisableStartupCheck: true, + }) + require.NotNil(t, store) + _ = store.Close() + }) +} + func Test_Redis_DeleteWithContext(t *testing.T) { var ( key = "john" From 5652ca01b7bab48b231aaa1504d1fa9aaaba96f1 Mon Sep 17 00:00:00 2001 From: Juan Calderon-Perez <835733+gaby@users.noreply.github.com> Date: Mon, 13 Oct 2025 13:37:29 -0400 Subject: [PATCH 2/9] Add DisableStartupCheck support to Rueidis driver --- rueidis/README.md | 32 +++++++++++++++++++------------- rueidis/config.go | 10 ++++++++++ rueidis/rueidis.go | 18 ++++++++++-------- rueidis/rueidis_test.go | 11 +++++++++++ 4 files changed, 50 insertions(+), 21 deletions(-) diff --git a/rueidis/README.md b/rueidis/README.md index 32aa5890a..eef0d3489 100644 --- a/rueidis/README.md +++ b/rueidis/README.md @@ -179,15 +179,20 @@ type Config struct { // Optional. The default is true AlwaysPipelining bool - // Reset clears any existing keys in existing Collection - // - // Optional. Default is false - Reset bool - - // CacheTTL TTL - // - // Optional. Default is time.Minute - CacheTTL time.Duration + // Reset clears any existing keys in existing Collection + // + // Optional. Default is false + Reset bool + + // DisableStartupCheck skips the initial connection validation during New. + // + // Optional. Default is false + DisableStartupCheck bool + + // CacheTTL TTL + // + // Optional. Default is time.Minute + CacheTTL time.Duration } ``` @@ -207,9 +212,10 @@ var ConfigDefault = Config{ BlockingPoolSize: rueidis.DefaultPoolSize, PipelineMultiplex: 2, DisableRetry: false, - DisableCache: false, - AlwaysPipelining: true, - Reset: false, - CacheTTL: time.Minute, + DisableCache: false, + AlwaysPipelining: true, + Reset: false, + DisableStartupCheck: false, + CacheTTL: time.Minute, } ``` diff --git a/rueidis/config.go b/rueidis/config.go index 17f83610a..c67ec7c2f 100644 --- a/rueidis/config.go +++ b/rueidis/config.go @@ -95,6 +95,11 @@ type Config struct { // Optional. Default is false Reset bool + // DisableStartupCheck skips the initial connection validation during New. + // + // Optional. Default is false + DisableStartupCheck bool + // CacheTTL TTL // // Optional. Default is time.Minute @@ -120,6 +125,7 @@ var ConfigDefault = Config{ DisableCache: false, AlwaysPipelining: true, Reset: false, + DisableStartupCheck: false, CacheTTL: time.Minute, } @@ -194,5 +200,9 @@ func configDefault(config ...Config) Config { cfg.Reset = true } + if userConfig.DisableStartupCheck { + cfg.DisableStartupCheck = true + } + return cfg } diff --git a/rueidis/rueidis.go b/rueidis/rueidis.go index f6c997932..15c2c878f 100644 --- a/rueidis/rueidis.go +++ b/rueidis/rueidis.go @@ -67,16 +67,18 @@ func New(config ...Config) *Storage { panic(err) } - // Test connection - if err := db.Do(context.Background(), db.B().Ping().Build()).Error(); err != nil { - panic(err) - } - - // Empty collection if Clear is true - if cfg.Reset { - if err := db.Do(context.Background(), db.B().Flushdb().Build()).Error(); err != nil { + if !cfg.DisableStartupCheck { + // Test connection + if err := db.Do(context.Background(), db.B().Ping().Build()).Error(); err != nil { panic(err) } + + // Empty collection if Clear is true + if cfg.Reset { + if err := db.Do(context.Background(), db.B().Flushdb().Build()).Error(); err != nil { + panic(err) + } + } } // Create new store diff --git a/rueidis/rueidis_test.go b/rueidis/rueidis_test.go index 24b59ef61..2da9417a0 100644 --- a/rueidis/rueidis_test.go +++ b/rueidis/rueidis_test.go @@ -49,6 +49,17 @@ func newTestStore(t testing.TB, opts ...testredis.Option) *Storage { return New(newConfigFromContainer(t, opts...)) } +func Test_Rueidis_New_DisableStartupCheck(t *testing.T) { + require.NotPanics(t, func() { + store := New(Config{ + InitAddress: []string{"127.0.0.1:6390"}, + DisableStartupCheck: true, + }) + require.NotNil(t, store) + require.NoError(t, store.Close()) + }) +} + func Test_Rueidis_Set(t *testing.T) { var ( key = "john" From 1782bd5841730329fda24783764b6efb1663aed0 Mon Sep 17 00:00:00 2001 From: Juan Calderon-Perez <835733+gaby@users.noreply.github.com> Date: Mon, 13 Oct 2025 17:51:01 -0400 Subject: [PATCH 3/9] Avoid rueidis panic when startup checks disabled --- rueidis/rueidis.go | 106 ++++++++++++++++++++++++++++++++------------- 1 file changed, 77 insertions(+), 29 deletions(-) diff --git a/rueidis/rueidis.go b/rueidis/rueidis.go index 15c2c878f..9d969e5cc 100644 --- a/rueidis/rueidis.go +++ b/rueidis/rueidis.go @@ -2,6 +2,7 @@ package rueidis import ( "context" + "sync" "time" "github.com/redis/rueidis" @@ -11,7 +12,9 @@ var cacheTTL = time.Second // Storage interface that is implemented by storage providers type Storage struct { - db rueidis.Client + mu sync.Mutex + db rueidis.Client + cfg Config } // New creates a new rueidis storage @@ -45,29 +48,12 @@ func New(config ...Config) *Storage { } } - // Update config values accordingly and start new Client - db, err := rueidis.NewClient(rueidis.ClientOption{ - Username: cfg.Username, - Password: cfg.Password, - ClientName: cfg.ClientName, - SelectDB: cfg.SelectDB, - InitAddress: cfg.InitAddress, - TLSConfig: cfg.TLSConfig, - CacheSizeEachConn: cfg.CacheSizeEachConn, - RingScaleEachConn: cfg.RingScaleEachConn, - ReadBufferEachConn: cfg.ReadBufferEachConn, - WriteBufferEachConn: cfg.WriteBufferEachConn, - BlockingPoolSize: cfg.BlockingPoolSize, - PipelineMultiplex: cfg.PipelineMultiplex, - DisableRetry: cfg.DisableRetry, - DisableCache: cfg.DisableCache, - AlwaysPipelining: cfg.AlwaysPipelining, - }) + db, err := newRueidisClient(cfg) if err != nil { - panic(err) - } - - if !cfg.DisableStartupCheck { + if !cfg.DisableStartupCheck { + panic(err) + } + } else if !cfg.DisableStartupCheck { // Test connection if err := db.Do(context.Background(), db.B().Ping().Build()).Error(); err != nil { panic(err) @@ -83,7 +69,8 @@ func New(config ...Config) *Storage { // Create new store return &Storage{ - db: db, + db: db, + cfg: cfg, } } @@ -92,7 +79,11 @@ func (s *Storage) GetWithContext(ctx context.Context, key string) ([]byte, error if len(key) <= 0 { return nil, nil } - val, err := s.db.DoCache(ctx, s.db.B().Get().Key(key).Cache(), cacheTTL).AsBytes() + db, err := s.getClient() + if err != nil { + return nil, err + } + val, err := db.DoCache(ctx, db.B().Get().Key(key).Cache(), cacheTTL).AsBytes() if err != nil && rueidis.IsRedisNil(err) { return nil, nil } @@ -109,10 +100,14 @@ func (s *Storage) SetWithContext(ctx context.Context, key string, val []byte, ex if len(key) <= 0 || len(val) <= 0 { return nil } + db, err := s.getClient() + if err != nil { + return err + } if exp > 0 { - return s.db.Do(ctx, s.db.B().Set().Key(key).Value(string(val)).Ex(exp).Build()).Error() + return db.Do(ctx, db.B().Set().Key(key).Value(string(val)).Ex(exp).Build()).Error() } else { - return s.db.Do(ctx, s.db.B().Set().Key(key).Value(string(val)).Build()).Error() + return db.Do(ctx, db.B().Set().Key(key).Value(string(val)).Build()).Error() } } @@ -126,7 +121,11 @@ func (s *Storage) DeleteWithContext(ctx context.Context, key string) error { if len(key) <= 0 { return nil } - return s.db.Do(ctx, s.db.B().Del().Key(key).Build()).Error() + db, err := s.getClient() + if err != nil { + return err + } + return db.Do(ctx, db.B().Del().Key(key).Build()).Error() } // Delete deletes key by key @@ -136,7 +135,11 @@ func (s *Storage) Delete(key string) error { // ResetWithContext resets all keys with context func (s *Storage) ResetWithContext(ctx context.Context) error { - return s.db.Do(ctx, s.db.B().Flushdb().Build()).Error() + db, err := s.getClient() + if err != nil { + return err + } + return db.Do(ctx, db.B().Flushdb().Build()).Error() } // Reset resets all keys @@ -146,7 +149,15 @@ func (s *Storage) Reset() error { // Close the database func (s *Storage) Close() error { + s.mu.Lock() + defer s.mu.Unlock() + + if s.db == nil { + return nil + } + s.db.Close() + s.db = nil return nil } @@ -154,3 +165,40 @@ func (s *Storage) Close() error { func (s *Storage) Conn() rueidis.Client { return s.db } + +func (s *Storage) getClient() (rueidis.Client, error) { + s.mu.Lock() + defer s.mu.Unlock() + + if s.db != nil { + return s.db, nil + } + + db, err := newRueidisClient(s.cfg) + if err != nil { + return nil, err + } + + s.db = db + return s.db, nil +} + +func newRueidisClient(cfg Config) (rueidis.Client, error) { + return rueidis.NewClient(rueidis.ClientOption{ + Username: cfg.Username, + Password: cfg.Password, + ClientName: cfg.ClientName, + SelectDB: cfg.SelectDB, + InitAddress: cfg.InitAddress, + TLSConfig: cfg.TLSConfig, + CacheSizeEachConn: cfg.CacheSizeEachConn, + RingScaleEachConn: cfg.RingScaleEachConn, + ReadBufferEachConn: cfg.ReadBufferEachConn, + WriteBufferEachConn: cfg.WriteBufferEachConn, + BlockingPoolSize: cfg.BlockingPoolSize, + PipelineMultiplex: cfg.PipelineMultiplex, + DisableRetry: cfg.DisableRetry, + DisableCache: cfg.DisableCache, + AlwaysPipelining: cfg.AlwaysPipelining, + }) +} From 75a86506f771f16020f80bf8761dd99dfb5417e1 Mon Sep 17 00:00:00 2001 From: Juan Calderon-Perez <835733+gaby@users.noreply.github.com> Date: Mon, 13 Oct 2025 17:51:07 -0400 Subject: [PATCH 4/9] Revert rueidis lazy initialization --- rueidis/rueidis.go | 93 ++++++++++++---------------------------------- 1 file changed, 24 insertions(+), 69 deletions(-) diff --git a/rueidis/rueidis.go b/rueidis/rueidis.go index 9d969e5cc..3396ac2ab 100644 --- a/rueidis/rueidis.go +++ b/rueidis/rueidis.go @@ -2,7 +2,6 @@ package rueidis import ( "context" - "sync" "time" "github.com/redis/rueidis" @@ -12,9 +11,7 @@ var cacheTTL = time.Second // Storage interface that is implemented by storage providers type Storage struct { - mu sync.Mutex - db rueidis.Client - cfg Config + db rueidis.Client } // New creates a new rueidis storage @@ -48,7 +45,23 @@ func New(config ...Config) *Storage { } } - db, err := newRueidisClient(cfg) + db, err := rueidis.NewClient(rueidis.ClientOption{ + Username: cfg.Username, + Password: cfg.Password, + ClientName: cfg.ClientName, + SelectDB: cfg.SelectDB, + InitAddress: cfg.InitAddress, + TLSConfig: cfg.TLSConfig, + CacheSizeEachConn: cfg.CacheSizeEachConn, + RingScaleEachConn: cfg.RingScaleEachConn, + ReadBufferEachConn: cfg.ReadBufferEachConn, + WriteBufferEachConn: cfg.WriteBufferEachConn, + BlockingPoolSize: cfg.BlockingPoolSize, + PipelineMultiplex: cfg.PipelineMultiplex, + DisableRetry: cfg.DisableRetry, + DisableCache: cfg.DisableCache, + AlwaysPipelining: cfg.AlwaysPipelining, + }) if err != nil { if !cfg.DisableStartupCheck { panic(err) @@ -69,8 +82,7 @@ func New(config ...Config) *Storage { // Create new store return &Storage{ - db: db, - cfg: cfg, + db: db, } } @@ -79,11 +91,7 @@ func (s *Storage) GetWithContext(ctx context.Context, key string) ([]byte, error if len(key) <= 0 { return nil, nil } - db, err := s.getClient() - if err != nil { - return nil, err - } - val, err := db.DoCache(ctx, db.B().Get().Key(key).Cache(), cacheTTL).AsBytes() + val, err := s.db.DoCache(ctx, s.db.B().Get().Key(key).Cache(), cacheTTL).AsBytes() if err != nil && rueidis.IsRedisNil(err) { return nil, nil } @@ -100,14 +108,10 @@ func (s *Storage) SetWithContext(ctx context.Context, key string, val []byte, ex if len(key) <= 0 || len(val) <= 0 { return nil } - db, err := s.getClient() - if err != nil { - return err - } if exp > 0 { - return db.Do(ctx, db.B().Set().Key(key).Value(string(val)).Ex(exp).Build()).Error() + return s.db.Do(ctx, s.db.B().Set().Key(key).Value(string(val)).Ex(exp).Build()).Error() } else { - return db.Do(ctx, db.B().Set().Key(key).Value(string(val)).Build()).Error() + return s.db.Do(ctx, s.db.B().Set().Key(key).Value(string(val)).Build()).Error() } } @@ -121,11 +125,7 @@ func (s *Storage) DeleteWithContext(ctx context.Context, key string) error { if len(key) <= 0 { return nil } - db, err := s.getClient() - if err != nil { - return err - } - return db.Do(ctx, db.B().Del().Key(key).Build()).Error() + return s.db.Do(ctx, s.db.B().Del().Key(key).Build()).Error() } // Delete deletes key by key @@ -135,11 +135,7 @@ func (s *Storage) Delete(key string) error { // ResetWithContext resets all keys with context func (s *Storage) ResetWithContext(ctx context.Context) error { - db, err := s.getClient() - if err != nil { - return err - } - return db.Do(ctx, db.B().Flushdb().Build()).Error() + return s.db.Do(ctx, s.db.B().Flushdb().Build()).Error() } // Reset resets all keys @@ -149,15 +145,11 @@ func (s *Storage) Reset() error { // Close the database func (s *Storage) Close() error { - s.mu.Lock() - defer s.mu.Unlock() - if s.db == nil { return nil } s.db.Close() - s.db = nil return nil } @@ -165,40 +157,3 @@ func (s *Storage) Close() error { func (s *Storage) Conn() rueidis.Client { return s.db } - -func (s *Storage) getClient() (rueidis.Client, error) { - s.mu.Lock() - defer s.mu.Unlock() - - if s.db != nil { - return s.db, nil - } - - db, err := newRueidisClient(s.cfg) - if err != nil { - return nil, err - } - - s.db = db - return s.db, nil -} - -func newRueidisClient(cfg Config) (rueidis.Client, error) { - return rueidis.NewClient(rueidis.ClientOption{ - Username: cfg.Username, - Password: cfg.Password, - ClientName: cfg.ClientName, - SelectDB: cfg.SelectDB, - InitAddress: cfg.InitAddress, - TLSConfig: cfg.TLSConfig, - CacheSizeEachConn: cfg.CacheSizeEachConn, - RingScaleEachConn: cfg.RingScaleEachConn, - ReadBufferEachConn: cfg.ReadBufferEachConn, - WriteBufferEachConn: cfg.WriteBufferEachConn, - BlockingPoolSize: cfg.BlockingPoolSize, - PipelineMultiplex: cfg.PipelineMultiplex, - DisableRetry: cfg.DisableRetry, - DisableCache: cfg.DisableCache, - AlwaysPipelining: cfg.AlwaysPipelining, - }) -} From c28528418450ca829fdd3d326770edee2a200044 Mon Sep 17 00:00:00 2001 From: Juan Calderon-Perez <835733+gaby@users.noreply.github.com> Date: Mon, 13 Oct 2025 18:33:06 -0400 Subject: [PATCH 5/9] Fix rueidis startup check handling and revert mysql changes --- mysql/README.md | 6 -- mysql/config.go | 28 ++++----- mysql/mysql.go | 40 ++++++------ mysql/mysql_test.go | 12 ---- postgres/README.md | 144 ++++++++++++++++++++++---------------------- rueidis/rueidis.go | 8 +-- 6 files changed, 105 insertions(+), 133 deletions(-) diff --git a/mysql/README.md b/mysql/README.md index 06da231d8..4c9bcdd6e 100644 --- a/mysql/README.md +++ b/mysql/README.md @@ -127,11 +127,6 @@ type Config struct { // Optional. Default is false Reset bool - // DisableStartupCheck skips the initial connection validation during New. - // - // Optional. Default is false - DisableStartupCheck bool - // Time before deleting expired keys // // Optional. Default is 10 * time.Second @@ -148,7 +143,6 @@ var ConfigDefault = Config{ Database: "fiber", Table: "fiber_storage", Reset: false, - DisableStartupCheck: false, GCInterval: 10 * time.Second, } ``` diff --git a/mysql/config.go b/mysql/config.go index 7ae38af9e..d16349de6 100644 --- a/mysql/config.go +++ b/mysql/config.go @@ -53,11 +53,6 @@ type Config struct { // Optional. Default is false Reset bool - // DisableStartupCheck skips the initial connection validation during New. - // - // Optional. Default is false - DisableStartupCheck bool - // Time before deleting expired keys // // Optional. Default is 10 * time.Second @@ -74,18 +69,17 @@ type Config struct { // ConfigDefault is the default config var ConfigDefault = Config{ - Db: nil, - ConnectionURI: "", - Host: "127.0.0.1", - Port: 3306, - Database: "fiber", - Table: "fiber_storage", - Reset: false, - DisableStartupCheck: false, - GCInterval: 10 * time.Second, - maxOpenConns: 100, - maxIdleConns: 100, - connMaxLifetime: 1 * time.Second, + Db: nil, + ConnectionURI: "", + Host: "127.0.0.1", + Port: 3306, + Database: "fiber", + Table: "fiber_storage", + Reset: false, + GCInterval: 10 * time.Second, + maxOpenConns: 100, + maxIdleConns: 100, + connMaxLifetime: 1 * time.Second, } func (c Config) dsn() string { diff --git a/mysql/mysql.go b/mysql/mysql.go index f1db737cb..ae0bfcd25 100644 --- a/mysql/mysql.go +++ b/mysql/mysql.go @@ -63,28 +63,26 @@ func New(config ...Config) *Storage { db.SetConnMaxLifetime(cfg.connMaxLifetime) } - if !cfg.DisableStartupCheck { - // Ping database to ensure a connection has been made - if err := db.Ping(); err != nil { - panic(err) - } + // Ping database to ensure a connection has been made + if err := db.Ping(); err != nil { + panic(err) + } - // Drop table if Clear set to true - if cfg.Reset { - query := fmt.Sprintf(dropQuery, cfg.Table) - if _, err = db.Exec(query); err != nil { - _ = db.Close() - panic(err) - } + // Drop table if Clear set to true + if cfg.Reset { + query := fmt.Sprintf(dropQuery, cfg.Table) + if _, err = db.Exec(query); err != nil { + _ = db.Close() + panic(err) } + } - // Init database queries - for _, query := range initQuery { - query = fmt.Sprintf(query, cfg.Table) - if _, err := db.Exec(query); err != nil { - _ = db.Close() - panic(err) - } + // Init database queries + for _, query := range initQuery { + query = fmt.Sprintf(query, cfg.Table) + if _, err := db.Exec(query); err != nil { + _ = db.Close() + panic(err) } } @@ -100,9 +98,7 @@ func New(config ...Config) *Storage { sqlGC: fmt.Sprintf("DELETE FROM %s WHERE e <= ? AND e != 0", cfg.Table), } - if !cfg.DisableStartupCheck { - store.checkSchema(cfg.Table) - } + store.checkSchema(cfg.Table) // Start garbage collector go store.gcTicker() diff --git a/mysql/mysql_test.go b/mysql/mysql_test.go index 143646206..19ee758d1 100644 --- a/mysql/mysql_test.go +++ b/mysql/mysql_test.go @@ -108,18 +108,6 @@ func Test_MYSQL_New(t *testing.T) { defer newConfigStore.Close() } -func Test_MYSQL_New_DisableStartupCheck(t *testing.T) { - require.NotPanics(t, func() { - store := New(Config{ - Host: "127.0.0.1", - Port: 3308, - DisableStartupCheck: true, - }) - require.NotNil(t, store) - defer store.Close() - }) -} - func Test_MYSQL_GC(t *testing.T) { testVal := []byte("doe") diff --git a/postgres/README.md b/postgres/README.md index 11ccd6f0a..068a5d3bc 100644 --- a/postgres/README.md +++ b/postgres/README.md @@ -56,10 +56,10 @@ store := postgres.New() // Initialize custom config store := postgres.New(postgres.Config{ - DB: dbPool, - Table: "fiber_storage", - Reset: false, - GCInterval: 10 * time.Second, + DB: dbPool, + Table: "fiber_storage", + Reset: false, + GCInterval: 10 * time.Second, }) ``` @@ -67,65 +67,65 @@ store := postgres.New(postgres.Config{ ```go // Config defines the config for storage. type Config struct { - // DB pgxpool.Pool object will override connection uri and other connection fields - // - // Optional. Default is nil - DB *pgxpool.Pool - - // Connection string to use for DB. Will override all other authentication values if used - // - // Optional. Default is "" - ConnectionURI string - - // Host name where the DB is hosted - // - // Optional. Default is "127.0.0.1" - Host string - - // Port where the DB is listening on - // - // Optional. Default is 5432 - Port int - - // Server username - // - // Optional. Default is "" - Username string - - // Server password - // - // Optional. Default is "" - Password string - - // Database name - // - // Optional. Default is "fiber" - Database string - - // Table name - // - // Optional. Default is "fiber_storage" - Table string - - // The SSL mode for the connection - // - // Optional. Default is "disable" - SSLMode string - - // Reset clears any existing keys in existing Table - // - // Optional. Default is false - Reset bool - - // DisableStartupCheck skips the initial connection validation during New. - // - // Optional. Default is false - DisableStartupCheck bool - - // Time before deleting expired keys - // - // Optional. Default is 10 * time.Second - GCInterval time.Duration + // DB pgxpool.Pool object will override connection uri and other connection fields + // + // Optional. Default is nil + DB *pgxpool.Pool + + // Connection string to use for DB. Will override all other authentication values if used + // + // Optional. Default is "" + ConnectionURI string + + // Host name where the DB is hosted + // + // Optional. Default is "127.0.0.1" + Host string + + // Port where the DB is listening on + // + // Optional. Default is 5432 + Port int + + // Server username + // + // Optional. Default is "" + Username string + + // Server password + // + // Optional. Default is "" + Password string + + // Database name + // + // Optional. Default is "fiber" + Database string + + // Table name + // + // Optional. Default is "fiber_storage" + Table string + + // The SSL mode for the connection + // + // Optional. Default is "disable" + SSLMode string + + // Reset clears any existing keys in existing Table + // + // Optional. Default is false + Reset bool + + // DisableStartupCheck skips the initial connection validation during New. + // + // Optional. Default is false + DisableStartupCheck bool + + // Time before deleting expired keys + // + // Optional. Default is 10 * time.Second + GCInterval time.Duration } ``` @@ -133,14 +133,14 @@ type Config struct { ```go // ConfigDefault is the default config var ConfigDefault = Config{ - ConnectionURI: "", - Host: "127.0.0.1", - Port: 5432, - Database: "fiber", - Table: "fiber_storage", - SSLMode: "disable", - Reset: false, - DisableStartupCheck: false, - GCInterval: 10 * time.Second, + ConnectionURI: "", + Host: "127.0.0.1", + Port: 5432, + Database: "fiber", + Table: "fiber_storage", + SSLMode: "disable", + Reset: false, + DisableStartupCheck: false, + GCInterval: 10 * time.Second, } ``` diff --git a/rueidis/rueidis.go b/rueidis/rueidis.go index 3396ac2ab..0c4a72e89 100644 --- a/rueidis/rueidis.go +++ b/rueidis/rueidis.go @@ -63,10 +63,10 @@ func New(config ...Config) *Storage { AlwaysPipelining: cfg.AlwaysPipelining, }) if err != nil { - if !cfg.DisableStartupCheck { - panic(err) - } - } else if !cfg.DisableStartupCheck { + panic(err) + } + + if !cfg.DisableStartupCheck { // Test connection if err := db.Do(context.Background(), db.B().Ping().Build()).Error(); err != nil { panic(err) From 2fdcd6aba5f37e567619a4a6c2aba12eccb9ffda Mon Sep 17 00:00:00 2001 From: Juan Calderon-Perez <835733+gaby@users.noreply.github.com> Date: Mon, 13 Oct 2025 21:33:01 -0400 Subject: [PATCH 6/9] Handle rueidis startup check failures --- rueidis/README.md | 2 ++ rueidis/config.go | 2 ++ rueidis/rueidis.go | 19 ++++++++++++++++++- 3 files changed, 22 insertions(+), 1 deletion(-) diff --git a/rueidis/README.md b/rueidis/README.md index eef0d3489..e6067d509 100644 --- a/rueidis/README.md +++ b/rueidis/README.md @@ -185,6 +185,8 @@ type Config struct { Reset bool // DisableStartupCheck skips the initial connection validation during New. + // When true and client creation fails, New returns a Storage whose + // operations surface the initialization error instead of panicking. // // Optional. Default is false DisableStartupCheck bool diff --git a/rueidis/config.go b/rueidis/config.go index c67ec7c2f..c71937a9d 100644 --- a/rueidis/config.go +++ b/rueidis/config.go @@ -96,6 +96,8 @@ type Config struct { Reset bool // DisableStartupCheck skips the initial connection validation during New. + // When true and the client cannot be created, New returns a Storage whose + // operations will report the initialization error instead of panicking. // // Optional. Default is false DisableStartupCheck bool diff --git a/rueidis/rueidis.go b/rueidis/rueidis.go index 0c4a72e89..3a26665cb 100644 --- a/rueidis/rueidis.go +++ b/rueidis/rueidis.go @@ -11,7 +11,8 @@ var cacheTTL = time.Second // Storage interface that is implemented by storage providers type Storage struct { - db rueidis.Client + db rueidis.Client + initErr error } // New creates a new rueidis storage @@ -63,6 +64,10 @@ func New(config ...Config) *Storage { AlwaysPipelining: cfg.AlwaysPipelining, }) if err != nil { + if cfg.DisableStartupCheck { + return &Storage{initErr: err} + } + panic(err) } @@ -88,6 +93,9 @@ func New(config ...Config) *Storage { // GetWithContext gets value by key with context func (s *Storage) GetWithContext(ctx context.Context, key string) ([]byte, error) { + if s.db == nil { + return nil, s.initErr + } if len(key) <= 0 { return nil, nil } @@ -105,6 +113,9 @@ func (s *Storage) Get(key string) ([]byte, error) { // SetWithContext sets key with value with context func (s *Storage) SetWithContext(ctx context.Context, key string, val []byte, exp time.Duration) error { + if s.db == nil { + return s.initErr + } if len(key) <= 0 || len(val) <= 0 { return nil } @@ -122,6 +133,9 @@ func (s *Storage) Set(key string, val []byte, exp time.Duration) error { // DeleteWithContext deletes key by key with context func (s *Storage) DeleteWithContext(ctx context.Context, key string) error { + if s.db == nil { + return s.initErr + } if len(key) <= 0 { return nil } @@ -135,6 +149,9 @@ func (s *Storage) Delete(key string) error { // ResetWithContext resets all keys with context func (s *Storage) ResetWithContext(ctx context.Context) error { + if s.db == nil { + return s.initErr + } return s.db.Do(ctx, s.db.B().Flushdb().Build()).Error() } From 02a5e617ae01841b2e17a05f5f2af7ac0422f9e5 Mon Sep 17 00:00:00 2001 From: Juan Calderon-Perez <835733+gaby@users.noreply.github.com> Date: Mon, 13 Oct 2025 21:33:16 -0400 Subject: [PATCH 7/9] Fix Rueidis README indentation --- rueidis/README.md | 48 +++++++++++++++++++++++------------------------ 1 file changed, 24 insertions(+), 24 deletions(-) diff --git a/rueidis/README.md b/rueidis/README.md index e6067d509..500cc7609 100644 --- a/rueidis/README.md +++ b/rueidis/README.md @@ -98,8 +98,8 @@ store = rueidis.New(rueidis.Config{ ### Config ```go type Config struct { - // Server username - // + // Server username + // // Optional. Default is "" Username string @@ -167,17 +167,17 @@ type Config struct { // DisableRetry disables retrying read-only commands under network errors // // Optional. The default is False - DisableRetry bool + DisableRetry bool - // DisableCache falls back Client.DoCache/Client.DoMultiCache to Client.Do/Client.DoMulti - // - // Optional. The default is false - DisableCache bool + // DisableCache falls back Client.DoCache/Client.DoMultiCache to Client.Do/Client.DoMulti + // + // Optional. The default is false + DisableCache bool - // AlwaysPipelining makes rueidis.Client always pipeline redis commands even if they are not issued concurrently. - // - // Optional. The default is true - AlwaysPipelining bool + // AlwaysPipelining makes rueidis.Client always pipeline redis commands even if they are not issued concurrently. + // + // Optional. The default is true + AlwaysPipelining bool // Reset clears any existing keys in existing Collection // @@ -201,19 +201,19 @@ type Config struct { ### Default Config ```go var ConfigDefault = Config{ - Username: "", - Password: "", - ClientName: "", - SelectDB: 0, - InitAddress: []string{"127.0.0.1:6379"}, - TLSConfig: nil, - CacheSizeEachConn: rueidis.DefaultCacheBytes, - RingScaleEachConn: rueidis.DefaultRingScale, - ReadBufferEachConn: rueidis.DefaultReadBuffer, - WriteBufferEachConn: rueidis.DefaultWriteBuffer, - BlockingPoolSize: rueidis.DefaultPoolSize, - PipelineMultiplex: 2, - DisableRetry: false, + Username: "", + Password: "", + ClientName: "", + SelectDB: 0, + InitAddress: []string{"127.0.0.1:6379"}, + TLSConfig: nil, + CacheSizeEachConn: rueidis.DefaultCacheBytes, + RingScaleEachConn: rueidis.DefaultRingScale, + ReadBufferEachConn: rueidis.DefaultReadBuffer, + WriteBufferEachConn: rueidis.DefaultWriteBuffer, + BlockingPoolSize: rueidis.DefaultPoolSize, + PipelineMultiplex: 2, + DisableRetry: false, DisableCache: false, AlwaysPipelining: true, Reset: false, From 50d99b709c98c838b45f51f2bc75c1c5b628ef40 Mon Sep 17 00:00:00 2001 From: Juan Calderon-Perez <835733+gaby@users.noreply.github.com> Date: Mon, 13 Oct 2025 21:33:34 -0400 Subject: [PATCH 8/9] Align Rueidis README indentation --- rueidis/README.md | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/rueidis/README.md b/rueidis/README.md index 500cc7609..8859874a1 100644 --- a/rueidis/README.md +++ b/rueidis/README.md @@ -181,15 +181,15 @@ type Config struct { // Reset clears any existing keys in existing Collection // - // Optional. Default is false + // Optional. Default is false Reset bool - // DisableStartupCheck skips the initial connection validation during New. - // When true and client creation fails, New returns a Storage whose - // operations surface the initialization error instead of panicking. - // - // Optional. Default is false - DisableStartupCheck bool + // DisableStartupCheck skips the initial connection validation during New. + // When true and client creation fails, New returns a Storage whose + // operations surface the initialization error instead of panicking. + // + // Optional. Default is false + DisableStartupCheck bool // CacheTTL TTL // @@ -217,7 +217,7 @@ var ConfigDefault = Config{ DisableCache: false, AlwaysPipelining: true, Reset: false, - DisableStartupCheck: false, + DisableStartupCheck: false, CacheTTL: time.Minute, } ``` From 9951538c9e36dac1c02146dd0d781ed9a9a38dcc Mon Sep 17 00:00:00 2001 From: Juan Calderon-Perez <835733+gaby@users.noreply.github.com> Date: Mon, 13 Oct 2025 21:33:50 -0400 Subject: [PATCH 9/9] Normalize Rueidis README indentation --- rueidis/README.md | 70 +++++++++++++++++++++++------------------------ 1 file changed, 35 insertions(+), 35 deletions(-) diff --git a/rueidis/README.md b/rueidis/README.md index 8859874a1..d0d68ebca 100644 --- a/rueidis/README.md +++ b/rueidis/README.md @@ -98,8 +98,8 @@ store = rueidis.New(rueidis.Config{ ### Config ```go type Config struct { - // Server username - // + // Server username + // // Optional. Default is "" Username string @@ -167,22 +167,22 @@ type Config struct { // DisableRetry disables retrying read-only commands under network errors // // Optional. The default is False - DisableRetry bool + DisableRetry bool - // DisableCache falls back Client.DoCache/Client.DoMultiCache to Client.Do/Client.DoMulti - // - // Optional. The default is false - DisableCache bool + // DisableCache falls back Client.DoCache/Client.DoMultiCache to Client.Do/Client.DoMulti + // + // Optional. The default is false + DisableCache bool - // AlwaysPipelining makes rueidis.Client always pipeline redis commands even if they are not issued concurrently. - // - // Optional. The default is true - AlwaysPipelining bool + // AlwaysPipelining makes rueidis.Client always pipeline redis commands even if they are not issued concurrently. + // + // Optional. The default is true + AlwaysPipelining bool - // Reset clears any existing keys in existing Collection - // + // Reset clears any existing keys in existing Collection + // // Optional. Default is false - Reset bool + Reset bool // DisableStartupCheck skips the initial connection validation during New. // When true and client creation fails, New returns a Storage whose @@ -191,33 +191,33 @@ type Config struct { // Optional. Default is false DisableStartupCheck bool - // CacheTTL TTL - // - // Optional. Default is time.Minute - CacheTTL time.Duration + // CacheTTL TTL + // + // Optional. Default is time.Minute + CacheTTL time.Duration } ``` ### Default Config ```go var ConfigDefault = Config{ - Username: "", - Password: "", - ClientName: "", - SelectDB: 0, - InitAddress: []string{"127.0.0.1:6379"}, - TLSConfig: nil, - CacheSizeEachConn: rueidis.DefaultCacheBytes, - RingScaleEachConn: rueidis.DefaultRingScale, - ReadBufferEachConn: rueidis.DefaultReadBuffer, - WriteBufferEachConn: rueidis.DefaultWriteBuffer, - BlockingPoolSize: rueidis.DefaultPoolSize, - PipelineMultiplex: 2, - DisableRetry: false, - DisableCache: false, - AlwaysPipelining: true, - Reset: false, + Username: "", + Password: "", + ClientName: "", + SelectDB: 0, + InitAddress: []string{"127.0.0.1:6379"}, + TLSConfig: nil, + CacheSizeEachConn: rueidis.DefaultCacheBytes, + RingScaleEachConn: rueidis.DefaultRingScale, + ReadBufferEachConn: rueidis.DefaultReadBuffer, + WriteBufferEachConn: rueidis.DefaultWriteBuffer, + BlockingPoolSize: rueidis.DefaultPoolSize, + PipelineMultiplex: 2, + DisableRetry: false, + DisableCache: false, + AlwaysPipelining: true, + Reset: false, DisableStartupCheck: false, - CacheTTL: time.Minute, + CacheTTL: time.Minute, } ```