Redis summary note (ii) : C connects Redis simple example

  • 2020-05-09 19:36:26
  • OfStack

Note: C# do not use the ServiceStack.Redis driver version 4.0 when calling Redis, as this version has been commercialized and will have a limit of 6000 data per hour

1. Reference driver


    using ServiceStack.Redis;

2. Database connection

    RedisClient client;
            // Connect to server    6379 is redis Default port
            client = new RedisClient("127.0.0.1", 6379);
    client.Password = "";// Set the password No comments can be made           //10 Ten thousand data tests I found used set The efficiency is significantly higher than the use store It was very efficient and I found it during the test store Will be lost 7-80 The number of left and right bars set but 1 I haven't lost any of them
          Stopwatch sw = new Stopwatch();
            sw.Start();             for (int i = 0; i < 100000; i++)
            {
                client.Set<GPS>(Guid.NewGuid().ToString(), new GPS
                {
                    direction = 287,
                    gps_time = "1417622213418",
                    lati = 29.310586,
                    longi = 120.125143,
                    pla_no = " zhejiang A12345",
                    pla_type = 1,
                    speed = 23.5,
                    state = 0,
                    carstate = 0,
                    upload_time = "1417622088418"
                });                 client.Store<GPS>(
                    new GPS
                {
                    direction = 287,
                    gps_time = "1417622213418",
                    lati = 29.310586,
                    longi = 120.125143,
                    pla_no = " zhejiang A12345",
                    pla_type = 1,
                    speed = 23.5,
                    state = 0,
                    carstate = 0,
                    upload_time = "1417622088418"
                });
            }
            sw.Stop();
            Console.WriteLine(sw.ElapsedMilliseconds);  decimal price = client.Get<decimal>("price");// To get the data
 


Related articles: