Skip to content

Commit

Permalink
update more usage
Browse files Browse the repository at this point in the history
  • Loading branch information
WeihanLi authored Oct 23, 2024
1 parent 6f0d575 commit ccb4dc6
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ namespace RedisRateLimiting
{
public class RedisFixedWindowRateLimiter<TKey> : RateLimiter
{
private static readonly double TickFrequency = (double)TimeSpan.TicksPerSecond / Stopwatch.Frequency;

private readonly RedisFixedWindowManager _redisManager;
private readonly RedisFixedWindowRateLimiterOptions _options;

Expand All @@ -22,7 +20,7 @@ public class RedisFixedWindowRateLimiter<TKey> : RateLimiter

public override TimeSpan? IdleDuration => Interlocked.CompareExchange(ref _activeRequestsCount, 0, 0) > 0
? null
: new TimeSpan((long)((Stopwatch.GetTimestamp() - _idleSince) * TickFrequency));
: Stopwatch.GetElapsedTime(_idleSince);

public RedisFixedWindowRateLimiter(TKey partitionKey, RedisFixedWindowRateLimiterOptions options)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ namespace RedisRateLimiting
{
public class RedisSlidingWindowRateLimiter<TKey> : RateLimiter
{
private static readonly double TickFrequency = (double)TimeSpan.TicksPerSecond / Stopwatch.Frequency;

private readonly RedisSlidingWindowManager _redisManager;
private readonly RedisSlidingWindowRateLimiterOptions _options;

Expand All @@ -22,7 +20,7 @@ public class RedisSlidingWindowRateLimiter<TKey> : RateLimiter

public override TimeSpan? IdleDuration => Interlocked.CompareExchange(ref _activeRequestsCount, 0, 0) > 0
? null
: new TimeSpan((long)((Stopwatch.GetTimestamp() - _idleSince) * TickFrequency));
: Stopwatch.GetElapsedTime(_idleSince);

public RedisSlidingWindowRateLimiter(TKey partitionKey, RedisSlidingWindowRateLimiterOptions options)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ namespace RedisRateLimiting
{
public class RedisTokenBucketRateLimiter<TKey> : RateLimiter
{
private static readonly double TickFrequency = (double)TimeSpan.TicksPerSecond / Stopwatch.Frequency;

private readonly RedisTokenBucketManager _redisManager;
private readonly RedisTokenBucketRateLimiterOptions _options;

Expand All @@ -22,7 +20,7 @@ public class RedisTokenBucketRateLimiter<TKey> : RateLimiter

public override TimeSpan? IdleDuration => Interlocked.CompareExchange(ref _activeRequestsCount, 0, 0) > 0
? null
: new TimeSpan((long)((Stopwatch.GetTimestamp() - _idleSince) * TickFrequency));
: Stopwatch.GetElapsedTime(_idleSince);

public RedisTokenBucketRateLimiter(TKey partitionKey, RedisTokenBucketRateLimiterOptions options)
{
Expand Down

0 comments on commit ccb4dc6

Please sign in to comment.