Commit b2690ae5 authored by Marc Gravell's avatar Marc Gravell

Merge pull request #170 from kevin-montrose/named-script-parameters-squashed

Named script parameters squashed
parents f4208759 f0379da8
This diff is collapsed.
......@@ -74,6 +74,7 @@
<Compile Include="StackExchange\Redis\HashEntry.cs" />
<Compile Include="StackExchange\Redis\InternalErrorEventArgs.cs" />
<Compile Include="StackExchange\Redis\MigrateOptions.cs" />
<Compile Include="StackExchange\Redis\LuaScript.cs" />
<Compile Include="StackExchange\Redis\RedisChannel.cs" />
<Compile Include="StackExchange\Redis\Bitwise.cs" />
<Compile Include="StackExchange\Redis\ClientFlags.cs" />
......@@ -139,6 +140,7 @@
<Compile Include="StackExchange\Redis\ResultProcessor.cs" />
<Compile Include="StackExchange\Redis\RedisSubscriber.cs" />
<Compile Include="StackExchange\Redis\ResultType.cs" />
<Compile Include="StackExchange\Redis\ScriptParameterMapper.cs" />
<Compile Include="StackExchange\Redis\ServerCounters.cs" />
<Compile Include="StackExchange\Redis\ServerEndPoint.cs" />
<Compile Include="StackExchange\Redis\ServerSelectionStrategy.cs" />
......
......@@ -68,6 +68,7 @@
<Compile Include="StackExchange\Redis\HashEntry.cs" />
<Compile Include="StackExchange\Redis\InternalErrorEventArgs.cs" />
<Compile Include="StackExchange\Redis\MigrateOptions.cs" />
<Compile Include="StackExchange\Redis\LuaScript.cs" />
<Compile Include="StackExchange\Redis\RedisChannel.cs" />
<Compile Include="StackExchange\Redis\Bitwise.cs" />
<Compile Include="StackExchange\Redis\ClientFlags.cs" />
......@@ -133,6 +134,7 @@
<Compile Include="StackExchange\Redis\ResultProcessor.cs" />
<Compile Include="StackExchange\Redis\RedisSubscriber.cs" />
<Compile Include="StackExchange\Redis\ResultType.cs" />
<Compile Include="StackExchange\Redis\ScriptParameterMapper.cs" />
<Compile Include="StackExchange\Redis\ServerCounters.cs" />
<Compile Include="StackExchange\Redis\ServerEndPoint.cs" />
<Compile Include="StackExchange\Redis\ServerSelectionStrategy.cs" />
......
......@@ -1905,5 +1905,4 @@ public Task<long> PublishReconfigureAsync(CommandFlags flags = CommandFlags.None
return GetSubscriber().PublishAsync(channel, RedisLiterals.Wildcard, flags);
}
}
}
......@@ -452,6 +452,7 @@ public interface IDatabase : IRedis, IDatabaseAsync
/// <returns>the number of clients that received the message.</returns>
/// <remarks>http://redis.io/commands/publish</remarks>
long Publish(RedisChannel channel, RedisValue message, CommandFlags flags = CommandFlags.None);
/// <summary>
/// Execute a Lua script against the server
/// </summary>
......@@ -466,6 +467,19 @@ public interface IDatabase : IRedis, IDatabaseAsync
/// <returns>A dynamic representation of the script's result</returns>
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>
/// 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>
......
......@@ -439,6 +439,19 @@ public interface IDatabaseAsync : IRedisAsync
/// <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);
/// <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>
/// 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>
......
......@@ -314,11 +314,21 @@ public partial interface IServer : IRedis
/// </summary>
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>
/// Explicitly defines a script on the server
/// </summary>
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>
/// <remarks>http://redis.io/commands/shutdown</remarks>
void Shutdown(ShutdownMode shutdownMode = ShutdownMode.Default, CommandFlags flags = CommandFlags.None);
......
......@@ -323,6 +323,18 @@ public RedisResult ScriptEvaluate(string script, RedisKey[] keys = null, RedisVa
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)
{
return this.Inner.SetAdd(this.ToInner(key), values, flags);
......
......@@ -334,6 +334,16 @@ public Task<RedisResult> ScriptEvaluateAsync(string script, RedisKey[] keys = nu
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)
{
return this.Inner.SetAddAsync(this.ToInner(key), values, flags);
......
This diff is collapsed.
......@@ -9,7 +9,8 @@ internal class RedisDatabase : RedisBase, IDatabase
{
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;
}
......@@ -33,7 +34,7 @@ public ITransaction CreateTransaction(object asyncState)
private ITransaction CreateTransactionIfAvailable(object asyncState)
{
var map = multiplexer.CommandMap;
if(!map.IsAvailable(RedisCommand.MULTI) || !map.IsAvailable(RedisCommand.EXEC))
if (!map.IsAvailable(RedisCommand.MULTI) || !map.IsAvailable(RedisCommand.EXEC))
{
return null;
}
......@@ -785,7 +786,8 @@ public bool LockExtend(RedisKey key, RedisValue value, TimeSpan expiry, CommandF
{
if (value.IsNull) throw new ArgumentNullException("value");
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
return KeyExpire(key, expiry, flags);
......@@ -795,7 +797,7 @@ public Task<bool> LockExtendAsync(RedisKey key, RedisValue value, TimeSpan expir
{
if (value.IsNull) throw new ArgumentNullException("value");
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
return KeyExpireAsync(key, expiry, flags);
......@@ -815,7 +817,7 @@ public bool LockRelease(RedisKey key, RedisValue value, CommandFlags flags = Com
{
if (value.IsNull) throw new ArgumentNullException("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
return KeyDelete(key, flags);
......@@ -825,7 +827,7 @@ public Task<bool> LockReleaseAsync(RedisKey key, RedisValue value, CommandFlags
{
if (value.IsNull) throw new ArgumentNullException("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
return KeyDeleteAsync(key, flags);
......@@ -862,10 +864,12 @@ public RedisResult ScriptEvaluate(string script, RedisKey[] keys = null, RedisVa
try
{
return ExecuteSync(msg, ResultProcessor.ScriptResult);
} catch(RedisServerException)
}
catch (RedisServerException)
{
// 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;
}
}
......@@ -875,6 +879,16 @@ public RedisResult ScriptEvaluate(byte[] hash, RedisKey[] keys = null, RedisValu
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)
{
var msg = new ScriptEvalMessage(Db, flags, script, keys, values);
......@@ -886,6 +900,15 @@ public Task<RedisResult> ScriptEvaluateAsync(byte[] hash, RedisKey[] keys = null
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)
{
var msg = Message.Create(Db, flags, RedisCommand.SADD, key, value);
......@@ -1077,7 +1100,7 @@ public IEnumerable<RedisValue> SetScan(RedisKey key, RedisValue pattern = defaul
var scan = TryScan<RedisValue>(key, pattern, pageSize, cursor, pageOffset, flags, RedisCommand.SSCAN, SetScanResultProcessor.Default);
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);
throw ExceptionFactory.NotSupported(true, RedisCommand.SSCAN);
}
......@@ -1665,9 +1688,9 @@ ITransaction GetLockReleaseTransaction(RedisKey key, RedisValue value)
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;
......@@ -1857,7 +1880,7 @@ private Message GetSortedSetRangeByScoreMessage(RedisKey key, double start, doub
var tmp = start;
start = stop;
stop = tmp;
switch(exclude)
switch (exclude)
{
case Exclude.Start: exclude = Exclude.Stop; break;
case Exclude.Stop: exclude = Exclude.Start; break;
......@@ -2132,7 +2155,8 @@ protected override Message CreateMessage(long cursor)
internal sealed class ScriptLoadMessage : Message
{
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");
this.Script = script;
......@@ -2195,7 +2219,8 @@ public ScriptEvalMessage(int db, CommandFlags flags, byte[] hash, RedisKey[] key
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.hexHash = hexHash;
......@@ -2237,7 +2262,7 @@ public IEnumerable<Message> GetMessages(PhysicalConnection connection)
internal override void WriteImpl(PhysicalConnection physical)
{
if(hexHash != null)
if (hexHash != null)
{
physical.WriteHeader(RedisCommand.EVALSHA, 2 + keys.Length + values.Length);
physical.WriteAsHex(hexHash);
......@@ -2273,7 +2298,8 @@ sealed class SortedSetCombineAndStoreCommandMessage : Message.CommandKeyBase //
{
private readonly RedisKey[] keys;
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++)
keys[i].AssertNotNull();
......@@ -2359,7 +2385,7 @@ private class StringGetWithExpiryProcessor : ResultProcessor<RedisValueWithExpir
private StringGetWithExpiryProcessor() { }
protected override bool SetResultCore(PhysicalConnection connection, Message message, RawResult result)
{
switch(result.Type)
switch (result.Type)
{
case ResultType.Integer:
case ResultType.SimpleString:
......
......@@ -375,6 +375,16 @@ public Task<byte[]> ScriptLoadAsync(string script, CommandFlags flags = CommandF
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)
{
Message msg;
......
......@@ -113,6 +113,7 @@
<Compile Include="..\StackExchange.Redis\StackExchange\Redis\MessageCompletable.cs" />
<Compile Include="..\StackExchange.Redis\StackExchange\Redis\MessageQueue.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\PhysicalBridge.cs" />
<Compile Include="..\StackExchange.Redis\StackExchange\Redis\PhysicalConnection.cs" />
......@@ -136,6 +137,7 @@
<Compile Include="..\StackExchange.Redis\StackExchange\Redis\ResultBox.cs" />
<Compile Include="..\StackExchange.Redis\StackExchange\Redis\ResultProcessor.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\ServerCounters.cs" />
<Compile Include="..\StackExchange.Redis\StackExchange\Redis\ServerEndPoint.cs" />
......
......@@ -107,6 +107,7 @@
<Compile Include="..\StackExchange.Redis\StackExchange\Redis\MessageCompletable.cs" />
<Compile Include="..\StackExchange.Redis\StackExchange\Redis\MessageQueue.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\PhysicalBridge.cs" />
<Compile Include="..\StackExchange.Redis\StackExchange\Redis\PhysicalConnection.cs" />
......@@ -130,6 +131,7 @@
<Compile Include="..\StackExchange.Redis\StackExchange\Redis\ResultBox.cs" />
<Compile Include="..\StackExchange.Redis\StackExchange\Redis\ResultProcessor.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\ServerCounters.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