diff --git a/.github/workflows/test-mongodb.yml b/.github/workflows/test-mongodb.yml index 4ac6d329..e66620dd 100644 --- a/.github/workflows/test-mongodb.yml +++ b/.github/workflows/test-mongodb.yml @@ -11,6 +11,7 @@ jobs: strategy: matrix: go-version: [1.14.x, 1.15.x] + platform: [ubuntu-latest, windows-latest] steps: - name: Install Go uses: actions/setup-go@v1 diff --git a/.github/workflows/test-mysql.yml b/.github/workflows/test-mysql.yml index 496388b1..2613b825 100644 --- a/.github/workflows/test-mysql.yml +++ b/.github/workflows/test-mysql.yml @@ -21,6 +21,7 @@ jobs: strategy: matrix: go-version: [1.14.x, 1.15.x] + platform: [ubuntu-latest, windows-latest] steps: - name: Install Go uses: actions/setup-go@v1 diff --git a/.github/workflows/test-redis.yml b/.github/workflows/test-redis.yml index bfd63a34..c25fe345 100644 --- a/.github/workflows/test-redis.yml +++ b/.github/workflows/test-redis.yml @@ -11,6 +11,7 @@ jobs: strategy: matrix: go-version: [1.14.x, 1.15.x] + platform: [ubuntu-latest, windows-latest] steps: - name: Install Go uses: actions/setup-go@v1 diff --git a/mysql/mysql.go b/mysql/mysql.go index 7e553ab9..45ea29d1 100644 --- a/mysql/mysql.go +++ b/mysql/mysql.go @@ -75,7 +75,7 @@ func New(config ...Config) *Storage { store := &Storage{ gcInterval: cfg.GCInterval, db: db, - sqlSelect: fmt.Sprintf(`SELECT data, exp FROM %s WHERE id=?;`, cfg.Table), + sqlSelect: fmt.Sprintf("SELECT data, exp FROM %s WHERE id=?;", cfg.Table), sqlInsert: fmt.Sprintf("INSERT OR REPLACE INTO %s (id, data, exp) VALUES (?,?,?)", cfg.Table), sqlDelete: fmt.Sprintf("DELETE FROM %s WHERE id=?", cfg.Table), sqlClear: fmt.Sprintf("DELETE FROM %s;", cfg.Table), @@ -102,10 +102,10 @@ func (s *Storage) Get(key string) ([]byte, error) { ) if err := row.Scan(&data, &exp); err != nil { - if err.Error() != noRows { - return nil, err + if err == sql.ErrNoRows { + return nil, ErrNotExist } - return nil, nil + return nil, err } // If the expiration time has already passed, then return nil diff --git a/postgres/postgres.go b/postgres/postgres.go index 369f12b4..64b00368 100644 --- a/postgres/postgres.go +++ b/postgres/postgres.go @@ -99,7 +99,7 @@ func New(config ...Config) *Storage { db: db, gcInterval: cfg.GCInterval, sqlSelect: fmt.Sprintf(`SELECT data, exp FROM %s WHERE key=$1;`, cfg.Table), - sqlInsert: fmt.Sprintf("INSERT OR REPLACE INTO %s (key, data, exp) VALUES ($1, $2, $3)", cfg.Table), + sqlInsert: fmt.Sprintf(`INSERT INTO %s (key, data, exp) VALUES ($1, $2, $3) ON DUPLICATE KEY UPDATE data="$1", exp=$3`, cfg.Table), sqlDelete: fmt.Sprintf("DELETE FROM %s WHERE key=$1", cfg.Table), sqlClear: fmt.Sprintf("DELETE FROM %s;", cfg.Table), sqlGC: fmt.Sprintf("DELETE FROM %s WHERE exp <= $1", cfg.Table), @@ -122,10 +122,10 @@ func (s *Storage) Get(key string) ([]byte, error) { exp int64 = 0 ) if err := row.Scan(&data, &exp); err != nil { - if err != noRows { - return nil, err + if err == sql.ErrNoRows { + return nil, ErrNotExist } - return nil, nil + return nil, err } // If the expiration time has already passed, then return nil