Exemple #1
0
        public static void Main(string[] args)
        {
            // Run MONITOR command on redis-cli to display the commands that are being executed
            using (var redis = ConnectionMultiplexer.Connect("127.0.0.1"))
            {
                var redisDb = redis.GetDatabase();
                var server  = redis.GetServer("127.0.0.1:6379");

                // Reset the key
                redisDb.KeyDelete("statistics");

                // Converts the script to a single line in order to be loaded to Redis
                // Also does some StackExchange.Redis specific arguments replacement
                LuaScript prepared = LuaScript.Prepare(File.ReadAllText("calculate_stats.lua"));

                // Loads the script into the server and returns the SHA
                LoadedLuaScript loaded = prepared.Load(server);
                Console.WriteLine("Script SHA is " + BitConverter.ToString(loaded.Hash).Replace("-", String.Empty));

                for (int i = 1; i <= 5; ++i)
                {
                    loaded.Evaluate(redisDb, new { key = (RedisKey)"statistics", value = 10 * i });
                }
            }
        }
        public void Run()
        {
            var timestamp = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds();

            var metric = metrics[rand.Next(metrics.Count)];

            loaded.Evaluate(db, new
            {
                metricKey = (RedisKey)metric,
                timestamp,
                count = 1,
                min   = 1,
                max   = 1,
                sum   = 1,
            });
        }
Exemple #3
0
 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(Inner, parameters, Prefix, flags));
 }