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

@@ -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