/// <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)); }
/// <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)); }
internal void ExtractParameters(object ps, RedisKey?keyPrefix, out RedisKey[] keys, out RedisValue[] args) { if (HasArguments) { if (ps == null) { throw new ArgumentNullException(nameof(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> /// <para>Evaluates this LoadedLuaScript against the given database, extracting parameters for the passed in object if any.</para> /// <para> /// 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. /// </para> /// </summary> /// <param name="db">The redis database to evaluate against.</param> /// <param name="ps">The parameter object to use.</param> /// <param name="withKeyPrefix">The key prefix to use, if any.</param> /// <param name="flags">The command flags to use.</param> public RedisResult Evaluate(IDatabase db, object ps = null, RedisKey?withKeyPrefix = null, CommandFlags flags = CommandFlags.None) { Original.ExtractParameters(ps, withKeyPrefix, out RedisKey[] keys, out RedisValue[] args);