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] 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 | 122 ++++++++++++++++++++++---------------------- rueidis/rueidis.go | 8 +-- 6 files changed, 94 insertions(+), 122 deletions(-) diff --git a/mysql/README.md b/mysql/README.md index 06da231d..4c9bcdd6 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 7ae38af9..d16349de 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 f1db737c..ae0bfcd2 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 { + // 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 14364620..19ee758d 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 11ccd6f0..068a5d3b 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 + // 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 + // 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 + // 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 + // Port where the DB is listening on + // + // Optional. Default is 5432 + Port int - // Server username - // - // Optional. Default is "" - Username string + // Server username + // + // Optional. Default is "" + Username string - // Server password - // - // Optional. Default is "" - Password string + // Server password + // + // Optional. Default is "" + Password string - // Database name - // - // Optional. Default is "fiber" - Database string + // Database name + // + // Optional. Default is "fiber" + Database string - // Table name - // - // Optional. Default is "fiber_storage" - Table string + // Table name + // + // Optional. Default is "fiber_storage" + Table string - // The SSL mode for the connection - // - // Optional. Default is "disable" - SSLMode 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 + // 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 + // 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 + // 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 3396ac2a..0c4a72e8 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)