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

Commit 4211126

Browse files
committed
AssertServerVersionNumber is called for ops requiring version detection
1 parent bbe21df commit 4211126

File tree

3 files changed

+14
-5
lines changed

3 files changed

+14
-5
lines changed

src/ServiceStack.Redis/RedisClient.ICacheClient.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ public bool Set<T>(string key, T value, TimeSpan expiresIn)
121121
var bytesValue = value as byte[];
122122
if (bytesValue != null)
123123
{
124-
if (ServerVersionNumber >= 2600)
124+
if (AssertServerVersionNumber() >= 2600)
125125
{
126126
Exec(r => r.PSetEx(key, (long)expiresIn.TotalMilliseconds, bytesValue));
127127
}

src/ServiceStack.Redis/RedisClient.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ public void SetEntry(string key, string value, TimeSpan expireIn)
136136
? value.ToUtf8Bytes()
137137
: null;
138138

139-
if (ServerVersionNumber >= 2610)
139+
if (AssertServerVersionNumber() >= 2610)
140140
{
141141
if (expireIn.Milliseconds > 0)
142142
base.Set(key, bytesValue, 0, (long)expireIn.TotalMilliseconds);
@@ -331,7 +331,7 @@ public string GetRandomKey()
331331

332332
public bool ExpireEntryIn(string key, TimeSpan expireIn)
333333
{
334-
if (ServerVersionNumber >= 2600)
334+
if (AssertServerVersionNumber() >= 2600)
335335
{
336336
if (expireIn.Milliseconds > 0)
337337
{
@@ -344,7 +344,7 @@ public bool ExpireEntryIn(string key, TimeSpan expireIn)
344344

345345
public bool ExpireEntryAt(string key, DateTime expireAt)
346346
{
347-
if (ServerVersionNumber >= 2600)
347+
if (AssertServerVersionNumber() >= 2600)
348348
{
349349
return PExpireAt(key, ConvertToServerDate(expireAt).ToUnixTimeMs());
350350
}
@@ -416,6 +416,7 @@ public IDisposable AcquireLock(string key, TimeSpan timeOut)
416416

417417
public IRedisTransaction CreateTransaction()
418418
{
419+
AssertServerVersionNumber(); // pre-fetch call to INFO before transaction if needed
419420
return new RedisTransaction(this);
420421
}
421422

src/ServiceStack.Redis/RedisNativeClient_Utils.cs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,14 @@ public partial class RedisNativeClient
2929
private const int Unknown = -1;
3030
public int ServerVersionNumber { get; set; }
3131

32+
public int AssertServerVersionNumber()
33+
{
34+
if (ServerVersionNumber == 0)
35+
AssertConnectedSocket();
36+
37+
return ServerVersionNumber;
38+
}
39+
3240
public static void DisposeTimers()
3341
{
3442
if (UsageTimer == null) return;
@@ -163,7 +171,7 @@ public bool IsSocketConnected()
163171
return !(part1 & part2);
164172
}
165173

166-
private bool AssertConnectedSocket()
174+
internal bool AssertConnectedSocket()
167175
{
168176
if (LastConnectedAtTimestamp > 0)
169177
{

0 commit comments

Comments
 (0)