Permalink
Browse files

small tweaks

  • Loading branch information...
1 parent 0c97ba9 commit 7a64aad8b9a4fcd452c4e35a3d62a757c8d465d7 Karl Seguin committed Nov 4, 2011
View
@@ -7,46 +7,104 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Metsys.Redis.Console", "Met
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Metsys.Redis.Tests", "Metsys.Redis.Tests\Metsys.Redis.Tests.csproj", "{83A9D87F-E7AA-40D7-8403-4A8BDF09357C}"
EndProject
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ServiceStack.Redis", "E:\ServiceStackRedis\src\ServiceStack.Redis\ServiceStack.Redis.csproj", "{AF99F19B-4C04-4F58-81EF-B092F1FCC540}"
+EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Debug|Mixed Platforms = Debug|Mixed Platforms
Debug|x86 = Debug|x86
+ MonoTouch|Any CPU = MonoTouch|Any CPU
+ MonoTouch|Mixed Platforms = MonoTouch|Mixed Platforms
+ MonoTouch|x86 = MonoTouch|x86
Release|Any CPU = Release|Any CPU
Release|Mixed Platforms = Release|Mixed Platforms
Release|x86 = Release|x86
+ STATIC_ONLY NO_EXPRESSIONS|Any CPU = STATIC_ONLY NO_EXPRESSIONS|Any CPU
+ STATIC_ONLY NO_EXPRESSIONS|Mixed Platforms = STATIC_ONLY NO_EXPRESSIONS|Mixed Platforms
+ STATIC_ONLY NO_EXPRESSIONS|x86 = STATIC_ONLY NO_EXPRESSIONS|x86
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{C050F51C-8CAC-4E10-A215-AE155F67EA02}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{C050F51C-8CAC-4E10-A215-AE155F67EA02}.Debug|Any CPU.Build.0 = Debug|Any CPU
{C050F51C-8CAC-4E10-A215-AE155F67EA02}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU
{C050F51C-8CAC-4E10-A215-AE155F67EA02}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU
{C050F51C-8CAC-4E10-A215-AE155F67EA02}.Debug|x86.ActiveCfg = Debug|Any CPU
+ {C050F51C-8CAC-4E10-A215-AE155F67EA02}.MonoTouch|Any CPU.ActiveCfg = Release|Any CPU
+ {C050F51C-8CAC-4E10-A215-AE155F67EA02}.MonoTouch|Any CPU.Build.0 = Release|Any CPU
+ {C050F51C-8CAC-4E10-A215-AE155F67EA02}.MonoTouch|Mixed Platforms.ActiveCfg = Release|Any CPU
+ {C050F51C-8CAC-4E10-A215-AE155F67EA02}.MonoTouch|Mixed Platforms.Build.0 = Release|Any CPU
+ {C050F51C-8CAC-4E10-A215-AE155F67EA02}.MonoTouch|x86.ActiveCfg = Release|Any CPU
{C050F51C-8CAC-4E10-A215-AE155F67EA02}.Release|Any CPU.ActiveCfg = Release|Any CPU
{C050F51C-8CAC-4E10-A215-AE155F67EA02}.Release|Any CPU.Build.0 = Release|Any CPU
{C050F51C-8CAC-4E10-A215-AE155F67EA02}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
{C050F51C-8CAC-4E10-A215-AE155F67EA02}.Release|Mixed Platforms.Build.0 = Release|Any CPU
{C050F51C-8CAC-4E10-A215-AE155F67EA02}.Release|x86.ActiveCfg = Release|Any CPU
+ {C050F51C-8CAC-4E10-A215-AE155F67EA02}.STATIC_ONLY NO_EXPRESSIONS|Any CPU.ActiveCfg = Release|Any CPU
+ {C050F51C-8CAC-4E10-A215-AE155F67EA02}.STATIC_ONLY NO_EXPRESSIONS|Any CPU.Build.0 = Release|Any CPU
+ {C050F51C-8CAC-4E10-A215-AE155F67EA02}.STATIC_ONLY NO_EXPRESSIONS|Mixed Platforms.ActiveCfg = Release|Any CPU
+ {C050F51C-8CAC-4E10-A215-AE155F67EA02}.STATIC_ONLY NO_EXPRESSIONS|Mixed Platforms.Build.0 = Release|Any CPU
+ {C050F51C-8CAC-4E10-A215-AE155F67EA02}.STATIC_ONLY NO_EXPRESSIONS|x86.ActiveCfg = Release|Any CPU
{B28FB5AB-98D9-4B5B-A8F6-E39BBCB64EA4}.Debug|Any CPU.ActiveCfg = Debug|x86
{B28FB5AB-98D9-4B5B-A8F6-E39BBCB64EA4}.Debug|Mixed Platforms.ActiveCfg = Debug|x86
{B28FB5AB-98D9-4B5B-A8F6-E39BBCB64EA4}.Debug|Mixed Platforms.Build.0 = Debug|x86
{B28FB5AB-98D9-4B5B-A8F6-E39BBCB64EA4}.Debug|x86.ActiveCfg = Debug|x86
{B28FB5AB-98D9-4B5B-A8F6-E39BBCB64EA4}.Debug|x86.Build.0 = Debug|x86
+ {B28FB5AB-98D9-4B5B-A8F6-E39BBCB64EA4}.MonoTouch|Any CPU.ActiveCfg = Release|x86
+ {B28FB5AB-98D9-4B5B-A8F6-E39BBCB64EA4}.MonoTouch|Mixed Platforms.ActiveCfg = Release|x86
+ {B28FB5AB-98D9-4B5B-A8F6-E39BBCB64EA4}.MonoTouch|Mixed Platforms.Build.0 = Release|x86
+ {B28FB5AB-98D9-4B5B-A8F6-E39BBCB64EA4}.MonoTouch|x86.ActiveCfg = Release|x86
+ {B28FB5AB-98D9-4B5B-A8F6-E39BBCB64EA4}.MonoTouch|x86.Build.0 = Release|x86
{B28FB5AB-98D9-4B5B-A8F6-E39BBCB64EA4}.Release|Any CPU.ActiveCfg = Release|x86
{B28FB5AB-98D9-4B5B-A8F6-E39BBCB64EA4}.Release|Mixed Platforms.ActiveCfg = Release|x86
{B28FB5AB-98D9-4B5B-A8F6-E39BBCB64EA4}.Release|Mixed Platforms.Build.0 = Release|x86
{B28FB5AB-98D9-4B5B-A8F6-E39BBCB64EA4}.Release|x86.ActiveCfg = Release|x86
{B28FB5AB-98D9-4B5B-A8F6-E39BBCB64EA4}.Release|x86.Build.0 = Release|x86
+ {B28FB5AB-98D9-4B5B-A8F6-E39BBCB64EA4}.STATIC_ONLY NO_EXPRESSIONS|Any CPU.ActiveCfg = Release|x86
+ {B28FB5AB-98D9-4B5B-A8F6-E39BBCB64EA4}.STATIC_ONLY NO_EXPRESSIONS|Mixed Platforms.ActiveCfg = Release|x86
+ {B28FB5AB-98D9-4B5B-A8F6-E39BBCB64EA4}.STATIC_ONLY NO_EXPRESSIONS|Mixed Platforms.Build.0 = Release|x86
+ {B28FB5AB-98D9-4B5B-A8F6-E39BBCB64EA4}.STATIC_ONLY NO_EXPRESSIONS|x86.ActiveCfg = Release|x86
+ {B28FB5AB-98D9-4B5B-A8F6-E39BBCB64EA4}.STATIC_ONLY NO_EXPRESSIONS|x86.Build.0 = Release|x86
{83A9D87F-E7AA-40D7-8403-4A8BDF09357C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{83A9D87F-E7AA-40D7-8403-4A8BDF09357C}.Debug|Any CPU.Build.0 = Debug|Any CPU
{83A9D87F-E7AA-40D7-8403-4A8BDF09357C}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU
{83A9D87F-E7AA-40D7-8403-4A8BDF09357C}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU
{83A9D87F-E7AA-40D7-8403-4A8BDF09357C}.Debug|x86.ActiveCfg = Debug|Any CPU
+ {83A9D87F-E7AA-40D7-8403-4A8BDF09357C}.MonoTouch|Any CPU.ActiveCfg = Release|Any CPU
+ {83A9D87F-E7AA-40D7-8403-4A8BDF09357C}.MonoTouch|Any CPU.Build.0 = Release|Any CPU
+ {83A9D87F-E7AA-40D7-8403-4A8BDF09357C}.MonoTouch|Mixed Platforms.ActiveCfg = Release|Any CPU
+ {83A9D87F-E7AA-40D7-8403-4A8BDF09357C}.MonoTouch|Mixed Platforms.Build.0 = Release|Any CPU
+ {83A9D87F-E7AA-40D7-8403-4A8BDF09357C}.MonoTouch|x86.ActiveCfg = Release|Any CPU
{83A9D87F-E7AA-40D7-8403-4A8BDF09357C}.Release|Any CPU.ActiveCfg = Release|Any CPU
{83A9D87F-E7AA-40D7-8403-4A8BDF09357C}.Release|Any CPU.Build.0 = Release|Any CPU
{83A9D87F-E7AA-40D7-8403-4A8BDF09357C}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
{83A9D87F-E7AA-40D7-8403-4A8BDF09357C}.Release|Mixed Platforms.Build.0 = Release|Any CPU
{83A9D87F-E7AA-40D7-8403-4A8BDF09357C}.Release|x86.ActiveCfg = Release|Any CPU
+ {83A9D87F-E7AA-40D7-8403-4A8BDF09357C}.STATIC_ONLY NO_EXPRESSIONS|Any CPU.ActiveCfg = Release|Any CPU
+ {83A9D87F-E7AA-40D7-8403-4A8BDF09357C}.STATIC_ONLY NO_EXPRESSIONS|Any CPU.Build.0 = Release|Any CPU
+ {83A9D87F-E7AA-40D7-8403-4A8BDF09357C}.STATIC_ONLY NO_EXPRESSIONS|Mixed Platforms.ActiveCfg = Release|Any CPU
+ {83A9D87F-E7AA-40D7-8403-4A8BDF09357C}.STATIC_ONLY NO_EXPRESSIONS|Mixed Platforms.Build.0 = Release|Any CPU
+ {83A9D87F-E7AA-40D7-8403-4A8BDF09357C}.STATIC_ONLY NO_EXPRESSIONS|x86.ActiveCfg = Release|Any CPU
+ {AF99F19B-4C04-4F58-81EF-B092F1FCC540}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {AF99F19B-4C04-4F58-81EF-B092F1FCC540}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {AF99F19B-4C04-4F58-81EF-B092F1FCC540}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU
+ {AF99F19B-4C04-4F58-81EF-B092F1FCC540}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU
+ {AF99F19B-4C04-4F58-81EF-B092F1FCC540}.Debug|x86.ActiveCfg = Debug|Any CPU
+ {AF99F19B-4C04-4F58-81EF-B092F1FCC540}.MonoTouch|Any CPU.ActiveCfg = MonoTouch|Any CPU
+ {AF99F19B-4C04-4F58-81EF-B092F1FCC540}.MonoTouch|Any CPU.Build.0 = MonoTouch|Any CPU
+ {AF99F19B-4C04-4F58-81EF-B092F1FCC540}.MonoTouch|Mixed Platforms.ActiveCfg = MonoTouch|Any CPU
+ {AF99F19B-4C04-4F58-81EF-B092F1FCC540}.MonoTouch|Mixed Platforms.Build.0 = MonoTouch|Any CPU
+ {AF99F19B-4C04-4F58-81EF-B092F1FCC540}.MonoTouch|x86.ActiveCfg = MonoTouch|Any CPU
+ {AF99F19B-4C04-4F58-81EF-B092F1FCC540}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {AF99F19B-4C04-4F58-81EF-B092F1FCC540}.Release|Any CPU.Build.0 = Release|Any CPU
+ {AF99F19B-4C04-4F58-81EF-B092F1FCC540}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
+ {AF99F19B-4C04-4F58-81EF-B092F1FCC540}.Release|Mixed Platforms.Build.0 = Release|Any CPU
+ {AF99F19B-4C04-4F58-81EF-B092F1FCC540}.Release|x86.ActiveCfg = Release|Any CPU
+ {AF99F19B-4C04-4F58-81EF-B092F1FCC540}.STATIC_ONLY NO_EXPRESSIONS|Any CPU.ActiveCfg = STATIC_ONLY NO_EXPRESSIONS|Any CPU
+ {AF99F19B-4C04-4F58-81EF-B092F1FCC540}.STATIC_ONLY NO_EXPRESSIONS|Any CPU.Build.0 = STATIC_ONLY NO_EXPRESSIONS|Any CPU
+ {AF99F19B-4C04-4F58-81EF-B092F1FCC540}.STATIC_ONLY NO_EXPRESSIONS|Mixed Platforms.ActiveCfg = STATIC_ONLY NO_EXPRESSIONS|Any CPU
+ {AF99F19B-4C04-4F58-81EF-B092F1FCC540}.STATIC_ONLY NO_EXPRESSIONS|Mixed Platforms.Build.0 = STATIC_ONLY NO_EXPRESSIONS|Any CPU
+ {AF99F19B-4C04-4F58-81EF-B092F1FCC540}.STATIC_ONLY NO_EXPRESSIONS|x86.ActiveCfg = STATIC_ONLY NO_EXPRESSIONS|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
View
@@ -0,0 +1,12 @@
+namespace Metsys.Redis
+{
+ public class Commands
+ {
+ public static readonly byte[] Get = Encoding.GetBytes("GET");
+ public static readonly byte[] Incr = Encoding.GetBytes("INCR");
+ public static readonly byte[] IncrBy = Encoding.GetBytes("INCRBY");
+ public static readonly byte[] Del = Encoding.GetBytes("DEL");
+ public static readonly byte[] Select = Encoding.GetBytes("SELECT");
+ public static readonly byte[] FlushDb = Encoding.GetBytes("FLUSHDB");
+ }
+}
@@ -37,6 +37,7 @@
<Reference Include="System.Core" />
</ItemGroup>
<ItemGroup>
+ <Compile Include="Commands.cs" />
<Compile Include="Configuration.cs" />
<Compile Include="Connections\Connection.cs" />
<Compile Include="Connections\ConnectionInfo.cs" />
@@ -2,6 +2,7 @@ namespace Metsys.Redis
{
public class DynamicBuffer
{
+ private const int _smallBufferLength = 4096;
private readonly byte[] _smallBuffer;
private byte[] _dynamicBuffer;
private int _length;
@@ -18,13 +19,13 @@ public int Length
public DynamicBuffer()
{
- _smallBuffer = new byte[4092];
+ _smallBuffer = new byte[_smallBufferLength];
}
public void SetLength(int length)
{
_length = length;
- if (length > _smallBuffer.Length && (_dynamicBuffer == null || length > _dynamicBuffer.Length))
+ if (length > _smallBufferLength && (_dynamicBuffer == null || length > _dynamicBuffer.Length))
{
_dynamicBuffer = new byte[length];
}
@@ -22,8 +22,8 @@ public static DynamicBuffer Serialize(byte[] command, DynamicBuffer dynamicBuffe
dynamicBuffer.SetLength(length);
var buffer = dynamicBuffer.Buffer;
var offset = 0;
- offset = WriteString(buffer, offset, parameterValues, _argumentCountMarker);
- offset = WriteString(buffer, offset, commandValue, _argumentBytesMarker);
+ offset = WriteFastString(buffer, offset, parameterValues, _argumentCountMarker);
+ offset = WriteFastString(buffer, offset, commandValue, _argumentBytesMarker);
offset = WriteBytes(buffer, offset, command, command.Length);
foreach(var parameter in parameters)
@@ -45,12 +45,28 @@ private static int WriteString(byte[] buffer, int offset, string value)
return WriteLineTerminator(buffer, offset);
}
+ private static int WriteFastString(byte[] buffer, int offset, string value, byte marker)
+ {
+ buffer[offset] = marker;
+ return WriteFastString(buffer, offset + 1, value);
+ }
+
+ private static int WriteFastString(byte[] buffer, int offset, string value)
+ {
+ var length = value.Length;
+ for (var i = 0; i < length; ++i)
+ {
+ buffer[offset++] = (byte) value[i];
+ }
+ return WriteLineTerminator(buffer, offset);
+ }
+
private static int WriteValue(byte[] buffer, int offset, object value)
{
if (value is string)
{
var v = (string)value;
- offset = WriteString(buffer, offset, v.Length.ToString(), _argumentBytesMarker);
+ offset = WriteFastString(buffer, offset, v.Length.ToString(), _argumentBytesMarker);
return WriteString(buffer, offset, v);
}
else
@@ -70,8 +86,8 @@ private static int WriteBytes(byte[] buffer, int offset, byte[] value, int lengt
private static int WriteLineTerminator(byte[] buffer, int offset)
{
- buffer[offset] = (byte) '\r';
- buffer[offset+1] = (byte) '\n';
+ buffer[offset] = 0x0D;
+ buffer[offset + 1] = 0x0A;
return offset + 2;
}
View
@@ -18,48 +18,42 @@ internal Redis(RedisManager manager)
_dynamicBuffer = new DynamicBuffer();
}
- private static readonly byte[] _getCommand = Encoding.GetBytes("GET");
+
public T Get<T>(string key)
{
- var length = Send(Writer.Serialize(_getCommand, _dynamicBuffer, key), Reader.Bulk);
+ var length = Send(Writer.Serialize(Commands.Get, _dynamicBuffer, key), Reader.Bulk);
return length == 0 ? default(T) : Serializer.Deserialize<T>(_dynamicBuffer);
}
- private static readonly byte[] _incrCommand = Encoding.GetBytes("INCR");
public long Incr(string key)
{
- return Send(Writer.Serialize(_incrCommand, _dynamicBuffer, key), Reader.Integer);
+ return Send(Writer.Serialize(Commands.Incr, _dynamicBuffer, key), Reader.Integer);
}
- private static readonly byte[] _incrByCommand = Encoding.GetBytes("INCRBY");
public long IncrBy(string key, int value)
{
- return Send(Writer.Serialize(_incrByCommand, _dynamicBuffer, key, value.ToString()), Reader.Integer);
+ return Send(Writer.Serialize(Commands.IncrBy, _dynamicBuffer, key, value.ToString()), Reader.Integer);
}
- private static readonly byte[] _delCommand = Encoding.GetBytes("DEL");
public long Del(params string[] key)
{
- return Send(Writer.Serialize(_delCommand, _dynamicBuffer, key), Reader.Integer);
+ return Send(Writer.Serialize(Commands.Del, _dynamicBuffer, key), Reader.Integer);
}
- private static readonly byte[] _flushDbCommand = Encoding.GetBytes("FLUSHDB");
public void FlushDb()
{
- Send(Writer.Serialize(_flushDbCommand, _dynamicBuffer), Reader.Status);
+ Send(Writer.Serialize(Commands.FlushDb, _dynamicBuffer), Reader.Status);
}
-
public void Select(int database)
{
Select(database, true);
}
- private static readonly byte[] _selectCommand = Encoding.GetBytes("SELECT");
private void Select(int database, bool flagAsDifferent)
{
if (flagAsDifferent) { _selectedADatabase = true; }
- Send(Writer.Serialize(_selectCommand, _dynamicBuffer, database.ToString()), Reader.Status);
+ Send(Writer.Serialize(Commands.Select, _dynamicBuffer, database.ToString()), Reader.Status);
}
private T Send<T>(DynamicBuffer context, Func<Stream, DynamicBuffer, T> callback)
@@ -30,7 +30,7 @@ public static IRedisManager Configure(Action<IConfiguration> action)
private RedisManager()
{
_redisPool = new ConcurrentQueue<IRedis>();
- for(var i = 0; i < 25; ++i)
+ for(var i = 0; i < 4; ++i)
{
_redisPool.Enqueue(new Redis(this));
}

0 comments on commit 7a64aad

Please sign in to comment.