Skip to content

Commit f8c6979

Browse files
authored
breaking-change(redis): deprecated expire option (#66)
1 parent 3c58fdc commit f8c6979

File tree

3 files changed

+3
-39
lines changed

3 files changed

+3
-39
lines changed

README.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,7 @@ Available Commands:
5656
githubrepos Fetch the data of github repos
5757

5858
Flags:
59-
--batch-size int The number of batch size to insert. NOTE: This Option does not work for dbtype: redis. (default 500)
60-
--expire uint timeout to set for Redis keys in seconds. If set to 0, the key is persistent.
59+
--batch-size int The number of batch size to insert. (default 500)
6160
-h, --help help for fetch
6261

6362
Global Flags:

commands/fetch.go

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,6 @@ var fetchCmd = &cobra.Command{
1515
func init() {
1616
RootCmd.AddCommand(fetchCmd)
1717

18-
fetchCmd.PersistentFlags().Uint("expire", 0, "timeout to set for Redis keys in seconds. If set to 0, the key is persistent.")
19-
_ = viper.BindPFlag("expire", fetchCmd.PersistentFlags().Lookup("expire"))
20-
2118
fetchCmd.PersistentFlags().Int("batch-size", 500, "The number of batch size to insert.")
2219
_ = viper.BindPFlag("batch-size", fetchCmd.PersistentFlags().Lookup("batch-size"))
2320
}

db/redis.go

Lines changed: 2 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import (
66
"errors"
77
"fmt"
88
"strconv"
9-
"time"
109

1110
"github.com/cheggaaa/pb/v3"
1211
"github.com/go-redis/redis/v8"
@@ -299,7 +298,6 @@ func (r *RedisDriver) GetExploitMultiByCveID(cveIDs []string) (map[string][]mode
299298
//InsertExploit :
300299
func (r *RedisDriver) InsertExploit(exploitType models.ExploitType, exploits []models.Exploit) (err error) {
301300
ctx := context.Background()
302-
expire := viper.GetUint("expire")
303301
batchSize := viper.GetInt("batch-size")
304302
if batchSize < 1 {
305303
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
329327
return xerrors.Errorf("Failed to marshal json. err: %w", err)
330328
}
331329

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 {
334331
return xerrors.Errorf("Failed to HSet Exploit. err: %w", err)
335332
}
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-
346333
if _, ok := newDeps[exploit.ExploitUniqueID]; !ok {
347334
newDeps[exploit.ExploitUniqueID] = map[string]struct{}{}
348335
}
349336

350337
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 {
353339
return xerrors.Errorf("Failed to SAdd CVE. err: %w", err)
354340
}
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-
}
364341
cveIDExploitCount++
365342
} else {
366343
noCveIDExploitCount++
@@ -401,15 +378,6 @@ func (r *RedisDriver) InsertExploit(exploitType models.ExploitType, exploits []m
401378
if err := pipe.HSet(ctx, depKey, string(exploitType), string(newDepsJSON)).Err(); err != nil {
402379
return xerrors.Errorf("Failed to Set depkey. err: %w", err)
403380
}
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-
}
413381
if _, err = pipe.Exec(ctx); err != nil {
414382
return xerrors.Errorf("Failed to exec pipeline. err: %w", err)
415383
}

0 commit comments

Comments
 (0)