Skip to content

Commit

Permalink
add missing commands
Browse files Browse the repository at this point in the history
  • Loading branch information
shiweichuan committed Jul 5, 2013
1 parent 09d99f1 commit ad0860f
Show file tree
Hide file tree
Showing 2 changed files with 134 additions and 8 deletions.
2 changes: 2 additions & 0 deletions src/ServiceStack.Redis/Commands.cs
Expand Up @@ -82,6 +82,8 @@ public static class Commands

public readonly static byte[] RPush = "RPUSH".ToUtf8Bytes();
public readonly static byte[] LPush = "LPUSH".ToUtf8Bytes();
public readonly static byte[] RPushX = "RPUSHX".ToUtf8Bytes();
public readonly static byte[] LPushX = "LPUSHX".ToUtf8Bytes();
public readonly static byte[] LLen = "LLEN".ToUtf8Bytes();
public readonly static byte[] LRange = "LRANGE".ToUtf8Bytes();
public readonly static byte[] LTrim = "LTRIM".ToUtf8Bytes();
Expand Down
140 changes: 132 additions & 8 deletions src/ServiceStack.Redis/RedisNativeClient.cs
Expand Up @@ -814,13 +814,38 @@ public long SAdd(string setId, byte[] value)
return SendExpectLong(Commands.SAdd, setId.ToUtf8Bytes(), value);
}

public long SAdd(string setId, byte[][] values)
{
if (setId == null)
throw new ArgumentNullException("setId");
if (values == null)
throw new ArgumentNullException("values");
if (values.Length == 0)
throw new ArgumentException("values");

var cmdWithArgs = MergeCommandWithArgs(Commands.SAdd, setId.ToUtf8Bytes(), values);
return SendExpectLong(cmdWithArgs);
}
public long SRem(string setId, byte[] value)
{
AssertSetIdAndValue(setId, value);

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

public long SRem(string setId, byte[][] values)
{
if (setId == null)
throw new ArgumentNullException("setId");
if (values == null)
throw new ArgumentNullException("values");
if (values.Length == 0)
throw new ArgumentException("values");

var cmdWithArgs = MergeCommandWithArgs(Commands.SRem, setId.ToUtf8Bytes(), values);
return SendExpectLong(cmdWithArgs);
}

public byte[] SPop(string setId)
{
if (setId == null)
Expand Down Expand Up @@ -909,6 +934,11 @@ public byte[] SRandMember(string setId)
return SendExpectData(Commands.SRandMember, setId.ToUtf8Bytes());
}

public byte[][] SRandMember(string setId, int count)
{
return SendExpectMultiData(Commands.SRandMember, setId.ToUtf8Bytes(), count.ToUtf8Bytes());
}

#endregion


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

public long RPushX(string listId, byte[] value)
{
throw new NotImplementedException();
}
public long RPush(string listId, byte[][] values)
{
if (listId == null)
throw new ArgumentNullException("listId");
if (values == null)
throw new ArgumentNullException("values");
if (values.Length == 0)
throw new ArgumentException("values");

var cmdWithArgs = MergeCommandWithArgs(Commands.RPush, listId.ToUtf8Bytes(), values);
return SendExpectLong(cmdWithArgs);
}

public long RPushX(string listId, byte[] value)
{
AssertListIdAndValue(listId, value);

return SendExpectLong(Commands.RPushX, listId.ToUtf8Bytes(), value);
}

public long LPush(string listId, byte[] value)
{
Expand All @@ -986,10 +1031,25 @@ public long LPush(string listId, byte[] value)
return SendExpectLong(Commands.LPush, listId.ToUtf8Bytes(), value);
}

public long LPushX(string listId, byte[] value)
{
throw new NotImplementedException();
}
public long LPush(string listId, byte[][] values)
{
if (listId == null)
throw new ArgumentNullException("listId");
if (values == null)
throw new ArgumentNullException("values");
if (values.Length == 0)
throw new ArgumentException("values");

var cmdWithArgs = MergeCommandWithArgs(Commands.LPush, listId.ToUtf8Bytes(), values);
return SendExpectLong(cmdWithArgs);
}

public long LPushX(string listId, byte[] value)
{
AssertListIdAndValue(listId, value);

return SendExpectLong(Commands.LPushX, listId.ToUtf8Bytes(), value);
}

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

public long ZAdd(string setId, List<KeyValuePair<byte[], double>> pairs)
{
if (setId == null)
throw new ArgumentNullException("setId");
if (pairs == null)
throw new ArgumentNullException("pairs");
if (pairs.Count == 0)
throw new ArgumentOutOfRangeException("pairs");

var mergedBytes = new byte[2 + pairs.Count * 2][];
mergedBytes[0] = Commands.ZAdd;
mergedBytes[1] = setId.ToUtf8Bytes();
for (var i = 0; i < pairs.Count; i++)
{
mergedBytes[i * 2 + 2] = pairs[i].Value.ToFastUtf8Bytes();
mergedBytes[i * 2 + 3] = pairs[i].Key;
}
return SendExpectLong(mergedBytes);
}

public long ZAdd(string setId, List<KeyValuePair<byte[], long>> pairs)
{
if (setId == null)
throw new ArgumentNullException("setId");
if (pairs == null)
throw new ArgumentNullException("pairs");
if (pairs.Count == 0)
throw new ArgumentOutOfRangeException("pairs");

var mergedBytes = new byte[2 + pairs.Count * 2][];
mergedBytes[0] = Commands.ZAdd;
mergedBytes[1] = setId.ToUtf8Bytes();
for (var i = 0; i < pairs.Count; i++)
{
mergedBytes[i * 2 + 2] = pairs[i].Value.ToUtf8Bytes();
mergedBytes[i * 2 + 3] = pairs[i].Key;
}
return SendExpectLong(mergedBytes);
}

public long ZRem(string setId, byte[] value)
{
AssertSetIdAndValue(setId, value);

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

public long ZRem(string setId, byte[][] values)
{
if (setId == null)
throw new ArgumentNullException("setId");
if (values == null)
throw new ArgumentNullException("values");
if (values.Length == 0)
throw new ArgumentException("values");

var cmdWithArgs = MergeCommandWithArgs(Commands.ZRem, setId.ToUtf8Bytes(), values);
return SendExpectLong(cmdWithArgs);
}
public double ZIncrBy(string setId, double incrBy, byte[] value)
{
AssertSetIdAndValue(setId, value);
Expand Down Expand Up @@ -1507,6 +1619,18 @@ public long HDel(string hashId, byte[] key)
return SendExpectLong(Commands.HDel, hashId.ToUtf8Bytes(), key);
}

public long HDel(string hashId, byte[][] keys)
{
if (hashId == null)
throw new ArgumentNullException("hashId");
if (keys == null)
throw new ArgumentNullException("keys");
if (keys.Length == 0)
throw new ArgumentException("keys");

var cmdWithArgs = MergeCommandWithArgs(Commands.HDel, hashId.ToUtf8Bytes(), keys);
return SendExpectLong(cmdWithArgs);
}
public long HExists(string hashId, byte[] key)
{
AssertHashIdAndKey(hashId, key);
Expand Down

0 comments on commit ad0860f

Please sign in to comment.