Skip to content

Commit

Permalink
fix(redis): pipe cannot take err except for pipe.Exec (#68)
Browse files Browse the repository at this point in the history
  • Loading branch information
MaineK00n authored Jan 6, 2022
1 parent ae0f310 commit dfbfaf4
Showing 1 changed file with 5 additions and 15 deletions.
20 changes: 5 additions & 15 deletions db/redis.go
Original file line number Diff line number Diff line change
Expand Up @@ -330,17 +330,13 @@ func (r *RedisDriver) InsertExploit(exploitType models.ExploitType, exploits []m
return xerrors.Errorf("Failed to marshal json. err: %w", err)
}

if err := pipe.HSet(ctx, fmt.Sprintf(exploitDBIDKeyFormat, exploit.ExploitUniqueID), exploit.CveID, string(j)).Err(); err != nil {
return xerrors.Errorf("Failed to HSet Exploit. err: %w", err)
}
_ = pipe.HSet(ctx, fmt.Sprintf(exploitDBIDKeyFormat, exploit.ExploitUniqueID), exploit.CveID, string(j))
if _, ok := newDeps[exploit.ExploitUniqueID]; !ok {
newDeps[exploit.ExploitUniqueID] = map[string]struct{}{}
}

if exploit.CveID != "" {
if err := pipe.SAdd(ctx, fmt.Sprintf(cveIDKeyFormat, exploit.CveID), exploit.ExploitUniqueID).Err(); err != nil {
return xerrors.Errorf("Failed to SAdd CVE. err: %w", err)
}
_ = pipe.SAdd(ctx, fmt.Sprintf(cveIDKeyFormat, exploit.CveID), exploit.ExploitUniqueID)
cveIDExploitCount++
} else {
noCveIDExploitCount++
Expand All @@ -365,22 +361,16 @@ func (r *RedisDriver) InsertExploit(exploitType models.ExploitType, exploits []m
for eid, cves := range oldDeps {
for cveid := range cves {
if cveid != "" {
if err := pipe.SRem(ctx, fmt.Sprintf(cveIDKeyFormat, cveid), eid).Err(); err != nil {
return xerrors.Errorf("Failed to SRem. err: %w", err)
}
}
if err := pipe.HDel(ctx, fmt.Sprintf(exploitDBIDKeyFormat, eid), cveid).Err(); err != nil {
return xerrors.Errorf("Failed to HDel. err: %w", err)
_ = pipe.SRem(ctx, fmt.Sprintf(cveIDKeyFormat, cveid), eid)
}
_ = pipe.HDel(ctx, fmt.Sprintf(exploitDBIDKeyFormat, eid), cveid)
}
}
newDepsJSON, err := json.Marshal(newDeps)
if err != nil {
return xerrors.Errorf("Failed to Marshal JSON. err: %w", err)
}
if err := pipe.HSet(ctx, depKey, string(exploitType), string(newDepsJSON)).Err(); err != nil {
return xerrors.Errorf("Failed to Set depkey. err: %w", err)
}
_ = pipe.HSet(ctx, depKey, string(exploitType), string(newDepsJSON))
if _, err = pipe.Exec(ctx); err != nil {
return xerrors.Errorf("Failed to exec pipeline. err: %w", err)
}
Expand Down

0 comments on commit dfbfaf4

Please sign in to comment.