mirror of
https://github.com/simon987/feed_archiver.git
synced 2025-04-19 18:36:47 +00:00
cache KEYS command
This commit is contained in:
parent
dd990706c3
commit
df2ce33234
25
main.go
25
main.go
@ -203,17 +203,29 @@ func createTable(table string, idType fastjson.Type) {
|
|||||||
archiverCtx.tables[table] = true
|
archiverCtx.tables[table] = true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var keyCache []string = nil
|
||||||
|
|
||||||
|
func getKeys(ctx context.Context, rdb *redis.Client, pattern string) []string {
|
||||||
|
|
||||||
|
if keyCache == nil {
|
||||||
|
keys, err := rdb.Keys(ctx, pattern).Result()
|
||||||
|
if err != nil {
|
||||||
|
logrus.WithField("Pattern", pattern).Error("Could not get keys for Pattern")
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
keyCache = keys
|
||||||
|
}
|
||||||
|
|
||||||
|
return keyCache
|
||||||
|
}
|
||||||
|
|
||||||
func dispatchFromQueue(rdb *redis.Client, pattern string, consume func(message string, key string) error) error {
|
func dispatchFromQueue(rdb *redis.Client, pattern string, consume func(message string, key string) error) error {
|
||||||
|
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
|
|
||||||
for {
|
for {
|
||||||
keys, err := rdb.Keys(ctx, pattern).Result()
|
keys := getKeys(ctx, rdb, pattern)
|
||||||
if err != nil {
|
|
||||||
logrus.WithField("Pattern", pattern).Error("Could not get keys for Pattern")
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
if len(keys) == 0 {
|
if len(keys) == 0 {
|
||||||
time.Sleep(time.Second * 1)
|
time.Sleep(time.Second * 1)
|
||||||
continue
|
continue
|
||||||
@ -221,6 +233,7 @@ func dispatchFromQueue(rdb *redis.Client, pattern string, consume func(message s
|
|||||||
|
|
||||||
rawTask, err := rdb.BLPop(ctx, time.Second*30, keys...).Result()
|
rawTask, err := rdb.BLPop(ctx, time.Second*30, keys...).Result()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
keyCache = nil
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user