remove close method

This commit is contained in:
Fenny
2020-11-05 06:08:05 +01:00
parent 5571999805
commit 86b9cfe4c1
7 changed files with 3 additions and 37 deletions

View File

@@ -76,7 +76,7 @@ func New(config ...Config) *Storage {
gcInterval: cfg.GCInterval,
db: db,
sqlSelect: fmt.Sprintf("SELECT data, exp FROM %s WHERE id=?;", cfg.Table),
sqlInsert: fmt.Sprintf("INSERT INTO %s (id, data, exp) VALUES (?,?,?)", cfg.Table),
sqlInsert: fmt.Sprintf("INSERT INTO %s (id, data, exp) VALUES (?,?,?) ON DUPLICATE KEY UPDATE data = ?, exp = ?", cfg.Table),
sqlDelete: fmt.Sprintf("DELETE FROM %s WHERE id=?", cfg.Table),
sqlClear: fmt.Sprintf("DELETE FROM %s;", cfg.Table),
sqlGC: fmt.Sprintf("DELETE FROM %s WHERE exp <= ?", cfg.Table),
@@ -126,7 +126,8 @@ func (s *Storage) Set(key string, val []byte, exp time.Duration) error {
if exp != 0 {
expSeconds = time.Now().Add(exp).Unix()
}
_, err := s.db.Exec(s.sqlInsert, key, utils.UnsafeString(val), expSeconds)
valStr := utils.UnsafeString(val)
_, err := s.db.Exec(s.sqlInsert, key, valStr, expSeconds, valStr, expSeconds)
return err
}
@@ -142,11 +143,6 @@ func (s *Storage) Clear() error {
return err
}
// Close the storage
func (s *Storage) Close() error {
return s.db.Close()
}
// Garbage collector to delete expired keys
func (s *Storage) gc() {
tick := time.NewTicker(s.gcInterval)