示例#1
0
        /// <summary>
        /// Run a lua script against the connected redis instance
        /// </summary>
        /// <param name="script">the script to run. Keys should be @Key1, @Key2 ... @Key10. Int arguments: @IntArg1 .. @IntArg20. String arguments: @StringArg1 .. @StringArg20</param>
        /// <param name="keysAndParameters">an instance of RedisScriptKeysAndArguments</param>
        /// <returns></returns>
        private RedisResult RunScriptInternal(string script, RedisScriptKeysAndArguments keysAndParameters)
        {
            var conn = this.Connection;
            var db   = conn.GetDatabase(this.DatabaseNumber);

            if (!this.loadedScripts.TryGetValue(script, out var loadedLuaScript))
            {
                var server   = conn.GetServer(hosts.First());
                var prepared = LuaScript.Prepare(script);
                this.loadedScripts[script] = loadedLuaScript = prepared.Load(server);
            }

            try
            {
                return(loadedLuaScript.Evaluate(db, keysAndParameters));
            }
            catch (RedisServerException)
            {
                // TODO: validate that the message is NOSCRIPT
                var server   = conn.GetServer(hosts.First());
                var prepared = LuaScript.Prepare(script);
                this.loadedScripts[script] = loadedLuaScript = prepared.Load(server);

                // run
                return(loadedLuaScript.Evaluate(db, keysAndParameters));
            }
        }
示例#2
0
        /// <summary>
        /// Run a lua script against the connected redis instance
        /// </summary>
        /// <param name="script">the script to run. Keys should be @Key1, @Key2 ... @Key10. Int arguments: @IntArg1 .. @IntArg20. String arguments: @StringArg1 .. @StringArg20</param>
        /// <param name="keysAndParameters">an instance of RedisScriptKeysAndArguments</param>
        /// <returns>result as string[]</returns>
        public string[] RunScriptStringArray(string script, RedisScriptKeysAndArguments keysAndParameters)
        {
            var result = Retry(() => this.RunScriptInternal(script, keysAndParameters), defaultRetries);

            return((string[])result);
        }
示例#3
0
        /// <summary>
        /// Run a lua script against the connected redis instance
        /// </summary>
        /// <param name="script">the script to run. Keys should be @Key1, @Key2 ... @Key10. Int arguments: @IntArg1 .. @IntArg20. String arguments: @StringArg1 .. @StringArg20</param>
        /// <param name="keysAndParameters">an instance of RedisScriptKeysAndArguments</param>
        /// <returns>result as string</returns>
        public long RunScriptLong(string script, RedisScriptKeysAndArguments keysAndParameters)
        {
            var result = Retry(() => this.RunScriptInternal(script, keysAndParameters), defaultRetries);

            return((long)result);
        }
示例#4
0
        /// <summary>
        /// Run a lua script against the connected redis instance
        /// </summary>
        /// <param name="script">the script to run. Keys should be @Key1, @Key2 ... @Key10. Int arguments: @IntArg1 .. @IntArg20. String arguments: @StringArg1 .. @StringArg20</param>
        /// <param name="keysAndParameters">an instance of RedisScriptKeysAndArguments</param>
        /// <returns>result as double</returns>
        public double RunScriptDouble(string script, RedisScriptKeysAndArguments keysAndParameters)
        {
            var result = Retry(() => this.RunScriptInternal(script, keysAndParameters), defaultRetries);

            return((double)result);
        }
示例#5
0
 /// <summary>
 /// Run a lua script against the connected redis instance
 /// </summary>
 /// <param name="script">the script to run. Keys should be @Key1, @Key2 ... @Key10. Int arguments: @IntArg1 .. @IntArg20. String arguments: @StringArg1 .. @StringArg20</param>
 /// <param name="keysAndParameters">an instance of RedisScriptKeysAndArguments</param>
 public void RunScript(string script, RedisScriptKeysAndArguments keysAndParameters)
 {
     Retry(() => this.RunScriptInternal(script, keysAndParameters), defaultRetries);
 }