diff --git a/src/RedisRateLimiting/FixedWindow/RedisFixedWindowRateLimiter.cs b/src/RedisRateLimiting/FixedWindow/RedisFixedWindowRateLimiter.cs index c4aceb9..66bee3e 100644 --- a/src/RedisRateLimiting/FixedWindow/RedisFixedWindowRateLimiter.cs +++ b/src/RedisRateLimiting/FixedWindow/RedisFixedWindowRateLimiter.cs @@ -10,8 +10,6 @@ namespace RedisRateLimiting { public class RedisFixedWindowRateLimiter : RateLimiter { - private static readonly double TickFrequency = (double)TimeSpan.TicksPerSecond / Stopwatch.Frequency; - private readonly RedisFixedWindowManager _redisManager; private readonly RedisFixedWindowRateLimiterOptions _options; @@ -22,7 +20,7 @@ public class RedisFixedWindowRateLimiter : 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) { diff --git a/src/RedisRateLimiting/SlidingWindow/RedisSlidingWindowRateLimiter.cs b/src/RedisRateLimiting/SlidingWindow/RedisSlidingWindowRateLimiter.cs index 7283a5a..8bf2a1f 100644 --- a/src/RedisRateLimiting/SlidingWindow/RedisSlidingWindowRateLimiter.cs +++ b/src/RedisRateLimiting/SlidingWindow/RedisSlidingWindowRateLimiter.cs @@ -10,8 +10,6 @@ namespace RedisRateLimiting { public class RedisSlidingWindowRateLimiter : RateLimiter { - private static readonly double TickFrequency = (double)TimeSpan.TicksPerSecond / Stopwatch.Frequency; - private readonly RedisSlidingWindowManager _redisManager; private readonly RedisSlidingWindowRateLimiterOptions _options; @@ -22,7 +20,7 @@ public class RedisSlidingWindowRateLimiter : 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) { diff --git a/src/RedisRateLimiting/TokenBucket/RedisTokenBucketRateLimiter.cs b/src/RedisRateLimiting/TokenBucket/RedisTokenBucketRateLimiter.cs index 6ca2803..517eb15 100644 --- a/src/RedisRateLimiting/TokenBucket/RedisTokenBucketRateLimiter.cs +++ b/src/RedisRateLimiting/TokenBucket/RedisTokenBucketRateLimiter.cs @@ -10,8 +10,6 @@ namespace RedisRateLimiting { public class RedisTokenBucketRateLimiter : RateLimiter { - private static readonly double TickFrequency = (double)TimeSpan.TicksPerSecond / Stopwatch.Frequency; - private readonly RedisTokenBucketManager _redisManager; private readonly RedisTokenBucketRateLimiterOptions _options; @@ -22,7 +20,7 @@ public class RedisTokenBucketRateLimiter : 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) {