Redis Summary Note (ii): simple example of C # connection to Redis

Source: Internet
Author: User

Reproduced in: http://www.itxuexiwang.com/a/shujukujishu/redis/2016/0216/113.html?1455860686

Note: C # does not use the 4.0 version of the Servicestack.redis driver when calling Redis? Because this version has been commercialized, there will be a limit of 6,000 data per hour

1. Reference driver

The code is as follows:


Using Servicestack.redis;


2. Database connection

The code is as follows:


Redisclient client;
Connection Server 6379 is the default port for Redis
Client = new Redisclient ("127.0.0.1", 6379);
Client. Password = "";//Setting the password can not be commented

100,000 data tests, I found the efficiency of using set is significantly more efficient than using the store, and I found in the test that the store lost 7-80 or so of the number and set was not lost
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 = "Zhe A12345", #p # page title #e#
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 = "Zhe 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");//Get Data

Redis Summary Note (ii): simple example of C # connection to Redis

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.