Commit ad868210 authored by kevin-montrose's avatar kevin-montrose

squash named-script-parameters branch into a single commit

parent dcf546f4
...@@ -16,3 +16,4 @@ Mono/ ...@@ -16,3 +16,4 @@ Mono/
redis-cli.exe redis-cli.exe
Redis Configs/*.dat Redis Configs/*.dat
RedisQFork*.dat RedisQFork*.dat
StackExchange.Redis.*.zip
\ No newline at end of file
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
using System.Diagnostics; using System.Diagnostics;
using NUnit.Framework; using NUnit.Framework;
using System.Linq; using System.Linq;
using System.IO;
namespace StackExchange.Redis.Tests namespace StackExchange.Redis.Tests
{ {
...@@ -169,5 +170,345 @@ public void TestCallByHash() ...@@ -169,5 +170,345 @@ public void TestCallByHash()
} }
} }
[Test]
public void SimpleLuaScript()
{
const string Script = "return @ident";
using(var conn = Create(allowAdmin: true))
{
var server = conn.GetServer(PrimaryServer, PrimaryPort);
server.FlushAllDatabases();
server.ScriptFlush();
var prepared = LuaScript.Prepare(Script);
var db = conn.GetDatabase();
{
var val = prepared.Evaluate(db, new { ident = "hello" });
Assert.AreEqual("hello", (string)val);
}
{
var val = prepared.Evaluate(db, new { ident = 123 });
Assert.AreEqual(123, (int)val);
}
{
var val = prepared.Evaluate(db, new { ident = 123L });
Assert.AreEqual(123L, (long)val);
}
{
var val = prepared.Evaluate(db, new { ident = 1.1 });
Assert.AreEqual(1.1, (double)val);
}
{
var val = prepared.Evaluate(db, new { ident = true });
Assert.AreEqual(true, (bool)val);
}
{
var val = prepared.Evaluate(db, new { ident = new byte[] { 4, 5, 6 } });
Assert.IsTrue(new byte [] { 4, 5, 6}.SequenceEqual((byte[])val));
}
}
}
[Test]
public void LuaScriptWithKeys()
{
const string Script = "redis.call('set', @key, @value)";
using (var conn = Create(allowAdmin: true))
{
var server = conn.GetServer(PrimaryServer, PrimaryPort);
server.FlushAllDatabases();
server.ScriptFlush();
var script = LuaScript.Prepare(Script);
var db = conn.GetDatabase();
var p = new { key = (RedisKey)"testkey", value = 123 };
script.Evaluate(db, p);
var val = db.StringGet("testkey");
Assert.AreEqual(123, (int)val);
// no super clean way to extract this; so just abuse InternalsVisibleTo
RedisKey[] keys;
RedisValue[] args;
script.ExtractParameters(p, null, out keys, out args);
Assert.IsNotNull(keys);
Assert.AreEqual(1, keys.Length);
Assert.AreEqual("testkey", (string)keys[0]);
}
}
[Test]
public void NoInlineReplacement()
{
const string Script = "redis.call('set', @key, 'hello@example')";
using (var conn = Create(allowAdmin: true))
{
var server = conn.GetServer(PrimaryServer, PrimaryPort);
server.FlushAllDatabases();
server.ScriptFlush();
var script = LuaScript.Prepare(Script);
Assert.AreEqual("redis.call('set', ARGV[1], 'hello@example')", script.ExecutableScript);
var db = conn.GetDatabase();
var p = new { key = (RedisKey)"key" };
script.Evaluate(db, p);
var val = db.StringGet("key");
Assert.AreEqual("hello@example", (string)val);
}
}
[Test]
public void EscapeReplacement()
{
const string Script = "redis.call('set', @key, @@escapeMe)";
var script = LuaScript.Prepare(Script);
Assert.AreEqual("redis.call('set', ARGV[1], @escapeMe)", script.ExecutableScript);
}
[Test]
public void SimpleLoadedLuaScript()
{
const string Script = "return @ident";
using (var conn = Create(allowAdmin: true))
{
var server = conn.GetServer(PrimaryServer, PrimaryPort);
server.FlushAllDatabases();
server.ScriptFlush();
var prepared = LuaScript.Prepare(Script);
var loaded = prepared.Load(server);
var db = conn.GetDatabase();
{
var val = loaded.Evaluate(db, new { ident = "hello" });
Assert.AreEqual("hello", (string)val);
}
{
var val = loaded.Evaluate(db, new { ident = 123 });
Assert.AreEqual(123, (int)val);
}
{
var val = loaded.Evaluate(db, new { ident = 123L });
Assert.AreEqual(123L, (long)val);
}
{
var val = loaded.Evaluate(db, new { ident = 1.1 });
Assert.AreEqual(1.1, (double)val);
}
{
var val = loaded.Evaluate(db, new { ident = true });
Assert.AreEqual(true, (bool)val);
}
{
var val = loaded.Evaluate(db, new { ident = new byte[] { 4, 5, 6 } });
Assert.IsTrue(new byte[] { 4, 5, 6 }.SequenceEqual((byte[])val));
}
}
}
[Test]
public void LoadedLuaScriptWithKeys()
{
const string Script = "redis.call('set', @key, @value)";
using (var conn = Create(allowAdmin: true))
{
var server = conn.GetServer(PrimaryServer, PrimaryPort);
server.FlushAllDatabases();
server.ScriptFlush();
var script = LuaScript.Prepare(Script);
var prepared = script.Load(server);
var db = conn.GetDatabase();
var p = new { key = (RedisKey)"testkey", value = 123 };
prepared.Evaluate(db, p);
var val = db.StringGet("testkey");
Assert.AreEqual(123, (int)val);
// no super clean way to extract this; so just abuse InternalsVisibleTo
RedisKey[] keys;
RedisValue[] args;
prepared.Original.ExtractParameters(p, null, out keys, out args);
Assert.IsNotNull(keys);
Assert.AreEqual(1, keys.Length);
Assert.AreEqual("testkey", (string)keys[0]);
}
}
[Test]
public void PurgeLuaScriptCache()
{
const string Script = "redis.call('set', @PurgeLuaScriptCacheKey, @PurgeLuaScriptCacheValue)";
var first = LuaScript.Prepare(Script);
var fromCache = LuaScript.Prepare(Script);
Assert.IsTrue(object.ReferenceEquals(first, fromCache));
LuaScript.PurgeCache();
var shouldBeNew = LuaScript.Prepare(Script);
Assert.IsFalse(object.ReferenceEquals(first, shouldBeNew));
}
static void _PurgeLuaScriptOnFinalize(string script)
{
var first = LuaScript.Prepare(script);
var fromCache = LuaScript.Prepare(script);
Assert.IsTrue(object.ReferenceEquals(first, fromCache));
Assert.AreEqual(1, LuaScript.GetCachedScriptCount());
}
[Test]
public void PurgeLuaScriptOnFinalize()
{
const string Script = "redis.call('set', @PurgeLuaScriptOnFinalizeKey, @PurgeLuaScriptOnFinalizeValue)";
LuaScript.PurgeCache();
Assert.AreEqual(0, LuaScript.GetCachedScriptCount());
// This has to be a separate method to guarantee that the created LuaScript objects go out of scope,
// and are thus available to be GC'd
_PurgeLuaScriptOnFinalize(Script);
GC.Collect(2, GCCollectionMode.Forced, blocking: true);
GC.WaitForPendingFinalizers();
Assert.AreEqual(0, LuaScript.GetCachedScriptCount());
var shouldBeNew = LuaScript.Prepare(Script);
Assert.AreEqual(1, LuaScript.GetCachedScriptCount());
}
[Test]
public void IDatabaseLuaScriptConvenienceMethods()
{
const string Script = "redis.call('set', @key, @value)";
using (var conn = Create(allowAdmin: true))
{
var script = LuaScript.Prepare(Script);
var db = conn.GetDatabase();
db.ScriptEvaluate(script, new { key = (RedisKey)"key", value = "value" });
var val = db.StringGet("key");
Assert.AreEqual("value", (string)val);
var prepared = script.Load(conn.GetServer(conn.GetEndPoints()[0]));
db.ScriptEvaluate(prepared, new { key = (RedisKey)"key2", value = "value2" });
var val2 = db.StringGet("key2");
Assert.AreEqual("value2", (string)val2);
}
}
[Test]
public void IServerLuaScriptConvenienceMethods()
{
const string Script = "redis.call('set', @key, @value)";
using (var conn = Create(allowAdmin: true))
{
var script = LuaScript.Prepare(Script);
var server = conn.GetServer(conn.GetEndPoints()[0]);
var db = conn.GetDatabase();
var prepared = server.ScriptLoad(script);
db.ScriptEvaluate(prepared, new { key = (RedisKey)"key3", value = "value3" });
var val = db.StringGet("key3");
Assert.AreEqual("value3", (string)val);
}
}
[Test]
public void LuaScriptPrefixedKeys()
{
const string Script = "redis.call('set', @key, @value)";
var prepared = LuaScript.Prepare(Script);
var p = new { key = (RedisKey)"key", value = "hello" };
// no super clean way to extract this; so just abuse InternalsVisibleTo
RedisKey[] keys;
RedisValue[] args;
prepared.ExtractParameters(p, "prefix-", out keys, out args);
Assert.IsNotNull(keys);
Assert.AreEqual(1, keys.Length);
Assert.AreEqual("prefix-key", (string)keys[0]);
Assert.AreEqual(2, args.Length);
Assert.AreEqual("prefix-key", (string)args[0]);
Assert.AreEqual("hello", (string)args[1]);
}
[Test]
public void LuaScriptWithWrappedDatabase()
{
const string Script = "redis.call('set', @key, @value)";
using (var conn = Create(allowAdmin: true))
{
var db = conn.GetDatabase(0);
var wrappedDb = StackExchange.Redis.KeyspaceIsolation.DatabaseExtensions.WithKeyPrefix(db, "prefix-");
var prepared = LuaScript.Prepare(Script);
wrappedDb.ScriptEvaluate(prepared, new { key = (RedisKey)"mykey", value = 123 });
var val1 = wrappedDb.StringGet("mykey");
Assert.AreEqual(123, (int)val1);
var val2 = db.StringGet("prefix-mykey");
Assert.AreEqual(123, (int)val2);
var val3 = db.StringGet("mykey");
Assert.IsTrue(val3.IsNull);
}
}
[Test]
public void LoadedLuaScriptWithWrappedDatabase()
{
const string Script = "redis.call('set', @key, @value)";
using (var conn = Create(allowAdmin: true))
{
var db = conn.GetDatabase(0);
var wrappedDb = StackExchange.Redis.KeyspaceIsolation.DatabaseExtensions.WithKeyPrefix(db, "prefix2-");
var server = conn.GetServer(conn.GetEndPoints()[0]);
var prepared = LuaScript.Prepare(Script).Load(server);
wrappedDb.ScriptEvaluate(prepared, new { key = (RedisKey)"mykey", value = 123 });
var val1 = wrappedDb.StringGet("mykey");
Assert.AreEqual(123, (int)val1);
var val2 = db.StringGet("prefix2-mykey");
Assert.AreEqual(123, (int)val2);
var val3 = db.StringGet("mykey");
Assert.IsTrue(val3.IsNull);
}
}
} }
} }
...@@ -74,6 +74,7 @@ ...@@ -74,6 +74,7 @@
<Compile Include="StackExchange\Redis\HashEntry.cs" /> <Compile Include="StackExchange\Redis\HashEntry.cs" />
<Compile Include="StackExchange\Redis\InternalErrorEventArgs.cs" /> <Compile Include="StackExchange\Redis\InternalErrorEventArgs.cs" />
<Compile Include="StackExchange\Redis\MigrateOptions.cs" /> <Compile Include="StackExchange\Redis\MigrateOptions.cs" />
<Compile Include="StackExchange\Redis\LuaScript.cs" />
<Compile Include="StackExchange\Redis\RedisChannel.cs" /> <Compile Include="StackExchange\Redis\RedisChannel.cs" />
<Compile Include="StackExchange\Redis\Bitwise.cs" /> <Compile Include="StackExchange\Redis\Bitwise.cs" />
<Compile Include="StackExchange\Redis\ClientFlags.cs" /> <Compile Include="StackExchange\Redis\ClientFlags.cs" />
...@@ -139,6 +140,7 @@ ...@@ -139,6 +140,7 @@
<Compile Include="StackExchange\Redis\ResultProcessor.cs" /> <Compile Include="StackExchange\Redis\ResultProcessor.cs" />
<Compile Include="StackExchange\Redis\RedisSubscriber.cs" /> <Compile Include="StackExchange\Redis\RedisSubscriber.cs" />
<Compile Include="StackExchange\Redis\ResultType.cs" /> <Compile Include="StackExchange\Redis\ResultType.cs" />
<Compile Include="StackExchange\Redis\ScriptParameterMapper.cs" />
<Compile Include="StackExchange\Redis\ServerCounters.cs" /> <Compile Include="StackExchange\Redis\ServerCounters.cs" />
<Compile Include="StackExchange\Redis\ServerEndPoint.cs" /> <Compile Include="StackExchange\Redis\ServerEndPoint.cs" />
<Compile Include="StackExchange\Redis\ServerSelectionStrategy.cs" /> <Compile Include="StackExchange\Redis\ServerSelectionStrategy.cs" />
......
...@@ -68,6 +68,7 @@ ...@@ -68,6 +68,7 @@
<Compile Include="StackExchange\Redis\HashEntry.cs" /> <Compile Include="StackExchange\Redis\HashEntry.cs" />
<Compile Include="StackExchange\Redis\InternalErrorEventArgs.cs" /> <Compile Include="StackExchange\Redis\InternalErrorEventArgs.cs" />
<Compile Include="StackExchange\Redis\MigrateOptions.cs" /> <Compile Include="StackExchange\Redis\MigrateOptions.cs" />
<Compile Include="StackExchange\Redis\LuaScript.cs" />
<Compile Include="StackExchange\Redis\RedisChannel.cs" /> <Compile Include="StackExchange\Redis\RedisChannel.cs" />
<Compile Include="StackExchange\Redis\Bitwise.cs" /> <Compile Include="StackExchange\Redis\Bitwise.cs" />
<Compile Include="StackExchange\Redis\ClientFlags.cs" /> <Compile Include="StackExchange\Redis\ClientFlags.cs" />
...@@ -133,6 +134,7 @@ ...@@ -133,6 +134,7 @@
<Compile Include="StackExchange\Redis\ResultProcessor.cs" /> <Compile Include="StackExchange\Redis\ResultProcessor.cs" />
<Compile Include="StackExchange\Redis\RedisSubscriber.cs" /> <Compile Include="StackExchange\Redis\RedisSubscriber.cs" />
<Compile Include="StackExchange\Redis\ResultType.cs" /> <Compile Include="StackExchange\Redis\ResultType.cs" />
<Compile Include="StackExchange\Redis\ScriptParameterMapper.cs" />
<Compile Include="StackExchange\Redis\ServerCounters.cs" /> <Compile Include="StackExchange\Redis\ServerCounters.cs" />
<Compile Include="StackExchange\Redis\ServerEndPoint.cs" /> <Compile Include="StackExchange\Redis\ServerEndPoint.cs" />
<Compile Include="StackExchange\Redis\ServerSelectionStrategy.cs" /> <Compile Include="StackExchange\Redis\ServerSelectionStrategy.cs" />
......
...@@ -51,6 +51,30 @@ public static ConfiguredTaskAwaitable<T> ForAwait<T>(this Task<T> task) ...@@ -51,6 +51,30 @@ public static ConfiguredTaskAwaitable<T> ForAwait<T>(this Task<T> task)
/// </summary> /// </summary>
public sealed partial class ConnectionMultiplexer : IDisposable public sealed partial class ConnectionMultiplexer : IDisposable
{ {
private static TaskFactory _factory = null;
/// <summary>
/// Provides a way of overriding the default Task Factory. If not set, it will use the default Task.Factory.
/// Useful when top level code sets it's own factory which may interfere with Redis queries.
/// </summary>
public static TaskFactory Factory
{
get
{
if (_factory != null)
{
return _factory;
}
return Task.Factory;
}
set
{
_factory = value;
}
}
/// <summary> /// <summary>
/// Get summary statistics associates with this server /// Get summary statistics associates with this server
/// </summary> /// </summary>
...@@ -738,7 +762,7 @@ private static ConnectionMultiplexer ConnectImpl(Func<ConnectionMultiplexer> mul ...@@ -738,7 +762,7 @@ private static ConnectionMultiplexer ConnectImpl(Func<ConnectionMultiplexer> mul
killMe = muxer; killMe = muxer;
// note that task has timeouts internally, so it might take *just over* the regular timeout // note that task has timeouts internally, so it might take *just over* the regular timeout
// wrap into task to force async execution // wrap into task to force async execution
var task = Task.Factory.StartNew(() => { return muxer.ReconfigureAsync(true, false, log, null, "connect").Result; }); var task = Factory.StartNew(() => { return muxer.ReconfigureAsync(true, false, log, null, "connect").Result; });
if (!task.Wait(muxer.SyncConnectTimeout(true))) if (!task.Wait(muxer.SyncConnectTimeout(true)))
{ {
...@@ -1472,9 +1496,38 @@ private ServerEndPoint SelectServerByElection(ServerEndPoint[] servers, string e ...@@ -1472,9 +1496,38 @@ private ServerEndPoint SelectServerByElection(ServerEndPoint[] servers, string e
return servers[i]; return servers[i];
} }
LogLocked(log, "...but we couldn't find that"); LogLocked(log, "...but we couldn't find that");
var deDottedEndpoint = DeDotifyHost(endpoint);
for (int i = 0; i < servers.Length; i++)
{
if (string.Equals(DeDotifyHost(Format.ToString(servers[i].EndPoint)), deDottedEndpoint, StringComparison.OrdinalIgnoreCase))
{
LogLocked(log, "...but we did find instead: {0}", deDottedEndpoint);
return servers[i];
}
}
return null; return null;
} }
static string DeDotifyHost(string input)
{
if (string.IsNullOrWhiteSpace(input)) return input; // GIGO
if (!char.IsLetter(input[0])) return input; // need first char to be alpha for this to work
int periodPosition = input.IndexOf('.');
if (periodPosition <= 0) return input; // no period or starts with a period? nothing useful to split
int colonPosition = input.IndexOf(':');
if (colonPosition > 0)
{ // has a port specifier
return input.Substring(0, periodPosition) + input.Substring(colonPosition);
}
else
{
return input.Substring(0, periodPosition);
}
}
internal void UpdateClusterRange(ClusterConfiguration configuration) internal void UpdateClusterRange(ClusterConfiguration configuration)
{ {
if (configuration == null) return; if (configuration == null) return;
...@@ -1852,5 +1905,4 @@ public Task<long> PublishReconfigureAsync(CommandFlags flags = CommandFlags.None ...@@ -1852,5 +1905,4 @@ public Task<long> PublishReconfigureAsync(CommandFlags flags = CommandFlags.None
return GetSubscriber().PublishAsync(channel, RedisLiterals.Wildcard, flags); return GetSubscriber().PublishAsync(channel, RedisLiterals.Wildcard, flags);
} }
} }
} }
...@@ -452,6 +452,7 @@ public interface IDatabase : IRedis, IDatabaseAsync ...@@ -452,6 +452,7 @@ public interface IDatabase : IRedis, IDatabaseAsync
/// <returns>the number of clients that received the message.</returns> /// <returns>the number of clients that received the message.</returns>
/// <remarks>http://redis.io/commands/publish</remarks> /// <remarks>http://redis.io/commands/publish</remarks>
long Publish(RedisChannel channel, RedisValue message, CommandFlags flags = CommandFlags.None); long Publish(RedisChannel channel, RedisValue message, CommandFlags flags = CommandFlags.None);
/// <summary> /// <summary>
/// Execute a Lua script against the server /// Execute a Lua script against the server
/// </summary> /// </summary>
...@@ -466,6 +467,19 @@ public interface IDatabase : IRedis, IDatabaseAsync ...@@ -466,6 +467,19 @@ public interface IDatabase : IRedis, IDatabaseAsync
/// <returns>A dynamic representation of the script's result</returns> /// <returns>A dynamic representation of the script's result</returns>
RedisResult ScriptEvaluate(byte[] hash, RedisKey[] keys = null, RedisValue[] values = null, CommandFlags flags = CommandFlags.None); RedisResult ScriptEvaluate(byte[] hash, RedisKey[] keys = null, RedisValue[] values = null, CommandFlags flags = CommandFlags.None);
/// <summary>
/// Execute a lua script against the server, using previously prepared script.
/// Named parameters, if any, are provided by the `parameters` object.
/// </summary>
RedisResult ScriptEvaluate(LuaScript script, object parameters = null, CommandFlags flags = CommandFlags.None);
/// <summary>
/// Execute a lua script against the server, using previously prepared and loaded script.
/// This method sends only the SHA1 hash of the lua script to Redis.
/// Named parameters, if any, are provided by the `parameters` object.
/// </summary>
RedisResult ScriptEvaluate(LoadedLuaScript script, object parameters = null, CommandFlags flags = CommandFlags.None);
/// <summary> /// <summary>
/// Add the specified member to the set stored at key. Specified members that are already a member of this set are ignored. If key does not exist, a new set is created before adding the specified members. /// Add the specified member to the set stored at key. Specified members that are already a member of this set are ignored. If key does not exist, a new set is created before adding the specified members.
/// </summary> /// </summary>
......
...@@ -439,6 +439,19 @@ public interface IDatabaseAsync : IRedisAsync ...@@ -439,6 +439,19 @@ public interface IDatabaseAsync : IRedisAsync
/// <returns>A dynamic representation of the script's result</returns> /// <returns>A dynamic representation of the script's result</returns>
Task<RedisResult> ScriptEvaluateAsync(byte[] hash, RedisKey[] keys = null, RedisValue[] values = null, CommandFlags flags = CommandFlags.None); Task<RedisResult> ScriptEvaluateAsync(byte[] hash, RedisKey[] keys = null, RedisValue[] values = null, CommandFlags flags = CommandFlags.None);
/// <summary>
/// Execute a lua script against the server, using previously prepared script.
/// Named parameters, if any, are provided by the `parameters` object.
/// </summary>
Task<RedisResult> ScriptEvaluateAsync(LuaScript script, object parameters = null, CommandFlags flags = CommandFlags.None);
/// <summary>
/// Execute a lua script against the server, using previously prepared and loaded script.
/// This method sends only the SHA1 hash of the lua script to Redis.
/// Named parameters, if any, are provided by the `parameters` object.
/// </summary>
Task<RedisResult> ScriptEvaluateAsync(LoadedLuaScript script, object parameters = null, CommandFlags flags = CommandFlags.None);
/// <summary> /// <summary>
/// Add the specified member to the set stored at key. Specified members that are already a member of this set are ignored. If key does not exist, a new set is created before adding the specified members. /// Add the specified member to the set stored at key. Specified members that are already a member of this set are ignored. If key does not exist, a new set is created before adding the specified members.
/// </summary> /// </summary>
......
...@@ -314,11 +314,21 @@ public partial interface IServer : IRedis ...@@ -314,11 +314,21 @@ public partial interface IServer : IRedis
/// </summary> /// </summary>
byte[] ScriptLoad(string script, CommandFlags flags = CommandFlags.None); byte[] ScriptLoad(string script, CommandFlags flags = CommandFlags.None);
/// <summary>
/// Explicitly defines a script on the server
/// </summary>
LoadedLuaScript ScriptLoad(LuaScript script, CommandFlags flags = CommandFlags.None);
/// <summary> /// <summary>
/// Explicitly defines a script on the server /// Explicitly defines a script on the server
/// </summary> /// </summary>
Task<byte[]> ScriptLoadAsync(string script, CommandFlags flags = CommandFlags.None); Task<byte[]> ScriptLoadAsync(string script, CommandFlags flags = CommandFlags.None);
/// <summary>
/// Explicitly defines a script on the server
/// </summary>
Task<LoadedLuaScript> ScriptLoadAsync(LuaScript script, CommandFlags flags = CommandFlags.None);
/// <summary>Asks the redis server to shutdown, killing all connections. Please FULLY read the notes on the SHUTDOWN command.</summary> /// <summary>Asks the redis server to shutdown, killing all connections. Please FULLY read the notes on the SHUTDOWN command.</summary>
/// <remarks>http://redis.io/commands/shutdown</remarks> /// <remarks>http://redis.io/commands/shutdown</remarks>
void Shutdown(ShutdownMode shutdownMode = ShutdownMode.Default, CommandFlags flags = CommandFlags.None); void Shutdown(ShutdownMode shutdownMode = ShutdownMode.Default, CommandFlags flags = CommandFlags.None);
......
...@@ -323,6 +323,18 @@ public RedisResult ScriptEvaluate(string script, RedisKey[] keys = null, RedisVa ...@@ -323,6 +323,18 @@ public RedisResult ScriptEvaluate(string script, RedisKey[] keys = null, RedisVa
return this.Inner.ScriptEvaluate(script, this.ToInner(keys), values, flags); return this.Inner.ScriptEvaluate(script, this.ToInner(keys), values, flags);
} }
public RedisResult ScriptEvaluate(LuaScript script, object parameters = null, CommandFlags flags = CommandFlags.None)
{
// TODO: The return value could contain prefixed keys. It might make sense to 'unprefix' those?
return script.Evaluate(this.Inner, parameters, Prefix, flags);
}
public RedisResult ScriptEvaluate(LoadedLuaScript script, object parameters = null, CommandFlags flags = CommandFlags.None)
{
// TODO: The return value could contain prefixed keys. It might make sense to 'unprefix' those?
return script.Evaluate(this.Inner, parameters, Prefix, flags);
}
public long SetAdd(RedisKey key, RedisValue[] values, CommandFlags flags = CommandFlags.None) public long SetAdd(RedisKey key, RedisValue[] values, CommandFlags flags = CommandFlags.None)
{ {
return this.Inner.SetAdd(this.ToInner(key), values, flags); return this.Inner.SetAdd(this.ToInner(key), values, flags);
......
...@@ -334,6 +334,16 @@ public Task<RedisResult> ScriptEvaluateAsync(string script, RedisKey[] keys = nu ...@@ -334,6 +334,16 @@ public Task<RedisResult> ScriptEvaluateAsync(string script, RedisKey[] keys = nu
return this.Inner.ScriptEvaluateAsync(script, this.ToInner(keys), values, flags); return this.Inner.ScriptEvaluateAsync(script, this.ToInner(keys), values, flags);
} }
public Task<RedisResult> ScriptEvaluateAsync(LuaScript script, object parameters = null, CommandFlags flags = CommandFlags.None)
{
throw new NotImplementedException();
}
public Task<RedisResult> ScriptEvaluateAsync(LoadedLuaScript script, object parameters = null, CommandFlags flags = CommandFlags.None)
{
throw new NotImplementedException();
}
public Task<long> SetAddAsync(RedisKey key, RedisValue[] values, CommandFlags flags = CommandFlags.None) public Task<long> SetAddAsync(RedisKey key, RedisValue[] values, CommandFlags flags = CommandFlags.None)
{ {
return this.Inner.SetAddAsync(this.ToInner(key), values, flags); return this.Inner.SetAddAsync(this.ToInner(key), values, flags);
......
using System;
using System.Collections;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace StackExchange.Redis
{
/// <summary>
/// Represents a Lua script that can be executed on Redis.
///
/// Unlike normal Redis Lua scripts, LuaScript can have named parameters (prefixed by a @).
/// Public fields and properties of the passed in object are treated as parameters.
///
/// Parameters of type RedisKey are sent to Redis as KEY (http://redis.io/commands/eval) in addition to arguments,
/// so as to play nicely with Redis Cluster.
///
/// All members of this class are thread safe.
/// </summary>
public sealed class LuaScript
{
// Since the mapping of "script text" -> LuaScript doesn't depend on any particular details of
// the redis connection itself, this cache is global.
static readonly ConcurrentDictionary<string, WeakReference> Cache = new ConcurrentDictionary<string, WeakReference>();
/// <summary>
/// The original Lua script that was used to create this.
/// </summary>
public string OriginalScript { get; private set; }
/// <summary>
/// The Lua script that will actually be sent to Redis for execution.
///
/// All @-prefixed parameter names have been replaced at this point.
/// </summary>
public string ExecutableScript { get; private set; }
// Arguments are in the order they have to passed to the script in
internal string[] Arguments { get; private set; }
bool HasArguments { get { return Arguments != null && Arguments.Length > 0; } }
Hashtable ParameterMappers;
internal LuaScript(string originalScript, string executableScript, string[] arguments)
{
OriginalScript = originalScript;
ExecutableScript = executableScript;
Arguments = arguments;
if (HasArguments)
{
ParameterMappers = new Hashtable();
}
}
/// <summary>
/// Finalizer, used to prompt cleanups of the script cache when
/// a LuaScript reference goes out of scope.
/// </summary>
~LuaScript()
{
try
{
WeakReference ignored;
Cache.TryRemove(OriginalScript, out ignored);
}
catch { }
}
/// <summary>
/// Invalidates the internal cache of LuaScript objects.
/// Existing LuaScripts will continue to work, but future calls to LuaScript.Prepare
/// return a new LuaScript instance.
/// </summary>
public static void PurgeCache()
{
Cache.Clear();
}
/// <summary>
/// Returns the number of cached LuaScripts.
/// </summary>
public static int GetCachedScriptCount()
{
return Cache.Count;
}
/// <summary>
/// Prepares a Lua script with named parameters to be run against any Redis instance.
/// </summary>
public static LuaScript Prepare(string script)
{
LuaScript ret;
WeakReference weakRef;
if (!Cache.TryGetValue(script, out weakRef) || (ret = (LuaScript)weakRef.Target) == null)
{
ret = ScriptParameterMapper.PrepareScript(script);
Cache[script] = new WeakReference(ret);
}
return ret;
}
internal void ExtractParameters(object ps, RedisKey? keyPrefix, out RedisKey[] keys, out RedisValue[] args)
{
if (HasArguments)
{
if (ps == null) throw new ArgumentNullException("ps", "Script requires parameters");
var psType = ps.GetType();
var mapper = (Func<object, RedisKey?, ScriptParameterMapper.ScriptParameters>)ParameterMappers[psType];
if (ps != null && mapper == null)
{
lock (ParameterMappers)
{
mapper = (Func<object, RedisKey?, ScriptParameterMapper.ScriptParameters>)ParameterMappers[psType];
if (mapper == null)
{
string missingMember;
string badMemberType;
if(!ScriptParameterMapper.IsValidParameterHash(psType, this, out missingMember, out badMemberType))
{
if (missingMember != null)
{
throw new ArgumentException("ps", "Expected [" + missingMember + "] to be a field or gettable property on [" + psType.FullName + "]");
}
throw new ArgumentException("ps", "Expected [" + badMemberType + "] on [" + psType.FullName + "] to be convertable to a RedisValue");
}
ParameterMappers[psType] = mapper = ScriptParameterMapper.GetParameterExtractor(psType, this);
}
}
}
var mapped = mapper(ps, keyPrefix);
keys = mapped.Keys;
args = mapped.Arguments;
}
else
{
keys = null;
args = null;
}
}
/// <summary>
/// Evaluates this LuaScript against the given database, extracting parameters from the passed in object if any.
/// </summary>
public RedisResult Evaluate(IDatabase db, object ps = null, RedisKey? withKeyPrefix = null, CommandFlags flags = CommandFlags.None)
{
RedisKey[] keys;
RedisValue[] args;
ExtractParameters(ps, withKeyPrefix, out keys, out args);
return db.ScriptEvaluate(ExecutableScript, keys, args, flags);
}
/// <summary>
/// Evaluates this LuaScript against the given database, extracting parameters from the passed in object if any.
/// </summary>
public Task<RedisResult> EvaluateAsync(IDatabaseAsync db, object ps = null, RedisKey? withKeyPrefix = null, CommandFlags flags = CommandFlags.None)
{
RedisKey[] keys;
RedisValue[] args;
ExtractParameters(ps, withKeyPrefix, out keys, out args);
return db.ScriptEvaluateAsync(ExecutableScript, keys, args, flags);
}
/// <summary>
/// Loads this LuaScript into the given IServer so it can be run with it's SHA1 hash, instead of
/// passing the full script on each Evaluate or EvaluateAsync call.
///
/// Note: the FireAndForget command flag cannot be set
/// </summary>
public LoadedLuaScript Load(IServer server, CommandFlags flags = CommandFlags.None)
{
if (flags.HasFlag(CommandFlags.FireAndForget))
{
throw new ArgumentOutOfRangeException("flags", "Loading a script cannot be FireAndForget");
}
var hash = server.ScriptLoad(ExecutableScript, flags);
return new LoadedLuaScript(this, hash);
}
/// <summary>
/// Loads this LuaScript into the given IServer so it can be run with it's SHA1 hash, instead of
/// passing the full script on each Evaluate or EvaluateAsync call.
///
/// Note: the FireAndForget command flag cannot be set
/// </summary>
public async Task<LoadedLuaScript> LoadAsync(IServer server, CommandFlags flags = CommandFlags.None)
{
if (flags.HasFlag(CommandFlags.FireAndForget))
{
throw new ArgumentOutOfRangeException("flags", "Loading a script cannot be FireAndForget");
}
var hash = await server.ScriptLoadAsync(ExecutableScript, flags);
return new LoadedLuaScript(this, hash);
}
}
/// <summary>
/// Represents a Lua script that can be executed on Redis.
///
/// Unlike LuaScript, LoadedLuaScript sends the hash of it's ExecutableScript to Redis rather than pass
/// the whole script on each call. This requires that the script be loaded into Redis before it is used.
///
/// To create a LoadedLuaScript first create a LuaScript via LuaScript.Prepare(string), then
/// call Load(IServer, CommandFlags) on the returned LuaScript.
///
/// Unlike normal Redis Lua scripts, LoadedLuaScript can have named parameters (prefixed by a @).
/// Public fields and properties of the passed in object are treated as parameters.
///
/// Parameters of type RedisKey are sent to Redis as KEY (http://redis.io/commands/eval) in addition to arguments,
/// so as to play nicely with Redis Cluster.
///
/// All members of this class are thread safe.
/// </summary>
public sealed class LoadedLuaScript
{
/// <summary>
/// The original script that was used to create this LoadedLuaScript.
/// </summary>
public string OriginalScript { get { return Original.OriginalScript; } }
/// <summary>
/// The script that will actually be sent to Redis for execution.
/// </summary>
public string ExecutableScript { get { return Original.ExecutableScript; } }
/// <summary>
/// The SHA1 hash of ExecutableScript.
///
/// This is sent to Redis instead of ExecutableScript during Evaluate and EvaluateAsync calls.
/// </summary>
public byte[] Hash { get; private set; }
// internal for testing purposes only
internal LuaScript Original;
internal LoadedLuaScript(LuaScript original, byte[] hash)
{
Original = original;
Hash = hash;
}
/// <summary>
/// Evaluates this LoadedLuaScript against the given database, extracting parameters for the passed in object if any.
///
/// This method sends the SHA1 hash of the ExecutableScript instead of the script itself. If the script has not
/// been loaded into the passed Redis instance it will fail.
/// </summary>
public RedisResult Evaluate(IDatabase db, object ps = null, RedisKey? withKeyPrefix = null, CommandFlags flags = CommandFlags.None)
{
RedisKey[] keys;
RedisValue[] args;
Original.ExtractParameters(ps, withKeyPrefix, out keys, out args);
return db.ScriptEvaluate(Hash, keys, args, flags);
}
/// <summary>
/// Evaluates this LoadedLuaScript against the given database, extracting parameters for the passed in object if any.
///
/// This method sends the SHA1 hash of the ExecutableScript instead of the script itself. If the script has not
/// been loaded into the passed Redis instance it will fail.
/// </summary>
public Task<RedisResult> EvaluateAsync(IDatabaseAsync db, object ps = null, RedisKey? withKeyPrefix = null, CommandFlags flags = CommandFlags.None)
{
RedisKey[] keys;
RedisValue[] args;
Original.ExtractParameters(ps, withKeyPrefix, out keys, out args);
return db.ScriptEvaluateAsync(Hash, keys, args, flags);
}
}
}
...@@ -9,7 +9,8 @@ internal class RedisDatabase : RedisBase, IDatabase ...@@ -9,7 +9,8 @@ internal class RedisDatabase : RedisBase, IDatabase
{ {
private readonly int Db; private readonly int Db;
internal RedisDatabase(ConnectionMultiplexer multiplexer, int db, object asyncState) : base(multiplexer, asyncState) internal RedisDatabase(ConnectionMultiplexer multiplexer, int db, object asyncState)
: base(multiplexer, asyncState)
{ {
this.Db = db; this.Db = db;
} }
...@@ -33,7 +34,7 @@ public ITransaction CreateTransaction(object asyncState) ...@@ -33,7 +34,7 @@ public ITransaction CreateTransaction(object asyncState)
private ITransaction CreateTransactionIfAvailable(object asyncState) private ITransaction CreateTransactionIfAvailable(object asyncState)
{ {
var map = multiplexer.CommandMap; var map = multiplexer.CommandMap;
if(!map.IsAvailable(RedisCommand.MULTI) || !map.IsAvailable(RedisCommand.EXEC)) if (!map.IsAvailable(RedisCommand.MULTI) || !map.IsAvailable(RedisCommand.EXEC))
{ {
return null; return null;
} }
...@@ -785,7 +786,7 @@ public bool LockExtend(RedisKey key, RedisValue value, TimeSpan expiry, CommandF ...@@ -785,7 +786,7 @@ public bool LockExtend(RedisKey key, RedisValue value, TimeSpan expiry, CommandF
{ {
if (value.IsNull) throw new ArgumentNullException("value"); if (value.IsNull) throw new ArgumentNullException("value");
var tran = GetLockExtendTransaction(key, value, expiry); var tran = GetLockExtendTransaction(key, value, expiry);
if(tran != null) return tran.Execute(flags); if (tran != null) return tran.Execute(flags);
// without transactions (twemproxy etc), we can't enforce the "value" part // without transactions (twemproxy etc), we can't enforce the "value" part
return KeyExpire(key, expiry, flags); return KeyExpire(key, expiry, flags);
...@@ -795,7 +796,7 @@ public Task<bool> LockExtendAsync(RedisKey key, RedisValue value, TimeSpan expir ...@@ -795,7 +796,7 @@ public Task<bool> LockExtendAsync(RedisKey key, RedisValue value, TimeSpan expir
{ {
if (value.IsNull) throw new ArgumentNullException("value"); if (value.IsNull) throw new ArgumentNullException("value");
var tran = GetLockExtendTransaction(key, value, expiry); var tran = GetLockExtendTransaction(key, value, expiry);
if(tran != null) return tran.ExecuteAsync(flags); if (tran != null) return tran.ExecuteAsync(flags);
// without transactions (twemproxy etc), we can't enforce the "value" part // without transactions (twemproxy etc), we can't enforce the "value" part
return KeyExpireAsync(key, expiry, flags); return KeyExpireAsync(key, expiry, flags);
...@@ -815,7 +816,7 @@ public bool LockRelease(RedisKey key, RedisValue value, CommandFlags flags = Com ...@@ -815,7 +816,7 @@ public bool LockRelease(RedisKey key, RedisValue value, CommandFlags flags = Com
{ {
if (value.IsNull) throw new ArgumentNullException("value"); if (value.IsNull) throw new ArgumentNullException("value");
var tran = GetLockReleaseTransaction(key, value); var tran = GetLockReleaseTransaction(key, value);
if(tran != null) return tran.Execute(flags); if (tran != null) return tran.Execute(flags);
// without transactions (twemproxy etc), we can't enforce the "value" part // without transactions (twemproxy etc), we can't enforce the "value" part
return KeyDelete(key, flags); return KeyDelete(key, flags);
...@@ -825,7 +826,7 @@ public Task<bool> LockReleaseAsync(RedisKey key, RedisValue value, CommandFlags ...@@ -825,7 +826,7 @@ public Task<bool> LockReleaseAsync(RedisKey key, RedisValue value, CommandFlags
{ {
if (value.IsNull) throw new ArgumentNullException("value"); if (value.IsNull) throw new ArgumentNullException("value");
var tran = GetLockReleaseTransaction(key, value); var tran = GetLockReleaseTransaction(key, value);
if(tran != null) return tran.ExecuteAsync(flags); if (tran != null) return tran.ExecuteAsync(flags);
// without transactions (twemproxy etc), we can't enforce the "value" part // without transactions (twemproxy etc), we can't enforce the "value" part
return KeyDeleteAsync(key, flags); return KeyDeleteAsync(key, flags);
...@@ -862,10 +863,11 @@ public RedisResult ScriptEvaluate(string script, RedisKey[] keys = null, RedisVa ...@@ -862,10 +863,11 @@ public RedisResult ScriptEvaluate(string script, RedisKey[] keys = null, RedisVa
try try
{ {
return ExecuteSync(msg, ResultProcessor.ScriptResult); return ExecuteSync(msg, ResultProcessor.ScriptResult);
} catch(RedisServerException) }
catch (RedisServerException)
{ {
// could be a NOSCRIPT; for a sync call, we can re-issue that without problem // could be a NOSCRIPT; for a sync call, we can re-issue that without problem
if(msg.IsScriptUnavailable) return ExecuteSync(msg, ResultProcessor.ScriptResult); if (msg.IsScriptUnavailable) return ExecuteSync(msg, ResultProcessor.ScriptResult);
throw; throw;
} }
} }
...@@ -874,6 +876,14 @@ public RedisResult ScriptEvaluate(byte[] hash, RedisKey[] keys = null, RedisValu ...@@ -874,6 +876,14 @@ public RedisResult ScriptEvaluate(byte[] hash, RedisKey[] keys = null, RedisValu
var msg = new ScriptEvalMessage(Db, flags, hash, keys, values); var msg = new ScriptEvalMessage(Db, flags, hash, keys, values);
return ExecuteSync(msg, ResultProcessor.ScriptResult); return ExecuteSync(msg, ResultProcessor.ScriptResult);
} }
public RedisResult ScriptEvaluate(LuaScript script, object parameters = null, CommandFlags flags = CommandFlags.None)
{
return script.Evaluate(this, parameters, null, flags);
}
public RedisResult ScriptEvaluate(LoadedLuaScript script, object parameters = null, CommandFlags flags = CommandFlags.None)
{
return script.Evaluate(this, parameters, null, flags);
}
public Task<RedisResult> ScriptEvaluateAsync(string script, RedisKey[] keys = null, RedisValue[] values = null, CommandFlags flags = CommandFlags.None) public Task<RedisResult> ScriptEvaluateAsync(string script, RedisKey[] keys = null, RedisValue[] values = null, CommandFlags flags = CommandFlags.None)
{ {
...@@ -885,6 +895,14 @@ public Task<RedisResult> ScriptEvaluateAsync(byte[] hash, RedisKey[] keys = null ...@@ -885,6 +895,14 @@ public Task<RedisResult> ScriptEvaluateAsync(byte[] hash, RedisKey[] keys = null
var msg = new ScriptEvalMessage(Db, flags, hash, keys, values); var msg = new ScriptEvalMessage(Db, flags, hash, keys, values);
return ExecuteAsync(msg, ResultProcessor.ScriptResult); return ExecuteAsync(msg, ResultProcessor.ScriptResult);
} }
public Task<RedisResult> ScriptEvaluateAsync(LuaScript script, object parameters = null, CommandFlags flags = CommandFlags.None)
{
return script.EvaluateAsync(this, parameters, null, flags);
}
public Task<RedisResult> ScriptEvaluateAsync(LoadedLuaScript script, object parameters = null, CommandFlags flags = CommandFlags.None)
{
return script.EvaluateAsync(this, parameters, null, flags);
}
public bool SetAdd(RedisKey key, RedisValue value, CommandFlags flags = CommandFlags.None) public bool SetAdd(RedisKey key, RedisValue value, CommandFlags flags = CommandFlags.None)
{ {
...@@ -1077,7 +1095,7 @@ public IEnumerable<RedisValue> SetScan(RedisKey key, RedisValue pattern = defaul ...@@ -1077,7 +1095,7 @@ public IEnumerable<RedisValue> SetScan(RedisKey key, RedisValue pattern = defaul
var scan = TryScan<RedisValue>(key, pattern, pageSize, cursor, pageOffset, flags, RedisCommand.SSCAN, SetScanResultProcessor.Default); var scan = TryScan<RedisValue>(key, pattern, pageSize, cursor, pageOffset, flags, RedisCommand.SSCAN, SetScanResultProcessor.Default);
if (scan != null) return scan; if (scan != null) return scan;
if(cursor != 0 || pageOffset != 0) throw ExceptionFactory.NoCursor(RedisCommand.SMEMBERS); if (cursor != 0 || pageOffset != 0) throw ExceptionFactory.NoCursor(RedisCommand.SMEMBERS);
if (pattern.IsNull) return SetMembers(key, flags); if (pattern.IsNull) return SetMembers(key, flags);
throw ExceptionFactory.NotSupported(true, RedisCommand.SSCAN); throw ExceptionFactory.NotSupported(true, RedisCommand.SSCAN);
} }
...@@ -1665,9 +1683,9 @@ ITransaction GetLockReleaseTransaction(RedisKey key, RedisValue value) ...@@ -1665,9 +1683,9 @@ ITransaction GetLockReleaseTransaction(RedisKey key, RedisValue value)
private RedisValue GetLexRange(RedisValue value, Exclude exclude, bool isStart) private RedisValue GetLexRange(RedisValue value, Exclude exclude, bool isStart)
{ {
if(value.IsNull) if (value.IsNull)
{ {
return isStart? RedisLiterals.MinusSymbol : RedisLiterals.PlusSumbol; return isStart ? RedisLiterals.MinusSymbol : RedisLiterals.PlusSumbol;
} }
byte[] orig = value; byte[] orig = value;
...@@ -1857,7 +1875,7 @@ private Message GetSortedSetRangeByScoreMessage(RedisKey key, double start, doub ...@@ -1857,7 +1875,7 @@ private Message GetSortedSetRangeByScoreMessage(RedisKey key, double start, doub
var tmp = start; var tmp = start;
start = stop; start = stop;
stop = tmp; stop = tmp;
switch(exclude) switch (exclude)
{ {
case Exclude.Start: exclude = Exclude.Stop; break; case Exclude.Start: exclude = Exclude.Stop; break;
case Exclude.Stop: exclude = Exclude.Start; break; case Exclude.Stop: exclude = Exclude.Start; break;
...@@ -2132,7 +2150,8 @@ protected override Message CreateMessage(long cursor) ...@@ -2132,7 +2150,8 @@ protected override Message CreateMessage(long cursor)
internal sealed class ScriptLoadMessage : Message internal sealed class ScriptLoadMessage : Message
{ {
internal readonly string Script; internal readonly string Script;
public ScriptLoadMessage(CommandFlags flags, string script) : base(-1, flags, RedisCommand.SCRIPT) public ScriptLoadMessage(CommandFlags flags, string script)
: base(-1, flags, RedisCommand.SCRIPT)
{ {
if (script == null) throw new ArgumentNullException("script"); if (script == null) throw new ArgumentNullException("script");
this.Script = script; this.Script = script;
...@@ -2195,7 +2214,8 @@ public ScriptEvalMessage(int db, CommandFlags flags, byte[] hash, RedisKey[] key ...@@ -2195,7 +2214,8 @@ public ScriptEvalMessage(int db, CommandFlags flags, byte[] hash, RedisKey[] key
if (hash == null) throw new ArgumentNullException("hash"); if (hash == null) throw new ArgumentNullException("hash");
} }
private ScriptEvalMessage(int db, CommandFlags flags, RedisCommand command, string script, byte[] hexHash, RedisKey[] keys, RedisValue[] values) : base(db, flags, command) private ScriptEvalMessage(int db, CommandFlags flags, RedisCommand command, string script, byte[] hexHash, RedisKey[] keys, RedisValue[] values)
: base(db, flags, command)
{ {
this.script = script; this.script = script;
this.hexHash = hexHash; this.hexHash = hexHash;
...@@ -2220,7 +2240,7 @@ public override int GetHashSlot(ServerSelectionStrategy serverSelectionStrategy) ...@@ -2220,7 +2240,7 @@ public override int GetHashSlot(ServerSelectionStrategy serverSelectionStrategy)
public IEnumerable<Message> GetMessages(PhysicalConnection connection) public IEnumerable<Message> GetMessages(PhysicalConnection connection)
{ {
if (script != null) // a script was provided (rather than a hash); check it is known if (script != null && connection.Multiplexer.CommandMap.IsAvailable(RedisCommand.SCRIPT)) // a script was provided (rather than a hash); check it is known and supported
{ {
asciiHash = connection.Bridge.ServerEndPoint.GetScriptHash(script, command); asciiHash = connection.Bridge.ServerEndPoint.GetScriptHash(script, command);
...@@ -2237,7 +2257,7 @@ public IEnumerable<Message> GetMessages(PhysicalConnection connection) ...@@ -2237,7 +2257,7 @@ public IEnumerable<Message> GetMessages(PhysicalConnection connection)
internal override void WriteImpl(PhysicalConnection physical) internal override void WriteImpl(PhysicalConnection physical)
{ {
if(hexHash != null) if (hexHash != null)
{ {
physical.WriteHeader(RedisCommand.EVALSHA, 2 + keys.Length + values.Length); physical.WriteHeader(RedisCommand.EVALSHA, 2 + keys.Length + values.Length);
physical.WriteAsHex(hexHash); physical.WriteAsHex(hexHash);
...@@ -2273,7 +2293,8 @@ sealed class SortedSetCombineAndStoreCommandMessage : Message.CommandKeyBase // ...@@ -2273,7 +2293,8 @@ sealed class SortedSetCombineAndStoreCommandMessage : Message.CommandKeyBase //
{ {
private readonly RedisKey[] keys; private readonly RedisKey[] keys;
private readonly RedisValue[] values; private readonly RedisValue[] values;
public SortedSetCombineAndStoreCommandMessage(int db, CommandFlags flags, RedisCommand command, RedisKey destination, RedisKey[] keys, RedisValue[] values) : base(db, flags, command, destination) public SortedSetCombineAndStoreCommandMessage(int db, CommandFlags flags, RedisCommand command, RedisKey destination, RedisKey[] keys, RedisValue[] values)
: base(db, flags, command, destination)
{ {
for (int i = 0; i < keys.Length; i++) for (int i = 0; i < keys.Length; i++)
keys[i].AssertNotNull(); keys[i].AssertNotNull();
...@@ -2359,7 +2380,7 @@ private class StringGetWithExpiryProcessor : ResultProcessor<RedisValueWithExpir ...@@ -2359,7 +2380,7 @@ private class StringGetWithExpiryProcessor : ResultProcessor<RedisValueWithExpir
private StringGetWithExpiryProcessor() { } private StringGetWithExpiryProcessor() { }
protected override bool SetResultCore(PhysicalConnection connection, Message message, RawResult result) protected override bool SetResultCore(PhysicalConnection connection, Message message, RawResult result)
{ {
switch(result.Type) switch (result.Type)
{ {
case ResultType.Integer: case ResultType.Integer:
case ResultType.SimpleString: case ResultType.SimpleString:
......
...@@ -375,6 +375,16 @@ public Task<byte[]> ScriptLoadAsync(string script, CommandFlags flags = CommandF ...@@ -375,6 +375,16 @@ public Task<byte[]> ScriptLoadAsync(string script, CommandFlags flags = CommandF
return ExecuteAsync(msg, ResultProcessor.ScriptLoad); return ExecuteAsync(msg, ResultProcessor.ScriptLoad);
} }
public LoadedLuaScript ScriptLoad(LuaScript script, CommandFlags flags = CommandFlags.None)
{
return script.Load(this, flags);
}
public Task<LoadedLuaScript> ScriptLoadAsync(LuaScript script, CommandFlags flags = CommandFlags.None)
{
return script.LoadAsync(this, flags);
}
public void Shutdown(ShutdownMode shutdownMode = ShutdownMode.Default, CommandFlags flags = CommandFlags.None) public void Shutdown(ShutdownMode shutdownMode = ShutdownMode.Default, CommandFlags flags = CommandFlags.None)
{ {
Message msg; Message msg;
...@@ -563,12 +573,35 @@ internal override RedisFeatures GetFeatures(int db, RedisKey key, CommandFlags f ...@@ -563,12 +573,35 @@ internal override RedisFeatures GetFeatures(int db, RedisKey key, CommandFlags f
public void SlaveOf(EndPoint endpoint, CommandFlags flags = CommandFlags.None) public void SlaveOf(EndPoint endpoint, CommandFlags flags = CommandFlags.None)
{ {
var msg = CreateSlaveOfMessage(endpoint, flags);
if (endpoint == server.EndPoint) if (endpoint == server.EndPoint)
{ {
throw new ArgumentException("Cannot slave to self"); throw new ArgumentException("Cannot slave to self");
} }
ExecuteSync(msg, ResultProcessor.DemandOK); // prepare the actual slaveof message (not sent yet)
var slaveofMsg = CreateSlaveOfMessage(endpoint, flags);
var configuration = this.multiplexer.RawConfig;
// attempt to cease having an opinion on the master; will resume that when replication completes
// (note that this may fail; we aren't depending on it)
if (!string.IsNullOrWhiteSpace(configuration.TieBreaker)
&& this.multiplexer.CommandMap.IsAvailable(RedisCommand.DEL))
{
var del = Message.Create(0, CommandFlags.FireAndForget | CommandFlags.NoRedirect, RedisCommand.DEL, (RedisKey)configuration.TieBreaker);
del.SetInternalCall();
server.QueueDirectFireAndForget(del, ResultProcessor.Boolean);
}
ExecuteSync(slaveofMsg, ResultProcessor.DemandOK);
// attempt to broadcast a reconfigure message to anybody listening to this server
var channel = this.multiplexer.ConfigurationChangedChannel;
if (channel != null && this.multiplexer.CommandMap.IsAvailable(RedisCommand.PUBLISH))
{
var pub = Message.Create(-1, CommandFlags.FireAndForget | CommandFlags.NoRedirect, RedisCommand.PUBLISH, (RedisValue)channel, RedisLiterals.Wildcard);
pub.SetInternalCall();
server.QueueDirectFireAndForget(pub, ResultProcessor.Int64);
}
} }
public Task SlaveOfAsync(EndPoint endpoint, CommandFlags flags = CommandFlags.None) public Task SlaveOfAsync(EndPoint endpoint, CommandFlags flags = CommandFlags.None)
......
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Reflection.Emit;
using System.Security.Cryptography;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
namespace StackExchange.Redis
{
class ScriptParameterMapper
{
public struct ScriptParameters
{
public RedisKey[] Keys;
public RedisValue[] Arguments;
public static readonly ConstructorInfo Cons = typeof(ScriptParameters).GetConstructor(new[] { typeof(RedisKey[]), typeof(RedisValue[]) });
public ScriptParameters(RedisKey[] keys, RedisValue[] args)
{
Keys = keys;
Arguments = args;
}
}
static readonly Regex ParameterExtractor = new Regex(@"@(?<paramName> ([a-z]|_) ([a-z]|_|\d)*)", RegexOptions.Compiled | RegexOptions.IgnoreCase | RegexOptions.IgnorePatternWhitespace);
static string[] ExtractParameters(string script)
{
var ps = ParameterExtractor.Matches(script);
if (ps.Count == 0) return null;
var ret = new HashSet<string>();
for (var i = 0; i < ps.Count; i++)
{
var c = ps[i];
var ix = c.Index - 1;
if (ix >= 0)
{
var prevChar = script[ix];
// don't consider this a parameter if it's in the middle of word (ie. if it's preceeded by a letter)
if (char.IsLetterOrDigit(prevChar) || prevChar == '_') continue;
// this is an escape, ignore it
if (prevChar == '@') continue;
}
var n = c.Groups["paramName"].Value;
if (!ret.Contains(n)) ret.Add(n);
}
return ret.ToArray();
}
static string MakeOrdinalScriptWithoutKeys(string rawScript, string[] args)
{
var ps = ParameterExtractor.Matches(rawScript);
if (ps.Count == 0) return rawScript;
var ret = new StringBuilder();
var upTo = 0;
for (var i = 0; i < ps.Count; i++)
{
var capture = ps[i];
var name = capture.Groups["paramName"].Value;
var ix = capture.Index;
ret.Append(rawScript.Substring(upTo, ix - upTo));
var argIx = Array.IndexOf(args, name);
if (argIx != -1)
{
ret.Append("ARGV[");
ret.Append(argIx + 1);
ret.Append("]");
}
else
{
var isEscape = false;
var prevIx = capture.Index - 1;
if (prevIx >= 0)
{
var prevChar = rawScript[prevIx];
isEscape = prevChar == '@';
}
if (isEscape)
{
// strip the @ off, so just the one triggering the escape exists
ret.Append(capture.Groups["paramName"].Value);
}
else
{
ret.Append(capture.Value);
}
}
upTo = capture.Index + capture.Length;
}
ret.Append(rawScript.Substring(upTo, rawScript.Length - upTo));
return ret.ToString();
}
static void LoadMember(ILGenerator il, MemberInfo member)
{
// stack starts:
// T(*?)
var asField = member as FieldInfo;
if (asField != null)
{
il.Emit(OpCodes.Ldfld, asField); // typeof(member)
return;
}
var asProp = member as PropertyInfo;
if (asProp != null)
{
var getter = asProp.GetGetMethod();
if (getter.IsVirtual)
{
il.Emit(OpCodes.Callvirt, getter); // typeof(member)
}
else
{
il.Emit(OpCodes.Call, getter); // typeof(member)
}
return;
}
throw new Exception("Should't be possible");
}
static readonly MethodInfo RedisValue_FromInt = typeof(RedisValue).GetMethod("op_Implicit", new[] { typeof(int) });
static readonly MethodInfo RedisValue_FromNullableInt = typeof(RedisValue).GetMethod("op_Implicit", new[] { typeof(int?) });
static readonly MethodInfo RedisValue_FromLong = typeof(RedisValue).GetMethod("op_Implicit", new[] { typeof(long) });
static readonly MethodInfo RedisValue_FromNullableLong = typeof(RedisValue).GetMethod("op_Implicit", new[] { typeof(long?) });
static readonly MethodInfo RedisValue_FromDouble= typeof(RedisValue).GetMethod("op_Implicit", new[] { typeof(double) });
static readonly MethodInfo RedisValue_FromNullableDouble = typeof(RedisValue).GetMethod("op_Implicit", new[] { typeof(double?) });
static readonly MethodInfo RedisValue_FromString = typeof(RedisValue).GetMethod("op_Implicit", new[] { typeof(string) });
static readonly MethodInfo RedisValue_FromByteArray = typeof(RedisValue).GetMethod("op_Implicit", new[] { typeof(byte[]) });
static readonly MethodInfo RedisValue_FromBool = typeof(RedisValue).GetMethod("op_Implicit", new[] { typeof(bool) });
static readonly MethodInfo RedisValue_FromNullableBool = typeof(RedisValue).GetMethod("op_Implicit", new[] { typeof(bool?) });
static readonly MethodInfo RedisKey_AsRedisValue = typeof(RedisKey).GetMethod("AsRedisValue", BindingFlags.NonPublic | BindingFlags.Instance);
static void ConvertToRedisValue(MemberInfo member, ILGenerator il, LocalBuilder needsPrefixBool, ref LocalBuilder redisKeyLoc)
{
// stack starts:
// typeof(member)
var t = member is FieldInfo ? ((FieldInfo)member).FieldType : ((PropertyInfo)member).PropertyType;
if (t == typeof(RedisValue))
{
// They've already converted for us, don't do anything
return;
}
if (t == typeof(RedisKey))
{
redisKeyLoc = redisKeyLoc ?? il.DeclareLocal(typeof(RedisKey));
PrefixIfNeeded(il, needsPrefixBool, ref redisKeyLoc); // RedisKey
il.Emit(OpCodes.Stloc, redisKeyLoc); // --empty--
il.Emit(OpCodes.Ldloca, redisKeyLoc); // RedisKey*
il.Emit(OpCodes.Call, RedisKey_AsRedisValue); // RedisValue
return;
}
MethodInfo convertOp = null;
if (t == typeof(int)) convertOp = RedisValue_FromInt;
if (t == typeof(int?)) convertOp = RedisValue_FromNullableInt;
if (t == typeof(long)) convertOp = RedisValue_FromLong;
if (t == typeof(long?)) convertOp = RedisValue_FromNullableLong;
if (t == typeof(double)) convertOp = RedisValue_FromDouble;
if (t == typeof(double?)) convertOp = RedisValue_FromNullableDouble;
if (t == typeof(string)) convertOp = RedisValue_FromString;
if (t == typeof(byte[])) convertOp = RedisValue_FromByteArray;
if (t == typeof(bool)) convertOp = RedisValue_FromBool;
if (t == typeof(bool?)) convertOp = RedisValue_FromNullableBool;
il.Emit(OpCodes.Call, convertOp);
// stack ends:
// RedisValue
}
/// <summary>
/// Turns a script with @namedParameters into a LuaScript that can be executed
/// against a given IDatabase(Async) object
/// </summary>
public static LuaScript PrepareScript(string script)
{
var ps = ExtractParameters(script);
var ordinalScript = MakeOrdinalScriptWithoutKeys(script, ps);
return new LuaScript(script, ordinalScript, ps);
}
static readonly HashSet<Type> ConvertableTypes =
new HashSet<Type> {
typeof(int),
typeof(int?),
typeof(long),
typeof(long?),
typeof(double),
typeof(double?),
typeof(string),
typeof(byte[]),
typeof(bool),
typeof(bool?),
typeof(RedisKey),
typeof(RedisValue)
};
/// <summary>
/// Determines whether or not the given type can be used to provide parameters for the given LuaScript.
/// </summary>
public static bool IsValidParameterHash(Type t, LuaScript script, out string missingMember, out string badTypeMember)
{
for (var i = 0; i < script.Arguments.Length; i++)
{
var argName = script.Arguments[i];
var member = t.GetMember(argName).Where(m => m is PropertyInfo || m is FieldInfo).SingleOrDefault();
if (member == null)
{
missingMember = argName;
badTypeMember = null;
return false;
}
var memberType = member is FieldInfo ? ((FieldInfo)member).FieldType : ((PropertyInfo)member).PropertyType;
if(!ConvertableTypes.Contains(memberType)){
missingMember = null;
badTypeMember = argName;
return false;
}
}
missingMember = badTypeMember = null;
return true;
}
static void PrefixIfNeeded(ILGenerator il, LocalBuilder needsPrefixBool, ref LocalBuilder redisKeyLoc)
{
// top of stack is
// RedisKey
var getVal = typeof(RedisKey?).GetProperty("Value").GetGetMethod();
var prepend = typeof(RedisKey).GetMethod("Prepend");
var doNothing = il.DefineLabel();
redisKeyLoc = redisKeyLoc ?? il.DeclareLocal(typeof(RedisKey));
il.Emit(OpCodes.Ldloc, needsPrefixBool); // RedisKey bool
il.Emit(OpCodes.Brfalse, doNothing); // RedisKey
il.Emit(OpCodes.Stloc, redisKeyLoc); // --empty--
il.Emit(OpCodes.Ldloca, redisKeyLoc); // RedisKey*
il.Emit(OpCodes.Ldarga_S, 1); // RedisKey* RedisKey?*
il.Emit(OpCodes.Call, getVal); // RedisKey* RedisKey
il.Emit(OpCodes.Call, prepend); // RedisKey
il.MarkLabel(doNothing); // RedisKey
}
/// <summary>
/// Creates a Func that extracts parameters from the given type for use by a LuaScript.
///
/// Members that are RedisKey's get extracted to be passed in as keys to redis; all members that
/// appear in the script get extracted as RedisValue arguments to be sent up as args.
///
/// We send all values as arguments so we don't have to prepare the same script for different parameter
/// types.
///
/// The created Func takes a RedisKey, which will be prefixed to all keys (and arguments of type RedisKey) for
/// keyspace isolation.
/// </summary>
public static Func<object, RedisKey?, ScriptParameters> GetParameterExtractor(Type t, LuaScript script)
{
string ignored;
if (!IsValidParameterHash(t, script, out ignored, out ignored)) throw new Exception("Shouldn't be possible");
var keys = new List<MemberInfo>();
var args = new List<MemberInfo>();
for (var i = 0; i < script.Arguments.Length; i++)
{
var argName = script.Arguments[i];
var member = t.GetMember(argName).Where(m => m is PropertyInfo || m is FieldInfo).SingleOrDefault();
var memberType = member is FieldInfo ? ((FieldInfo)member).FieldType : ((PropertyInfo)member).PropertyType;
if (memberType == typeof(RedisKey))
{
keys.Add(member);
}
args.Add(member);
}
var nullableRedisKeyHasValue = typeof(RedisKey?).GetProperty("HasValue").GetGetMethod();
var dyn = new DynamicMethod("ParameterExtractor_" + t.FullName + "_" + script.OriginalScript.GetHashCode(), typeof(ScriptParameters), new[] { typeof(object), typeof(RedisKey?) }, restrictedSkipVisibility: true);
var il = dyn.GetILGenerator();
// only init'd if we use it
LocalBuilder redisKeyLoc = null;
var loc = il.DeclareLocal(t);
il.Emit(OpCodes.Ldarg_0); // object
if (t.IsValueType)
{
il.Emit(OpCodes.Unbox_Any, t); // T
}
else
{
il.Emit(OpCodes.Castclass, t); // T
}
il.Emit(OpCodes.Stloc, loc); // --empty--
var needsKeyPrefixLoc = il.DeclareLocal(typeof(bool));
il.Emit(OpCodes.Ldarga_S, 1); // RedisKey?*
il.Emit(OpCodes.Call, nullableRedisKeyHasValue); // bool
il.Emit(OpCodes.Stloc, needsKeyPrefixLoc); // --empty--
if (keys.Count == 0)
{
// if there are no keys, don't allocate
il.Emit(OpCodes.Ldnull); // null
}
else
{
il.Emit(OpCodes.Ldc_I4, keys.Count); // int
il.Emit(OpCodes.Newarr, typeof(RedisKey)); // RedisKey[]
}
for (var i = 0; i < keys.Count; i++)
{
il.Emit(OpCodes.Dup); // RedisKey[] RedisKey[]
il.Emit(OpCodes.Ldc_I4, i); // RedisKey[] RedisKey[] int
if (t.IsValueType)
{
il.Emit(OpCodes.Ldloca, loc); // RedisKey[] RedisKey[] int T*
}
else
{
il.Emit(OpCodes.Ldloc, loc); // RedisKey[] RedisKey[] int T
}
LoadMember(il, keys[i]); // RedisKey[] RedisKey[] int RedisKey
PrefixIfNeeded(il, needsKeyPrefixLoc, ref redisKeyLoc); // RedisKey[] RedisKey[] int RedisKey
il.Emit(OpCodes.Stelem, typeof(RedisKey)); // RedisKey[]
}
if (args.Count == 0)
{
// if there are no args, don't allocate
il.Emit(OpCodes.Ldnull); // RedisKey[] null
}
else
{
il.Emit(OpCodes.Ldc_I4, args.Count); // RedisKey[] int
il.Emit(OpCodes.Newarr, typeof(RedisValue)); // RedisKey[] RedisValue[]
}
for (var i = 0; i < args.Count; i++)
{
il.Emit(OpCodes.Dup); // RedisKey[] RedisValue[] RedisValue[]
il.Emit(OpCodes.Ldc_I4, i); // RedisKey[] RedisValue[] RedisValue[] int
if (t.IsValueType)
{
il.Emit(OpCodes.Ldloca, loc); // RedisKey[] RedisValue[] RedisValue[] int T*
}
else
{
il.Emit(OpCodes.Ldloc, loc); // RedisKey[] RedisValue[] RedisValue[] int T
}
var member = args[i];
LoadMember(il, member); // RedisKey[] RedisValue[] RedisValue[] int memberType
ConvertToRedisValue(member, il, needsKeyPrefixLoc, ref redisKeyLoc); // RedisKey[] RedisValue[] RedisValue[] int RedisValue
il.Emit(OpCodes.Stelem, typeof(RedisValue)); // RedisKey[] RedisValue[]
}
il.Emit(OpCodes.Newobj, ScriptParameters.Cons); // ScriptParameters
il.Emit(OpCodes.Ret); // --empty--
var ret = (Func<object, RedisKey?, ScriptParameters>)dyn.CreateDelegate(typeof(Func<object, RedisKey?, ScriptParameters>));
return ret;
}
}
}
...@@ -113,6 +113,7 @@ ...@@ -113,6 +113,7 @@
<Compile Include="..\StackExchange.Redis\StackExchange\Redis\MessageCompletable.cs" /> <Compile Include="..\StackExchange.Redis\StackExchange\Redis\MessageCompletable.cs" />
<Compile Include="..\StackExchange.Redis\StackExchange\Redis\MessageQueue.cs" /> <Compile Include="..\StackExchange.Redis\StackExchange\Redis\MessageQueue.cs" />
<Compile Include="..\StackExchange.Redis\StackExchange\Redis\MigrateOptions.cs" /> <Compile Include="..\StackExchange.Redis\StackExchange\Redis\MigrateOptions.cs" />
<Compile Include="..\StackExchange.Redis\StackExchange\Redis\LuaScript.cs" />
<Compile Include="..\StackExchange.Redis\StackExchange\Redis\Order.cs" /> <Compile Include="..\StackExchange.Redis\StackExchange\Redis\Order.cs" />
<Compile Include="..\StackExchange.Redis\StackExchange\Redis\PhysicalBridge.cs" /> <Compile Include="..\StackExchange.Redis\StackExchange\Redis\PhysicalBridge.cs" />
<Compile Include="..\StackExchange.Redis\StackExchange\Redis\PhysicalConnection.cs" /> <Compile Include="..\StackExchange.Redis\StackExchange\Redis\PhysicalConnection.cs" />
...@@ -136,6 +137,7 @@ ...@@ -136,6 +137,7 @@
<Compile Include="..\StackExchange.Redis\StackExchange\Redis\ResultBox.cs" /> <Compile Include="..\StackExchange.Redis\StackExchange\Redis\ResultBox.cs" />
<Compile Include="..\StackExchange.Redis\StackExchange\Redis\ResultProcessor.cs" /> <Compile Include="..\StackExchange.Redis\StackExchange\Redis\ResultProcessor.cs" />
<Compile Include="..\StackExchange.Redis\StackExchange\Redis\ResultType.cs" /> <Compile Include="..\StackExchange.Redis\StackExchange\Redis\ResultType.cs" />
<Compile Include="..\StackExchange.Redis\StackExchange\Redis\ScriptParameterMapper.cs" />
<Compile Include="..\StackExchange.Redis\StackExchange\Redis\SaveType.cs" /> <Compile Include="..\StackExchange.Redis\StackExchange\Redis\SaveType.cs" />
<Compile Include="..\StackExchange.Redis\StackExchange\Redis\ServerCounters.cs" /> <Compile Include="..\StackExchange.Redis\StackExchange\Redis\ServerCounters.cs" />
<Compile Include="..\StackExchange.Redis\StackExchange\Redis\ServerEndPoint.cs" /> <Compile Include="..\StackExchange.Redis\StackExchange\Redis\ServerEndPoint.cs" />
......
...@@ -107,6 +107,7 @@ ...@@ -107,6 +107,7 @@
<Compile Include="..\StackExchange.Redis\StackExchange\Redis\MessageCompletable.cs" /> <Compile Include="..\StackExchange.Redis\StackExchange\Redis\MessageCompletable.cs" />
<Compile Include="..\StackExchange.Redis\StackExchange\Redis\MessageQueue.cs" /> <Compile Include="..\StackExchange.Redis\StackExchange\Redis\MessageQueue.cs" />
<Compile Include="..\StackExchange.Redis\StackExchange\Redis\MigrateOptions.cs" /> <Compile Include="..\StackExchange.Redis\StackExchange\Redis\MigrateOptions.cs" />
<Compile Include="..\StackExchange.Redis\StackExchange\Redis\LuaScript.cs" />
<Compile Include="..\StackExchange.Redis\StackExchange\Redis\Order.cs" /> <Compile Include="..\StackExchange.Redis\StackExchange\Redis\Order.cs" />
<Compile Include="..\StackExchange.Redis\StackExchange\Redis\PhysicalBridge.cs" /> <Compile Include="..\StackExchange.Redis\StackExchange\Redis\PhysicalBridge.cs" />
<Compile Include="..\StackExchange.Redis\StackExchange\Redis\PhysicalConnection.cs" /> <Compile Include="..\StackExchange.Redis\StackExchange\Redis\PhysicalConnection.cs" />
...@@ -130,6 +131,7 @@ ...@@ -130,6 +131,7 @@
<Compile Include="..\StackExchange.Redis\StackExchange\Redis\ResultBox.cs" /> <Compile Include="..\StackExchange.Redis\StackExchange\Redis\ResultBox.cs" />
<Compile Include="..\StackExchange.Redis\StackExchange\Redis\ResultProcessor.cs" /> <Compile Include="..\StackExchange.Redis\StackExchange\Redis\ResultProcessor.cs" />
<Compile Include="..\StackExchange.Redis\StackExchange\Redis\ResultType.cs" /> <Compile Include="..\StackExchange.Redis\StackExchange\Redis\ResultType.cs" />
<Compile Include="..\StackExchange.Redis\StackExchange\Redis\ScriptParameterMapper.cs" />
<Compile Include="..\StackExchange.Redis\StackExchange\Redis\SaveType.cs" /> <Compile Include="..\StackExchange.Redis\StackExchange\Redis\SaveType.cs" />
<Compile Include="..\StackExchange.Redis\StackExchange\Redis\ServerCounters.cs" /> <Compile Include="..\StackExchange.Redis\StackExchange\Redis\ServerCounters.cs" />
<Compile Include="..\StackExchange.Redis\StackExchange\Redis\ServerEndPoint.cs" /> <Compile Include="..\StackExchange.Redis\StackExchange\Redis\ServerEndPoint.cs" />
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment