Fix rueidis startup check handling and revert mysql changes

This commit is contained in:
Juan Calderon-Perez
2025-10-13 18:33:06 -04:00
parent 75a86506f7
commit c285284184
6 changed files with 94 additions and 122 deletions

View File

@@ -127,11 +127,6 @@ type Config struct {
// Optional. Default is false // Optional. Default is false
Reset bool Reset bool
// DisableStartupCheck skips the initial connection validation during New.
//
// Optional. Default is false
DisableStartupCheck bool
// Time before deleting expired keys // Time before deleting expired keys
// //
// Optional. Default is 10 * time.Second // Optional. Default is 10 * time.Second
@@ -148,7 +143,6 @@ var ConfigDefault = Config{
Database: "fiber", Database: "fiber",
Table: "fiber_storage", Table: "fiber_storage",
Reset: false, Reset: false,
DisableStartupCheck: false,
GCInterval: 10 * time.Second, GCInterval: 10 * time.Second,
} }
``` ```

View File

@@ -53,11 +53,6 @@ type Config struct {
// Optional. Default is false // Optional. Default is false
Reset bool Reset bool
// DisableStartupCheck skips the initial connection validation during New.
//
// Optional. Default is false
DisableStartupCheck bool
// Time before deleting expired keys // Time before deleting expired keys
// //
// Optional. Default is 10 * time.Second // Optional. Default is 10 * time.Second
@@ -74,18 +69,17 @@ type Config struct {
// ConfigDefault is the default config // ConfigDefault is the default config
var ConfigDefault = Config{ var ConfigDefault = Config{
Db: nil, Db: nil,
ConnectionURI: "", ConnectionURI: "",
Host: "127.0.0.1", Host: "127.0.0.1",
Port: 3306, Port: 3306,
Database: "fiber", Database: "fiber",
Table: "fiber_storage", Table: "fiber_storage",
Reset: false, Reset: false,
DisableStartupCheck: false, GCInterval: 10 * time.Second,
GCInterval: 10 * time.Second, maxOpenConns: 100,
maxOpenConns: 100, maxIdleConns: 100,
maxIdleConns: 100, connMaxLifetime: 1 * time.Second,
connMaxLifetime: 1 * time.Second,
} }
func (c Config) dsn() string { func (c Config) dsn() string {

View File

@@ -63,28 +63,26 @@ func New(config ...Config) *Storage {
db.SetConnMaxLifetime(cfg.connMaxLifetime) db.SetConnMaxLifetime(cfg.connMaxLifetime)
} }
if !cfg.DisableStartupCheck { // Ping database to ensure a connection has been made
// Ping database to ensure a connection has been made if err := db.Ping(); err != nil {
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) panic(err)
} }
}
// Drop table if Clear set to true // Init database queries
if cfg.Reset { for _, query := range initQuery {
query := fmt.Sprintf(dropQuery, cfg.Table) query = fmt.Sprintf(query, cfg.Table)
if _, err = db.Exec(query); err != nil { if _, err := db.Exec(query); err != nil {
_ = db.Close() _ = db.Close()
panic(err) 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), 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 // Start garbage collector
go store.gcTicker() go store.gcTicker()

View File

@@ -108,18 +108,6 @@ func Test_MYSQL_New(t *testing.T) {
defer newConfigStore.Close() 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) { func Test_MYSQL_GC(t *testing.T) {
testVal := []byte("doe") testVal := []byte("doe")

View File

@@ -56,10 +56,10 @@ store := postgres.New()
// Initialize custom config // Initialize custom config
store := postgres.New(postgres.Config{ store := postgres.New(postgres.Config{
DB: dbPool, DB: dbPool,
Table: "fiber_storage", Table: "fiber_storage",
Reset: false, Reset: false,
GCInterval: 10 * time.Second, GCInterval: 10 * time.Second,
}) })
``` ```
@@ -67,65 +67,65 @@ store := postgres.New(postgres.Config{
```go ```go
// Config defines the config for storage. // Config defines the config for storage.
type Config struct { type Config struct {
// DB pgxpool.Pool object will override connection uri and other connection fields // DB pgxpool.Pool object will override connection uri and other connection fields
// //
// Optional. Default is nil // Optional. Default is nil
DB *pgxpool.Pool DB *pgxpool.Pool
// Connection string to use for DB. Will override all other authentication values if used // Connection string to use for DB. Will override all other authentication values if used
// //
// Optional. Default is "" // Optional. Default is ""
ConnectionURI string ConnectionURI string
// Host name where the DB is hosted // Host name where the DB is hosted
// //
// Optional. Default is "127.0.0.1" // Optional. Default is "127.0.0.1"
Host string Host string
// Port where the DB is listening on // Port where the DB is listening on
// //
// Optional. Default is 5432 // Optional. Default is 5432
Port int Port int
// Server username // Server username
// //
// Optional. Default is "" // Optional. Default is ""
Username string Username string
// Server password // Server password
// //
// Optional. Default is "" // Optional. Default is ""
Password string Password string
// Database name // Database name
// //
// Optional. Default is "fiber" // Optional. Default is "fiber"
Database string Database string
// Table name // Table name
// //
// Optional. Default is "fiber_storage" // Optional. Default is "fiber_storage"
Table string Table string
// The SSL mode for the connection // The SSL mode for the connection
// //
// Optional. Default is "disable" // Optional. Default is "disable"
SSLMode string SSLMode string
// Reset clears any existing keys in existing Table // Reset clears any existing keys in existing Table
// //
// Optional. Default is false // Optional. Default is false
Reset bool Reset bool
// DisableStartupCheck skips the initial connection validation during New. // DisableStartupCheck skips the initial connection validation during New.
// //
// Optional. Default is false // Optional. Default is false
DisableStartupCheck bool DisableStartupCheck bool
// Time before deleting expired keys // Time before deleting expired keys
// //
// Optional. Default is 10 * time.Second // Optional. Default is 10 * time.Second
GCInterval time.Duration GCInterval time.Duration
} }
``` ```
@@ -133,14 +133,14 @@ type Config struct {
```go ```go
// ConfigDefault is the default config // ConfigDefault is the default config
var ConfigDefault = Config{ var ConfigDefault = Config{
ConnectionURI: "", ConnectionURI: "",
Host: "127.0.0.1", Host: "127.0.0.1",
Port: 5432, Port: 5432,
Database: "fiber", Database: "fiber",
Table: "fiber_storage", Table: "fiber_storage",
SSLMode: "disable", SSLMode: "disable",
Reset: false, Reset: false,
DisableStartupCheck: false, DisableStartupCheck: false,
GCInterval: 10 * time.Second, GCInterval: 10 * time.Second,
} }
``` ```

View File

@@ -63,10 +63,10 @@ func New(config ...Config) *Storage {
AlwaysPipelining: cfg.AlwaysPipelining, AlwaysPipelining: cfg.AlwaysPipelining,
}) })
if err != nil { if err != nil {
if !cfg.DisableStartupCheck { panic(err)
panic(err) }
}
} else if !cfg.DisableStartupCheck { if !cfg.DisableStartupCheck {
// Test connection // Test connection
if err := db.Do(context.Background(), db.B().Ping().Build()).Error(); err != nil { if err := db.Do(context.Background(), db.B().Ping().Build()).Error(); err != nil {
panic(err) panic(err)