|
6 | 6 | "errors"
|
7 | 7 | "fmt"
|
8 | 8 | "strconv"
|
9 |
| - "time" |
10 | 9 |
|
11 | 10 | "github.com/cheggaaa/pb/v3"
|
12 | 11 | "github.com/go-redis/redis/v8"
|
@@ -299,7 +298,6 @@ func (r *RedisDriver) GetExploitMultiByCveID(cveIDs []string) (map[string][]mode
|
299 | 298 | //InsertExploit :
|
300 | 299 | func (r *RedisDriver) InsertExploit(exploitType models.ExploitType, exploits []models.Exploit) (err error) {
|
301 | 300 | ctx := context.Background()
|
302 |
| - expire := viper.GetUint("expire") |
303 | 301 | batchSize := viper.GetInt("batch-size")
|
304 | 302 | if batchSize < 1 {
|
305 | 303 | return xerrors.Errorf("Failed to set batch-size. err: batch-size option is not set properly")
|
@@ -329,38 +327,17 @@ func (r *RedisDriver) InsertExploit(exploitType models.ExploitType, exploits []m
|
329 | 327 | return xerrors.Errorf("Failed to marshal json. err: %w", err)
|
330 | 328 | }
|
331 | 329 |
|
332 |
| - exploitDBIDKey := fmt.Sprintf(exploitDBIDKeyFormat, exploit.ExploitUniqueID) |
333 |
| - if err := pipe.HSet(ctx, exploitDBIDKey, exploit.CveID, string(j)).Err(); err != nil { |
| 330 | + if err := pipe.HSet(ctx, fmt.Sprintf(exploitDBIDKeyFormat, exploit.ExploitUniqueID), exploit.CveID, string(j)).Err(); err != nil { |
334 | 331 | return xerrors.Errorf("Failed to HSet Exploit. err: %w", err)
|
335 | 332 | }
|
336 |
| - if expire > 0 { |
337 |
| - if err := pipe.Expire(ctx, exploitDBIDKey, time.Duration(expire*uint(time.Second))).Err(); err != nil { |
338 |
| - return xerrors.Errorf("Failed to set Expire to Key. err: %w", err) |
339 |
| - } |
340 |
| - } else { |
341 |
| - if err := pipe.Persist(ctx, exploitDBIDKey).Err(); err != nil { |
342 |
| - return xerrors.Errorf("Failed to remove the existing timeout on Key. err: %w", err) |
343 |
| - } |
344 |
| - } |
345 |
| - |
346 | 333 | if _, ok := newDeps[exploit.ExploitUniqueID]; !ok {
|
347 | 334 | newDeps[exploit.ExploitUniqueID] = map[string]struct{}{}
|
348 | 335 | }
|
349 | 336 |
|
350 | 337 | if exploit.CveID != "" {
|
351 |
| - cveKey := fmt.Sprintf(cveIDKeyFormat, exploit.CveID) |
352 |
| - if err := pipe.SAdd(ctx, cveKey, exploit.ExploitUniqueID).Err(); err != nil { |
| 338 | + if err := pipe.SAdd(ctx, fmt.Sprintf(cveIDKeyFormat, exploit.CveID), exploit.ExploitUniqueID).Err(); err != nil { |
353 | 339 | return xerrors.Errorf("Failed to SAdd CVE. err: %w", err)
|
354 | 340 | }
|
355 |
| - if expire > 0 { |
356 |
| - if err := pipe.Expire(ctx, cveKey, time.Duration(expire*uint(time.Second))).Err(); err != nil { |
357 |
| - return xerrors.Errorf("Failed to set Expire to Key. err: %w", err) |
358 |
| - } |
359 |
| - } else { |
360 |
| - if err := pipe.Persist(ctx, cveKey).Err(); err != nil { |
361 |
| - return xerrors.Errorf("Failed to remove the existing timeout on Key. err: %w", err) |
362 |
| - } |
363 |
| - } |
364 | 341 | cveIDExploitCount++
|
365 | 342 | } else {
|
366 | 343 | noCveIDExploitCount++
|
@@ -401,15 +378,6 @@ func (r *RedisDriver) InsertExploit(exploitType models.ExploitType, exploits []m
|
401 | 378 | if err := pipe.HSet(ctx, depKey, string(exploitType), string(newDepsJSON)).Err(); err != nil {
|
402 | 379 | return xerrors.Errorf("Failed to Set depkey. err: %w", err)
|
403 | 380 | }
|
404 |
| - if expire > 0 { |
405 |
| - if err := pipe.Expire(ctx, depKey, time.Duration(expire*uint(time.Second))).Err(); err != nil { |
406 |
| - return xerrors.Errorf("Failed to set Expire to Key. err: %w", err) |
407 |
| - } |
408 |
| - } else { |
409 |
| - if err := pipe.Persist(ctx, depKey).Err(); err != nil { |
410 |
| - return xerrors.Errorf("Failed to remove the existing timeout on Key. err: %w", err) |
411 |
| - } |
412 |
| - } |
413 | 381 | if _, err = pipe.Exec(ctx); err != nil {
|
414 | 382 | return xerrors.Errorf("Failed to exec pipeline. err: %w", err)
|
415 | 383 | }
|
|
0 commit comments