This commit is contained in:
Fenny
2020-11-05 05:44:12 +01:00
parent b26c0e0c71
commit 53f5b272a1
5 changed files with 11 additions and 8 deletions

View File

@@ -11,6 +11,7 @@ jobs:
strategy: strategy:
matrix: matrix:
go-version: [1.14.x, 1.15.x] go-version: [1.14.x, 1.15.x]
platform: [ubuntu-latest, windows-latest]
steps: steps:
- name: Install Go - name: Install Go
uses: actions/setup-go@v1 uses: actions/setup-go@v1

View File

@@ -21,6 +21,7 @@ jobs:
strategy: strategy:
matrix: matrix:
go-version: [1.14.x, 1.15.x] go-version: [1.14.x, 1.15.x]
platform: [ubuntu-latest, windows-latest]
steps: steps:
- name: Install Go - name: Install Go
uses: actions/setup-go@v1 uses: actions/setup-go@v1

View File

@@ -11,6 +11,7 @@ jobs:
strategy: strategy:
matrix: matrix:
go-version: [1.14.x, 1.15.x] go-version: [1.14.x, 1.15.x]
platform: [ubuntu-latest, windows-latest]
steps: steps:
- name: Install Go - name: Install Go
uses: actions/setup-go@v1 uses: actions/setup-go@v1

View File

@@ -75,7 +75,7 @@ func New(config ...Config) *Storage {
store := &Storage{ store := &Storage{
gcInterval: cfg.GCInterval, gcInterval: cfg.GCInterval,
db: db, 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), sqlInsert: fmt.Sprintf("INSERT OR REPLACE INTO %s (id, data, exp) VALUES (?,?,?)", cfg.Table),
sqlDelete: fmt.Sprintf("DELETE FROM %s WHERE id=?", cfg.Table), sqlDelete: fmt.Sprintf("DELETE FROM %s WHERE id=?", cfg.Table),
sqlClear: fmt.Sprintf("DELETE FROM %s;", 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 := row.Scan(&data, &exp); err != nil {
if err.Error() != noRows { if err == sql.ErrNoRows {
return nil, err return nil, ErrNotExist
} }
return nil, nil return nil, err
} }
// If the expiration time has already passed, then return nil // If the expiration time has already passed, then return nil

View File

@@ -99,7 +99,7 @@ func New(config ...Config) *Storage {
db: db, db: db,
gcInterval: cfg.GCInterval, gcInterval: cfg.GCInterval,
sqlSelect: fmt.Sprintf(`SELECT data, exp FROM %s WHERE key=$1;`, cfg.Table), 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), sqlDelete: fmt.Sprintf("DELETE FROM %s WHERE key=$1", cfg.Table),
sqlClear: fmt.Sprintf("DELETE FROM %s;", cfg.Table), sqlClear: fmt.Sprintf("DELETE FROM %s;", cfg.Table),
sqlGC: fmt.Sprintf("DELETE FROM %s WHERE exp <= $1", 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 exp int64 = 0
) )
if err := row.Scan(&data, &exp); err != nil { if err := row.Scan(&data, &exp); err != nil {
if err != noRows { if err == sql.ErrNoRows {
return nil, err return nil, ErrNotExist
} }
return nil, nil return nil, err
} }
// If the expiration time has already passed, then return nil // If the expiration time has already passed, then return nil