Skip to content
This repository was archived by the owner on Jun 21, 2019. It is now read-only.

delObjects method use scan to replace keys #8

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 24 additions & 7 deletions redis_cacher.go
Original file line number Diff line number Diff line change
Expand Up @@ -182,15 +182,32 @@ func (c *RedisCacher) delObjects(key string) error {
conn := c.pool.Get()
defer conn.Close()

keys, err := conn.Do("KEYS", key)
c.logDebugf("delObjects keys: %v", keys)

if err == nil {
for _, key := range keys.([]interface{}) {
conn.Do("DEL", key)
cursor := 0
args := []interface{}{cursor, "MATCH", key, "COUNT", 5000}
for cursor != -1 {
args[0] = cursor
replys, err := conn.Do("SCAN", args...)
if err != nil {
return err
}
if err == nil {
for index, reply := range replys.([]interface{}) {
if index == 0 {
cursor, _ = redis.Int(reply, nil)
if cursor == 0 {
cursor = -1
}
} else {
keys, _ := redis.Values(reply, nil)
if len(keys) > 0 {
c.logDebugf("delObjects keys: %s", keys)
conn.Do("DEL", keys...)
}
}
}
}
}
return err
return nil
}

func (c *RedisCacher) DelIds(tableName, sql string) {
Expand Down