Skip to content
This repository was archived by the owner on Dec 24, 2022. It is now read-only.

Commit 314b930

Browse files
committed
Fix GetServerTime to add micro secs properly.
1 parent 8f92380 commit 314b930

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

src/ServiceStack.Redis/RedisClient.cs

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,14 @@ public string this[string key]
8888
set { SetEntry(key, value); }
8989
}
9090

91+
public override void OnConnected() {}
92+
93+
public DateTime ConvertToServerDate(DateTime expiresAt)
94+
{
95+
//placeholder if we ever try to compensate for differences in server-time
96+
return expiresAt;
97+
}
98+
9199
public string GetTypeSequenceKey<T>()
92100
{
93101
return String.Concat(NamespacePrefix, "seq:", typeof(T).Name);
@@ -306,7 +314,7 @@ public bool ExpireEntryIn(string key, TimeSpan expireIn)
306314

307315
public bool ExpireEntryAt(string key, DateTime expireAt)
308316
{
309-
return ExpireAt(key, expireAt.ToUnixTime());
317+
return ExpireAt(key, ConvertToServerDate(expireAt).ToUnixTime());
310318
}
311319

312320
public TimeSpan GetTimeToLive(string key)
@@ -337,10 +345,12 @@ public DateTime GetServerTime()
337345
{
338346
var parts = base.Time();
339347
var unixTime = long.Parse(parts[0].FromUtf8Bytes());
340-
var ms = long.Parse(parts[1].FromUtf8Bytes());
348+
var microSecs = long.Parse(parts[1].FromUtf8Bytes());
349+
var ticks = microSecs / 1000 * TimeSpan.TicksPerMillisecond;
341350

342351
var date = unixTime.FromUnixTime();
343-
return date + TimeSpan.FromMilliseconds(ms);
352+
var timeSpan = TimeSpan.FromTicks(ticks);
353+
return date + timeSpan;
344354
}
345355

346356
public IRedisTypedClient<T> As<T>()

0 commit comments

Comments
 (0)