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

Commit ad0860f

Browse files
author
shiweichuan
committed
add missing commands
1 parent 09d99f1 commit ad0860f

File tree

2 files changed

+134
-8
lines changed

2 files changed

+134
-8
lines changed

src/ServiceStack.Redis/Commands.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,8 @@ public static class Commands
8282

8383
public readonly static byte[] RPush = "RPUSH".ToUtf8Bytes();
8484
public readonly static byte[] LPush = "LPUSH".ToUtf8Bytes();
85+
public readonly static byte[] RPushX = "RPUSHX".ToUtf8Bytes();
86+
public readonly static byte[] LPushX = "LPUSHX".ToUtf8Bytes();
8587
public readonly static byte[] LLen = "LLEN".ToUtf8Bytes();
8688
public readonly static byte[] LRange = "LRANGE".ToUtf8Bytes();
8789
public readonly static byte[] LTrim = "LTRIM".ToUtf8Bytes();

src/ServiceStack.Redis/RedisNativeClient.cs

Lines changed: 132 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -814,13 +814,38 @@ public long SAdd(string setId, byte[] value)
814814
return SendExpectLong(Commands.SAdd, setId.ToUtf8Bytes(), value);
815815
}
816816

817+
public long SAdd(string setId, byte[][] values)
818+
{
819+
if (setId == null)
820+
throw new ArgumentNullException("setId");
821+
if (values == null)
822+
throw new ArgumentNullException("values");
823+
if (values.Length == 0)
824+
throw new ArgumentException("values");
825+
826+
var cmdWithArgs = MergeCommandWithArgs(Commands.SAdd, setId.ToUtf8Bytes(), values);
827+
return SendExpectLong(cmdWithArgs);
828+
}
817829
public long SRem(string setId, byte[] value)
818830
{
819831
AssertSetIdAndValue(setId, value);
820832

821833
return SendExpectLong(Commands.SRem, setId.ToUtf8Bytes(), value);
822834
}
823835

836+
public long SRem(string setId, byte[][] values)
837+
{
838+
if (setId == null)
839+
throw new ArgumentNullException("setId");
840+
if (values == null)
841+
throw new ArgumentNullException("values");
842+
if (values.Length == 0)
843+
throw new ArgumentException("values");
844+
845+
var cmdWithArgs = MergeCommandWithArgs(Commands.SRem, setId.ToUtf8Bytes(), values);
846+
return SendExpectLong(cmdWithArgs);
847+
}
848+
824849
public byte[] SPop(string setId)
825850
{
826851
if (setId == null)
@@ -909,6 +934,11 @@ public byte[] SRandMember(string setId)
909934
return SendExpectData(Commands.SRandMember, setId.ToUtf8Bytes());
910935
}
911936

937+
public byte[][] SRandMember(string setId, int count)
938+
{
939+
return SendExpectMultiData(Commands.SRandMember, setId.ToUtf8Bytes(), count.ToUtf8Bytes());
940+
}
941+
912942
#endregion
913943

914944

@@ -974,10 +1004,25 @@ public long RPush(string listId, byte[] value)
9741004
return SendExpectLong(Commands.RPush, listId.ToUtf8Bytes(), value);
9751005
}
9761006

977-
public long RPushX(string listId, byte[] value)
978-
{
979-
throw new NotImplementedException();
980-
}
1007+
public long RPush(string listId, byte[][] values)
1008+
{
1009+
if (listId == null)
1010+
throw new ArgumentNullException("listId");
1011+
if (values == null)
1012+
throw new ArgumentNullException("values");
1013+
if (values.Length == 0)
1014+
throw new ArgumentException("values");
1015+
1016+
var cmdWithArgs = MergeCommandWithArgs(Commands.RPush, listId.ToUtf8Bytes(), values);
1017+
return SendExpectLong(cmdWithArgs);
1018+
}
1019+
1020+
public long RPushX(string listId, byte[] value)
1021+
{
1022+
AssertListIdAndValue(listId, value);
1023+
1024+
return SendExpectLong(Commands.RPushX, listId.ToUtf8Bytes(), value);
1025+
}
9811026

9821027
public long LPush(string listId, byte[] value)
9831028
{
@@ -986,10 +1031,25 @@ public long LPush(string listId, byte[] value)
9861031
return SendExpectLong(Commands.LPush, listId.ToUtf8Bytes(), value);
9871032
}
9881033

989-
public long LPushX(string listId, byte[] value)
990-
{
991-
throw new NotImplementedException();
992-
}
1034+
public long LPush(string listId, byte[][] values)
1035+
{
1036+
if (listId == null)
1037+
throw new ArgumentNullException("listId");
1038+
if (values == null)
1039+
throw new ArgumentNullException("values");
1040+
if (values.Length == 0)
1041+
throw new ArgumentException("values");
1042+
1043+
var cmdWithArgs = MergeCommandWithArgs(Commands.LPush, listId.ToUtf8Bytes(), values);
1044+
return SendExpectLong(cmdWithArgs);
1045+
}
1046+
1047+
public long LPushX(string listId, byte[] value)
1048+
{
1049+
AssertListIdAndValue(listId, value);
1050+
1051+
return SendExpectLong(Commands.LPushX, listId.ToUtf8Bytes(), value);
1052+
}
9931053

9941054
public void LTrim(string listId, int keepStartingFrom, int keepEndingAt)
9951055
{
@@ -1175,13 +1235,65 @@ public long ZAdd(string setId, long score, byte[] value)
11751235
return SendExpectLong(Commands.ZAdd, setId.ToUtf8Bytes(), score.ToUtf8Bytes(), value);
11761236
}
11771237

1238+
public long ZAdd(string setId, List<KeyValuePair<byte[], double>> pairs)
1239+
{
1240+
if (setId == null)
1241+
throw new ArgumentNullException("setId");
1242+
if (pairs == null)
1243+
throw new ArgumentNullException("pairs");
1244+
if (pairs.Count == 0)
1245+
throw new ArgumentOutOfRangeException("pairs");
1246+
1247+
var mergedBytes = new byte[2 + pairs.Count * 2][];
1248+
mergedBytes[0] = Commands.ZAdd;
1249+
mergedBytes[1] = setId.ToUtf8Bytes();
1250+
for (var i = 0; i < pairs.Count; i++)
1251+
{
1252+
mergedBytes[i * 2 + 2] = pairs[i].Value.ToFastUtf8Bytes();
1253+
mergedBytes[i * 2 + 3] = pairs[i].Key;
1254+
}
1255+
return SendExpectLong(mergedBytes);
1256+
}
1257+
1258+
public long ZAdd(string setId, List<KeyValuePair<byte[], long>> pairs)
1259+
{
1260+
if (setId == null)
1261+
throw new ArgumentNullException("setId");
1262+
if (pairs == null)
1263+
throw new ArgumentNullException("pairs");
1264+
if (pairs.Count == 0)
1265+
throw new ArgumentOutOfRangeException("pairs");
1266+
1267+
var mergedBytes = new byte[2 + pairs.Count * 2][];
1268+
mergedBytes[0] = Commands.ZAdd;
1269+
mergedBytes[1] = setId.ToUtf8Bytes();
1270+
for (var i = 0; i < pairs.Count; i++)
1271+
{
1272+
mergedBytes[i * 2 + 2] = pairs[i].Value.ToUtf8Bytes();
1273+
mergedBytes[i * 2 + 3] = pairs[i].Key;
1274+
}
1275+
return SendExpectLong(mergedBytes);
1276+
}
1277+
11781278
public long ZRem(string setId, byte[] value)
11791279
{
11801280
AssertSetIdAndValue(setId, value);
11811281

11821282
return SendExpectLong(Commands.ZRem, setId.ToUtf8Bytes(), value);
11831283
}
11841284

1285+
public long ZRem(string setId, byte[][] values)
1286+
{
1287+
if (setId == null)
1288+
throw new ArgumentNullException("setId");
1289+
if (values == null)
1290+
throw new ArgumentNullException("values");
1291+
if (values.Length == 0)
1292+
throw new ArgumentException("values");
1293+
1294+
var cmdWithArgs = MergeCommandWithArgs(Commands.ZRem, setId.ToUtf8Bytes(), values);
1295+
return SendExpectLong(cmdWithArgs);
1296+
}
11851297
public double ZIncrBy(string setId, double incrBy, byte[] value)
11861298
{
11871299
AssertSetIdAndValue(setId, value);
@@ -1507,6 +1619,18 @@ public long HDel(string hashId, byte[] key)
15071619
return SendExpectLong(Commands.HDel, hashId.ToUtf8Bytes(), key);
15081620
}
15091621

1622+
public long HDel(string hashId, byte[][] keys)
1623+
{
1624+
if (hashId == null)
1625+
throw new ArgumentNullException("hashId");
1626+
if (keys == null)
1627+
throw new ArgumentNullException("keys");
1628+
if (keys.Length == 0)
1629+
throw new ArgumentException("keys");
1630+
1631+
var cmdWithArgs = MergeCommandWithArgs(Commands.HDel, hashId.ToUtf8Bytes(), keys);
1632+
return SendExpectLong(cmdWithArgs);
1633+
}
15101634
public long HExists(string hashId, byte[] key)
15111635
{
15121636
AssertHashIdAndKey(hashId, key);

0 commit comments

Comments
 (0)