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

Commit 8f92380

Browse files
committed
Add GetServerTime
1 parent 0d98877 commit 8f92380

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

src/ServiceStack.Redis/RedisClient.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -333,6 +333,16 @@ public string GetConfig(string configItem)
333333
return sb.ToString();
334334
}
335335

336+
public DateTime GetServerTime()
337+
{
338+
var parts = base.Time();
339+
var unixTime = long.Parse(parts[0].FromUtf8Bytes());
340+
var ms = long.Parse(parts[1].FromUtf8Bytes());
341+
342+
var date = unixTime.FromUnixTime();
343+
return date + TimeSpan.FromMilliseconds(ms);
344+
}
345+
336346
public IRedisTypedClient<T> As<T>()
337347
{
338348
try

tests/ServiceStack.Redis.Tests/RedisClientTests.cs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,22 @@ public void Can_GetTimeToLive()
200200
Assert.That(ttl.TotalSeconds, Is.LessThanOrEqualTo(9));
201201
}
202202

203+
[Test]
204+
public void Can_GetServerTime()
205+
{
206+
var now = Redis.GetServerTime();
207+
208+
now.Kind.PrintDump();
209+
now.ToLongDateString().Print();
210+
now.ToLongTimeString().Print();
211+
212+
"UtcNow".Print();
213+
DateTime.UtcNow.ToLongDateString().Print();
214+
DateTime.UtcNow.ToLongTimeString().Print();
215+
216+
Assert.That(now.Date, Is.EqualTo(DateTime.UtcNow.Date));
217+
}
218+
203219
[Test]
204220
public void Can_Ping()
205221
{

0 commit comments

Comments
 (0)