public void Benchmark_SET_raw_bytes_1k_ServiceStack()
        {
            var redis = new RedisNativeClient();

            Run("ServiceStack.Redis 1K", 1000,
                (i, bytes) => redis.Set("eitan" + i.ToString(), bytes));
        }
        public void Test_Throughput()
        {
            var bytes = RandomBytes(MessageSizeBytes);
            var swTotal = Stopwatch.StartNew();

            var key = "test:bandwidth:" + bytes.Length;

            int bytesSent = 0;
            int bytesRecv = 0;

            using (var redisClient = new RedisNativeClient(RedisServer))
            {
                Count.Times(x =>
                {
                    var sw = Stopwatch.StartNew();

                    redisClient.Set(key, bytes);
                    bytesSent += bytes.Length;
                    "SEND {0} bytes in {1}ms".Print(bytes.Length, sw.ElapsedMilliseconds);

                    sw.Reset();
                    sw.Start();
                    var receivedBytes = redisClient.Get(key);
                    bytesRecv += receivedBytes.Length;
                    "RECV {0} bytes in {1}ms".Print(receivedBytes.Length, sw.ElapsedMilliseconds);

                    "TOTAL {0} bytes SENT {0} RECV {1} in {2}ms\n".Print(
                        bytesSent, bytesRecv, swTotal.ElapsedMilliseconds);
                });
            }
        }
Exemple #3
0
 public void Set(string keyName, string content)
 {
     using (var client = new RedisNativeClient(ConfigurationManager.AppSettings["RedisServer"]))
     {
         client.Set(keyName, Encoding.UTF8.GetBytes(content));
     }
 }
        public void Test_Throughput()
        {
            var bytes   = RandomBytes(MessageSizeBytes);
            var swTotal = Stopwatch.StartNew();

            var key = "test:bandwidth:" + bytes.Length;

            int bytesSent = 0;
            int bytesRecv = 0;

            using (var redisClient = new RedisNativeClient(RedisServer))
            {
                Count.Times(x =>
                {
                    var sw = Stopwatch.StartNew();

                    redisClient.Set(key, bytes);
                    bytesSent += bytes.Length;
                    "SEND {0} bytes in {1}ms".Print(bytes.Length, sw.ElapsedMilliseconds);

                    sw.Reset();
                    sw.Start();
                    var receivedBytes = redisClient.Get(key);
                    bytesRecv        += receivedBytes.Length;
                    "RECV {0} bytes in {1}ms".Print(receivedBytes.Length, sw.ElapsedMilliseconds);

                    "TOTAL {0} bytes SENT {0} RECV {1} in {2}ms\n".Print(
                        bytesSent, bytesRecv, swTotal.ElapsedMilliseconds);
                });
            }
        }
Exemple #5
0
    protected void btnRedisadd(object sender, EventArgs e)
    {
        RedisNativeClient rclient = new RedisNativeClient("192.168.1.207", 6379);
        string            keyval  = key0.Text.Trim();
        string            val     = value0.Text.Trim();

        byte[] value  = System.Text.Encoding.Default.GetBytes(val);
        int    extime = int.Parse(expiret.Text.Trim());

        try
        {
            var result = rclient.Set(keyval, value, false, extime * 60, long.Parse(expiret.Text.Trim()));

            if (result)
            {
                Response.Write("<script>window.alert('添加成功!');window.location.href='../Mem_RedisTest.aspx'</script>");
            }
            else
            {
                Response.Write("<script>window.alert('添加失败!');window.location.href='../Mem_RedisTest.aspx'</script>");
            }
        }
        catch
        {
            Response.Write("<script>window.alert('添加失败!');window.location.href='../Mem_RedisTest.aspx'</script>");
        }
    }
        public void Test_Throughput()
        {
            var bytes   = this.RandomBytes(_messageSizeBytes);
            var swTotal = Stopwatch.StartNew();

            var key = "test:bandwidth:" + bytes.Length;

            var bytesSent = 0;
            var bytesRecv = 0;

            using (var redisClient = new RedisNativeClient(Config.MasterHost)) {
                for (var i = 0; i < _count; i++)
                {
                    var sw = Stopwatch.StartNew();
                    redisClient.Set(key, bytes);
                    bytesSent += bytes.Length;
                    Console.WriteLine("SEND {0} bytes in {1}ms", bytes.Length, sw.ElapsedMilliseconds);

                    sw.Reset();
                    sw.Start();
                    var receivedBytes = redisClient.Get(key);
                    bytesRecv += receivedBytes.Length;
                    Console.WriteLine("RECV {0} bytes in {1}ms", receivedBytes.Length, sw.ElapsedMilliseconds);
                    Console.WriteLine("TOTAL {0} bytes SENT {0} RECV {1} in {2}ms\n", bytesSent, bytesRecv, swTotal.ElapsedMilliseconds);
                }
            }
        }
        public void Benchmark_SET_raw_bytes_8MB()
        {
            var redis = new RedisNativeClient(Config.MasterHost);

            this.Run("ServiceStack.Redis 8MB",
                     8000000,
                     (i, bytes) => redis.Set("eitan" + i.ToString(), bytes));
        }
Exemple #8
0
        public bool SetValueIfNotExists(string key, string value, int expirySeconds)
        {
            if (!this.IsValidValue(value))
            {
                return(false);
            }

            RedisNativeClient client = this.pool.GetRedisClient(key);

            return((client == null) ? false : client.Set(key, UTF8String.ToBytes(value), exists: false, expirySeconds: expirySeconds));
        }
Exemple #9
0
        /// <summary>
        /// 设置key 的值和保存时间
        /// </summary>
        /// <param name="key"></param>
        /// <param name="session_message"></param>
        /// <param name="expire_minutes"></param>
        public static void SetSession(string key, object session_message, int expire_minutes)
        {
            if (key == "-1")
            {
                return;
            }
            string redis_key = "SESS_" + key;

            byte[] bytes = Encoding.UTF8.GetBytes((string)JsonHelper.ToJson(session_message));
            using (RedisNativeClient RNC = GetNativeClientForKeySpace(space))
            {
                RNC.Set(redis_key, bytes);
                RNC.Expire(redis_key, Convert.ToInt32(new TimeSpan(0, expire_minutes, 0).TotalSeconds));
            }
        }
Exemple #10
0
        /// <summary>
        /// 设置Session,不过期。如果要修改一个Session为永不过期,需要单独调用SetSessioNeverExpire
        /// </summary>
        /// <param name="session_key"></param>
        /// <param name="session_obj"></param>
        /// <param name="ts"></param>
        /// <returns></returns>
        public static void SetSession(string key, object session_message)
        {
            if (key == "-1")
            {
                return;
            }
            string redis_key = "SESS_" + key;

            byte[] bytes = Encoding.UTF8.GetBytes((string)JsonHelper.ToJson(session_message));

            using (RedisNativeClient RNC = GetNativeClientForKeySpace(redis_key))
            {
                RNC.Set(redis_key, bytes);
            }
        }
Exemple #11
0
        //------------------------------------------------------------------
        // STRING

        public bool Set(string key, string value)
        {
            if (!this.IsValidValue(value))
            {
                return(false);
            }

            // Get the corresponding Redis client.
            RedisNativeClient client = this.pool.GetRedisClient(key);

            if (client == null)
            {
                return(false);
            }

            client.Set(key, UTF8String.ToBytes(value));
            return(true);
        }