コード例 #1
0
        public object Terminal(string cmd)
        {
            int flag = 0;

            try
            {
                object[]  arr = cmd.Split(" ");
                RedisText rd  = new RedisText();
                rd = _redis.Custom(arr);
                if (rd.Text == null)
                {
                    List <string> terminal_list = new List <string>();
                    foreach (var child in rd.Children)
                    {
                        flag = 1;
                        terminal_list.Add(child.Text);
                    }
                    if (flag == 1)
                    {
                        return(terminal_list);
                    }
                    else
                    {
                        return("Invalid Entry");
                    }
                }
                else
                {
                    return(rd.Text);
                }
            }

            catch (Exception e) { return(e.Message); }
        }
コード例 #2
0
        private bool IsContainerConnected(IRedisClient client, string containerId)
        {
            bool      connected = false;
            RedisText result    = client.Custom("PUBSUB", "channels", "*" + containerId + "*");

            if (result == null)
            {
                return(connected);
            }
            connected = result.GetResults <string>().Count > 0;
            return(connected);
        }
コード例 #3
0
        public void Can_call_LUA_Script_in_transaction()
        {
            using (var trans = this.Redis.CreateTransaction()) {
                trans.QueueCommand(r => r.ExecLua("return {'myval', 'myotherval'}"));

                trans.Commit();
            }

            RedisText result = null;

            using (var trans = this.Redis.CreateTransaction()) {
                trans.QueueCommand(r => r.ExecLua("return {'myval', 'myotherval'}"), s => result = s);

                trans.Commit();
            }

            Assert.That(result.Children[0].Text, Is.EqualTo("myval"));
            Assert.That(result.Children[1].Text, Is.EqualTo("myotherval"));
        }
コード例 #4
0
        public async Task Can_call_LUA_Script_in_transaction()
        {
            await using (var trans = await RedisAsync.CreateTransactionAsync())
            {
                trans.QueueCommand(r => r.ExecLuaAsync("return {'myval', 'myotherval'}", new string[0]));

                await trans.CommitAsync();
            }

            RedisText result = null;

            await using (var trans = await RedisAsync.CreateTransactionAsync())
            {
                trans.QueueCommand(r => r.ExecLuaAsync("return {'myval', 'myotherval'}", new string[0]), s => result = s);

                await trans.CommitAsync();
            }

            Assert.That(result.Children[0].Text, Is.EqualTo("myval"));
            Assert.That(result.Children[1].Text, Is.EqualTo("myotherval"));
        }
コード例 #5
0
        private RateLimitResult GetLimitResult(IRequest request, Limits limits)
        {
            string consumerId = KeyGenerator.GetConsumerId(request);
            string requestId  = KeyGenerator.GetRequestId(request);

            string args = GetLuaArgs(limits, request);

            using (var client = redisClientsManager.GetClient())
            {
                RedisText result = null;
                try
                {
                    // Call lua script to get current hit-rate and overall access/no-access
                    result = client.ExecLuaSha(GetSha1(), new[] { consumerId, requestId }, new[] { args });

                    var rateLimitResult = result.Text.FromJson <RateLimitResult>();
                    return(rateLimitResult);
                }
                catch (RedisResponseException e)
                {
                    log.Error($"Error executing rate-limit Lua script. Called with {args}", e);
                }
                catch (SerializationException e)
                {
                    log.Error(
                        $"Error serialising rate-limit Lua script return to RateLimitResult. Result: {result?.Text}. Called with {args}",
                        e);
                }
                catch (Exception e)
                {
                    log.Error($"Error getting rate-limit result from Redis. Called with {args}", e);
                }
            }

            return(new RateLimitResult());
        }
コード例 #6
0
        public async Task SelectRandomJobs(int nbr, Database databases)
        {
            Random r = new Random();

            if (databases.HasFlag(Database.Couchbase))
            {
                var     options = new QueryOptions().Metrics(true);
                IBucket bucket  = await cluster.BucketAsync("myBucket");

                IScope scope      = bucket.Scope("myScope");
                var    collection = scope.Collection("myCollection");

                long et  = 0;
                int  lim = 10;
                for (int q = 0; q < lim; q++)
                {
                    List <Task> tasks = new List <Task>();
                    Stopwatch   sw    = Stopwatch.StartNew();
                    for (int i = 0; i < nbr; i++)
                    {
                        string query = $"SELECT * FROM myCollection WHERE JobId = {r.Next(1, 100000)}";
                        //tasks.Add(scope.QueryAsync<dynamic>(query));
                        //var queryResult =  await scope.QueryAsync<dynamic>(query);
                        //var content = queryResult.Rows;

                        string key    = $"{r.Next(1, 100000)}";
                        var    result = await collection.GetAsync(key, options : new GetOptions().Transcoder(new LegacyTranscoder()));

                        var content = result.ContentAs <string>();
                    }
                    // await Task.WhenAll(tasks);
                    sw.Stop();
                    Console.WriteLine($"Couchbase Q: {q}\t{sw.ElapsedMilliseconds}");
                    et = et + sw.ElapsedMilliseconds;
                }
                Console.WriteLine($"average et: {et/lim} ms per {nbr} -> {et/lim * 1000 / nbr} usec / request");
            }


            if (databases.HasFlag(Database.Redis))
            {
                for (int q = 0; q < 10; q++)
                {
                    Stopwatch sw = Stopwatch.StartNew();
                    using (var client = redisManager.GetClient())
                    {
                        for (int i = 0; i < nbr; i++)
                        {
                            client.Get <string>($"jobId:{r.Next(1, 100000)}");
                        }
                    }
                    sw.Stop();
                    Console.WriteLine($"Redis Q: {q}\t{sw.ElapsedMilliseconds}");
                }
            }

            if (databases.HasFlag(Database.MySql))
            {
                MySqlConnection mySqlConnection = new MySqlConnection("Server=localhost;Database=test;port=3306;User Id=root;password=root;");
                mySqlConnection.Open();

                for (int q = 0; q < 10; q++)
                {
                    Stopwatch sw = Stopwatch.StartNew();
                    for (int i = 0; i < nbr; i++)
                    {
                        MySqlCommand cmd = new MySqlCommand($"SELECT data FROM test WHERE Id='{r.Next(1, 100000)}'", mySqlConnection);
                        using MySqlDataReader rdr = cmd.ExecuteReader();

                        while (rdr.Read())
                        {
                        }
                    }
                    sw.Stop();
                    Console.WriteLine($"MySql Q: {q} \t{sw.ElapsedMilliseconds} ms");
                    sw.Reset();
                }
            }


            if (databases.HasFlag(Database.Aerospike))
            {
                for (int q = 0; q < 10; q++)
                {
                    Stopwatch sw = Stopwatch.StartNew();
                    for (int i = 0; i < nbr; i++)
                    {
                        Record record = aeroClient.Get(null, new Key("test", "cache", r.Next(1, 100000).ToString()), "Data");
                    }
                    sw.Stop();
                    Console.WriteLine($"Aerospike Q: {q} \t{sw.ElapsedMilliseconds} ms");
                    sw.Reset();
                }
            }

            if (databases.HasFlag(Database.RediSql))
            {
                for (int q = 0; q < 10; q++)
                {
                    Stopwatch sw = Stopwatch.StartNew();
                    using (var client = redisManager.GetClient())
                    {
                        for (int i = 0; i < nbr; i++)
                        {
                            RedisText t = RediSqlCommand(client, "db", $"SELECT * FROM jobcache WHERE Id={r.Next(1, 100000)}");
                        }
                    }
                    sw.Stop();
                    Console.WriteLine($"RediSql Q: {q}\t{sw.ElapsedMilliseconds}");
                }
            }
        }