temp
This commit is contained in:
@@ -64,6 +64,7 @@ end
|
||||
|
||||
type RateLimitTransport struct {
|
||||
http.RoundTripper
|
||||
redis rueidis.Client
|
||||
}
|
||||
|
||||
func (t *RateLimitTransport) RoundTrip(req *http.Request) (*http.Response, error) {
|
||||
@@ -84,7 +85,7 @@ func (t *RateLimitTransport) RoundTrip(req *http.Request) (*http.Response, error
|
||||
return nil, fmt.Errorf("sellerId is required in JWT claims")
|
||||
}
|
||||
now := time.Now().UnixMilli()
|
||||
client := *redis.Client
|
||||
client := t.redis
|
||||
|
||||
waitTime, err := tokenBucketScript.Exec(ctx, client, []string{sellerId}, []string{
|
||||
fmt.Sprintf("%d", now),
|
||||
@@ -113,7 +114,7 @@ func SyncRateLimitRemaining(ctx context.Context, sellerId string, remaining int)
|
||||
return fmt.Errorf("invalid sellerId or remaining")
|
||||
}
|
||||
now := time.Now().UnixMilli()
|
||||
client := *redis.Client
|
||||
client :=
|
||||
|
||||
cmds := []rueidis.Completed{
|
||||
client.B().Set().Key(sellerId + ":capacity").Value(fmt.Sprintf("%d", defaultBucketCapacity)).Ex(time.Minute).Build(),
|
||||
@@ -167,6 +168,6 @@ func SetRateLimitRetry(ctx context.Context, sellerId string, retrySeconds int, l
|
||||
return nil
|
||||
}
|
||||
|
||||
func NewRateLimitTransport() *RateLimitTransport {
|
||||
func NewRateLimitTransport(client rueidis.Client) *RateLimitTransport {
|
||||
return &RateLimitTransport{RoundTripper: http.DefaultTransport}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user