feat: add replay protection plugin (#1672)

Co-authored-by: hanxiantao <601803023@qq.com>
This commit is contained in:
yunmaoQu
2025-03-10 15:11:13 +08:00
committed by GitHub
parent 5536502c15
commit f45bc9008a
11 changed files with 702 additions and 0 deletions

View File

@@ -44,6 +44,7 @@ type RedisClient interface {
Get(key string, callback RedisResponseCallback) error
Set(key string, value interface{}, callback RedisResponseCallback) error
SetEx(key string, value interface{}, ttl int, callback RedisResponseCallback) error
SetNX(key string, value interface{}, ttl int, callback RedisResponseCallback) error
MGet(keys []string, callback RedisResponseCallback) error
MSet(kvMap map[string]interface{}, callback RedisResponseCallback) error
Incr(key string, callback RedisResponseCallback) error
@@ -308,6 +309,22 @@ func (c *RedisClusterClient[C]) SetEx(key string, value interface{}, ttl int, ca
return RedisCall(c.cluster, respString(args), callback)
}
func (c *RedisClusterClient[C]) SetNX(key string, value interface{}, ttl int, callback RedisResponseCallback) error {
if err := c.checkReadyFunc(); err != nil {
return err
}
args := make([]interface{}, 0)
args = append(args, "set")
args = append(args, key)
args = append(args, value)
args = append(args, "nx")
if ttl > 0 {
args = append(args, "ex")
args = append(args, ttl)
}
return RedisCall(c.cluster, respString(args), callback)
}
func (c *RedisClusterClient[C]) MGet(keys []string, callback RedisResponseCallback) error {
if err := c.checkReadyFunc(); err != nil {
return err