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

Commit bc4a275

Browse files
committed
Merge new byte[] key API's into existing code-base
1 parent acd55da commit bc4a275

File tree

5 files changed

+92
-160
lines changed

5 files changed

+92
-160
lines changed

src/ServiceStack.Redis/RedisClient.KeyByteArray.cs

Lines changed: 0 additions & 43 deletions
This file was deleted.

src/ServiceStack.Redis/RedisClient.cs

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,20 @@ public void SetValue(string key, string value)
154154
base.Set(key, bytesValue);
155155
}
156156

157+
public bool SetValue(byte[] key, byte[] value, TimeSpan expireIn)
158+
{
159+
if (AssertServerVersionNumber() >= 2600)
160+
{
161+
Exec(r => r.Set(key, value, 0, expiryMs: (long)expireIn.TotalMilliseconds));
162+
}
163+
else
164+
{
165+
Exec(r => r.SetEx(key, (int)expireIn.TotalSeconds, value));
166+
}
167+
168+
return true;
169+
}
170+
157171
[Obsolete("Use SetValue()")]
158172
public void SetEntry(string key, string value, TimeSpan expireIn)
159173
{
@@ -324,6 +338,11 @@ public bool Remove(string key)
324338
return Del(key) == Success;
325339
}
326340

341+
public bool Remove(byte[] key)
342+
{
343+
return Del(key) == Success;
344+
}
345+
327346
public bool RemoveEntry(params string[] keys)
328347
{
329348
if (keys.Length == 0) return false;
@@ -394,6 +413,19 @@ public bool ExpireEntryIn(string key, TimeSpan expireIn)
394413
return Expire(key, (int)expireIn.TotalSeconds);
395414
}
396415

416+
public bool ExpireEntryIn(byte[] key, TimeSpan expireIn)
417+
{
418+
if (AssertServerVersionNumber() >= 2600)
419+
{
420+
if (expireIn.Milliseconds > 0)
421+
{
422+
return PExpire(key, (long)expireIn.TotalMilliseconds);
423+
}
424+
}
425+
426+
return Expire(key, (int)expireIn.TotalSeconds);
427+
}
428+
397429
public bool ExpireEntryAt(string key, DateTime expireAt)
398430
{
399431
if (AssertServerVersionNumber() >= 2600)

src/ServiceStack.Redis/RedisNativeClient.KeyByteArray.cs

Lines changed: 0 additions & 104 deletions
This file was deleted.

src/ServiceStack.Redis/RedisNativeClient.cs

Lines changed: 60 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -456,20 +456,26 @@ public void Set(string key, byte[] value)
456456
}
457457

458458
public void Set(string key, byte[] value, int expirySeconds, long expiryMs = 0)
459+
{
460+
Set(key.ToUtf8Bytes(), value, expirySeconds, expiryMs);
461+
}
462+
463+
public void Set(byte[] key, byte[] value, int expirySeconds, long expiryMs = 0)
459464
{
460465
if (key == null)
461466
throw new ArgumentNullException("key");
467+
462468
value = value ?? new byte[0];
463469

464470
if (value.Length > OneGb)
465471
throw new ArgumentException("value exceeds 1G", "value");
466472

467473
if (expirySeconds > 0)
468-
SendExpectSuccess(Commands.Set, key.ToUtf8Bytes(), value, Commands.Ex, expirySeconds.ToUtf8Bytes());
474+
SendExpectSuccess(Commands.Set, key, value, Commands.Ex, expirySeconds.ToUtf8Bytes());
469475
else if (expiryMs > 0)
470-
SendExpectSuccess(Commands.Set, key.ToUtf8Bytes(), value, Commands.Px, expiryMs.ToUtf8Bytes());
476+
SendExpectSuccess(Commands.Set, key, value, Commands.Px, expiryMs.ToUtf8Bytes());
471477
else
472-
SendExpectSuccess(Commands.Set, key.ToUtf8Bytes(), value);
478+
SendExpectSuccess(Commands.Set, key, value);
473479
}
474480

475481
public bool Set(string key, byte[] value, bool exists, int expirySeconds = 0, long expiryMs = 0)
@@ -485,6 +491,11 @@ public bool Set(string key, byte[] value, bool exists, int expirySeconds = 0, lo
485491
}
486492

487493
public void SetEx(string key, int expireInSeconds, byte[] value)
494+
{
495+
SetEx(key.ToUtf8Bytes(), expireInSeconds, value);
496+
}
497+
498+
public void SetEx(byte[] key, int expireInSeconds, byte[] value)
488499
{
489500
if (key == null)
490501
throw new ArgumentNullException("key");
@@ -493,7 +504,7 @@ public void SetEx(string key, int expireInSeconds, byte[] value)
493504
if (value.Length > OneGb)
494505
throw new ArgumentException("value exceeds 1G", "value");
495506

496-
SendExpectSuccess(Commands.SetEx, key.ToUtf8Bytes(), expireInSeconds.ToUtf8Bytes(), value);
507+
SendExpectSuccess(Commands.SetEx, key, expireInSeconds.ToUtf8Bytes(), value);
497508
}
498509

499510
public bool Persist(string key)
@@ -553,6 +564,14 @@ public byte[] Get(string key)
553564
return GetBytes(key);
554565
}
555566

567+
public byte[] Get(byte[] key)
568+
{
569+
if (key == null)
570+
throw new ArgumentNullException("key");
571+
572+
return SendExpectData(Commands.Get, key);
573+
}
574+
556575
public object[] Slowlog(int? top)
557576
{
558577
if (top.HasValue)
@@ -596,11 +615,16 @@ public long Exists(string key)
596615
}
597616

598617
public long Del(string key)
618+
{
619+
return Del(key.ToUtf8Bytes());
620+
}
621+
622+
public long Del(byte[] key)
599623
{
600624
if (key == null)
601625
throw new ArgumentNullException("key");
602626

603-
return SendExpectLong(Commands.Del, key.ToUtf8Bytes());
627+
return SendExpectLong(Commands.Del, key);
604628
}
605629

606630
public long Del(params string[] keys)
@@ -736,19 +760,29 @@ public bool RenameNx(string oldKeyname, string newKeyname)
736760
}
737761

738762
public bool Expire(string key, int seconds)
763+
{
764+
return Expire(key.ToUtf8Bytes(), seconds);
765+
}
766+
767+
public bool Expire(byte[] key, int seconds)
739768
{
740769
if (key == null)
741770
throw new ArgumentNullException("key");
742771

743-
return SendExpectLong(Commands.Expire, key.ToUtf8Bytes(), seconds.ToUtf8Bytes()) == Success;
772+
return SendExpectLong(Commands.Expire, key, seconds.ToUtf8Bytes()) == Success;
744773
}
745774

746775
public bool PExpire(string key, long ttlMs)
776+
{
777+
return PExpire(key.ToUtf8Bytes(), ttlMs);
778+
}
779+
780+
public bool PExpire(byte[] key, long ttlMs)
747781
{
748782
if (key == null)
749783
throw new ArgumentNullException("key");
750784

751-
return SendExpectLong(Commands.PExpire, key.ToUtf8Bytes(), ttlMs.ToUtf8Bytes()) == Success;
785+
return SendExpectLong(Commands.PExpire, key, ttlMs.ToUtf8Bytes()) == Success;
752786
}
753787

754788
public bool ExpireAt(string key, long unixTime)
@@ -1969,7 +2003,7 @@ public long ZRemRangeByLex(string setId, string min, string max)
19692003

19702004
#region Hash Operations
19712005

1972-
private static void AssertHashIdAndKey(string hashId, byte[] key)
2006+
private static void AssertHashIdAndKey(object hashId, byte[] key)
19732007
{
19742008
if (hashId == null)
19752009
throw new ArgumentNullException("hashId");
@@ -1978,10 +2012,15 @@ private static void AssertHashIdAndKey(string hashId, byte[] key)
19782012
}
19792013

19802014
public long HSet(string hashId, byte[] key, byte[] value)
2015+
{
2016+
return HSet(hashId.ToUtf8Bytes(), key, value);
2017+
}
2018+
2019+
public long HSet(byte[] hashId, byte[] key, byte[] value)
19812020
{
19822021
AssertHashIdAndKey(hashId, key);
19832022

1984-
return SendExpectLong(Commands.HSet, hashId.ToUtf8Bytes(), key, value);
2023+
return SendExpectLong(Commands.HSet, hashId, key, value);
19852024
}
19862025

19872026
public long HSetNX(string hashId, byte[] key, byte[] value)
@@ -2023,10 +2062,15 @@ public double HIncrbyFloat(string hashId, byte[] key, double incrementBy)
20232062
}
20242063

20252064
public byte[] HGet(string hashId, byte[] key)
2065+
{
2066+
return HGet(hashId.ToUtf8Bytes(), key);
2067+
}
2068+
2069+
public byte[] HGet(byte[] hashId, byte[] key)
20262070
{
20272071
AssertHashIdAndKey(hashId, key);
20282072

2029-
return SendExpectData(Commands.HGet, hashId.ToUtf8Bytes(), key);
2073+
return SendExpectData(Commands.HGet, hashId, key);
20302074
}
20312075

20322076
public byte[][] HMGet(string hashId, params byte[][] keys)
@@ -2042,10 +2086,15 @@ public byte[][] HMGet(string hashId, params byte[][] keys)
20422086
}
20432087

20442088
public long HDel(string hashId, byte[] key)
2089+
{
2090+
return HDel(hashId.ToUtf8Bytes(), key);
2091+
}
2092+
2093+
public long HDel(byte[] hashId, byte[] key)
20452094
{
20462095
AssertHashIdAndKey(hashId, key);
20472096

2048-
return SendExpectLong(Commands.HDel, hashId.ToUtf8Bytes(), key);
2097+
return SendExpectLong(Commands.HDel, hashId, key);
20492098
}
20502099

20512100
public long HDel(string hashId, byte[][] keys)

src/ServiceStack.Redis/ServiceStack.Redis.csproj

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -148,8 +148,6 @@
148148
<Compile Include="BasicRedisClientManager.cs" />
149149
<Compile Include="BasicRedisClientManager.ICacheClient.cs" />
150150
<Compile Include="BasicRedisResolver.cs" />
151-
<Compile Include="RedisClient.KeyByteArray.cs" />
152-
<Compile Include="RedisNativeClient.KeyByteArray.cs" />
153151
<Compile Include="RedisResolver.cs" />
154152
<Compile Include="BufferPool.cs" />
155153
<Compile Include="Commands.cs" />

0 commit comments

Comments
 (0)