Skip to content

Commit ff6739e

Browse files
committed
Del script for Reset functionality just removed and Del function used instead
1 parent 5cab8eb commit ff6739e

File tree

2 files changed

+2
-17
lines changed

2 files changed

+2
-17
lines changed

lua.go

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -130,15 +130,3 @@ return {
130130
tostring(reset_after),
131131
}
132132
`)
133-
134-
var reset = redis.NewScript(`
135-
-- this script has side-effects, so it requires replicate commands mode
136-
redis.replicate_commands()
137-
138-
local rate_limit_key = KEYS[1]
139-
local tat = redis.call("DEL", rate_limit_key)
140-
141-
return {
142-
tat,
143-
}
144-
`)

rate.go

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ type rediser interface {
1616
EvalSha(ctx context.Context, sha1 string, keys []string, args ...interface{}) *redis.Cmd
1717
ScriptExists(ctx context.Context, hashes ...string) *redis.BoolSliceCmd
1818
ScriptLoad(ctx context.Context, script string) *redis.StringCmd
19+
Del(ctx context.Context, keys ...string) *redis.IntCmd
1920
}
2021

2122
type Limit struct {
@@ -160,11 +161,7 @@ func (l Limiter) AllowAtMost(
160161

161162
// Reset gets a key and reset all limitations and previous usages
162163
func (l *Limiter) Reset(ctx context.Context, key string) error {
163-
_, err := reset.Run(ctx, l.rdb, []string{redisPrefix + key}, nil).Result()
164-
if err != nil {
165-
return err
166-
}
167-
return nil
164+
return l.rdb.Del(ctx, redisPrefix+key).Err()
168165
}
169166

170167
func dur(f float64) time.Duration {

0 commit comments

Comments
 (0)