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

Commit 0019dce

Browse files
committed
Get ExpireAt commands to call ConvertToServerDate if we ever want to compensate for the offset between client/server dates
1 parent ec3189f commit 0019dce

File tree

3 files changed

+10
-9
lines changed

3 files changed

+10
-9
lines changed

src/ServiceStack.Redis/Generic/RedisTypedClient.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,7 @@ public bool ExpireEntryIn(string key, TimeSpan expireIn)
288288

289289
public bool ExpireEntryAt(string key, DateTime expireAt)
290290
{
291-
return client.ExpireAt(key, expireAt.ToUnixTime());
291+
return client.ExpireEntryAt(key, expireAt);
292292
}
293293

294294
public bool ExpireIn(object id, TimeSpan expireIn)
@@ -300,7 +300,7 @@ public bool ExpireIn(object id, TimeSpan expireIn)
300300
public bool ExpireAt(object id, DateTime expireAt)
301301
{
302302
var key = client.UrnKey<T>(id);
303-
return client.ExpireAt(key, expireAt.ToUnixTime());
303+
return client.ExpireEntryAt(key, expireAt);
304304
}
305305

306306
public TimeSpan GetTimeToLive(string key)

src/ServiceStack.Redis/RedisClient.ICacheClient.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ public bool Add<T>(string key, T value, DateTime expiresAt)
9090
{
9191
if (Add(key, value))
9292
{
93-
ExpireEntryAt(key, expiresAt);
93+
ExpireEntryAt(key, ConvertToServerDate(expiresAt));
9494
return true;
9595
}
9696
return false;
@@ -113,15 +113,15 @@ public bool Set<T>(string key, T value, TimeSpan expiresIn)
113113
public bool Set<T>(string key, T value, DateTime expiresAt)
114114
{
115115
Set(key, value);
116-
ExpireEntryAt(key, expiresAt);
116+
ExpireEntryAt(key, ConvertToServerDate(expiresAt));
117117
return true;
118118
}
119119

120120
public bool Replace<T>(string key, T value, DateTime expiresAt)
121121
{
122122
if (Replace(key, value))
123123
{
124-
ExpireEntryAt(key, expiresAt);
124+
ExpireEntryAt(key, ConvertToServerDate(expiresAt));
125125
return true;
126126
}
127127
return false;

tests/ServiceStack.Redis.Tests/Generic/RedisTypedClientTests.cs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,10 @@ public virtual void OnBeforeEachTest()
4242
base.OnBeforeEachTest();
4343

4444
if (Redis != null) Redis.Dispose();
45-
Redis = new RedisClient(TestConfig.SingleHost);
46-
Redis.NamespacePrefix = "RedisTypedClientTests:";
47-
RedisTyped = Redis.As<CacheRecord>();
45+
Redis = new RedisClient(TestConfig.SingleHost) {
46+
NamespacePrefix = "RedisTypedClientTests:"
47+
};
48+
RedisTyped = Redis.As<CacheRecord>();
4849
}
4950

5051
[TearDown]
@@ -93,7 +94,7 @@ public void Can_ExpireAt()
9394

9495
RedisTyped.Store(cachedRecord);
9596

96-
var in2Secs = DateTime.Now.AddSeconds(2);
97+
var in2Secs = DateTime.UtcNow.AddSeconds(2);
9798

9899
RedisTyped.ExpireAt("key", in2Secs);
99100

0 commit comments

Comments
 (0)