-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathslist.go
42 lines (31 loc) · 947 Bytes
/
slist.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
package api
func (dc *DiskCache) SAdd(cacheKey string, cacheValue string) error {
tx := dc.Tx()
defer tx.Commit()
keyID, _ := GetKeyIDByCU(tx, cacheKey)
vauleMd5 := GetMd5String(cacheValue)
// 插入并更新内容
var vauleID int
err := tx.QueryRow("SELECT id FROM cache_value where key_id = ? and value_md5 = ?", keyID, vauleMd5).Scan(&vauleID)
if err == nil {
_, err := tx.Exec("UPDATE cache_value SET value = ? , value_md5 =? WHERE id = ?",
cacheValue, vauleMd5, vauleID)
if err != nil {
tx.Rollback()
return err
}
} else {
_, err := tx.Exec("INSERT INTO cache_value(key_id,value,value_md5) VALUES(?,?, ?)", keyID, cacheValue, vauleMd5)
if err != nil {
tx.Rollback()
return err
}
}
return nil
}
func (dc *DiskCache) SPop(cacheKey string) (string, error) {
return dc.LPop(cacheKey)
}
func (dc *DiskCache) SRem(cacheKey string, cacheValue string) error {
return dc.LRem(cacheKey, cacheValue)
}