Redis study Note 1

Source: Internet
Author: User

1. Install redis with a green version, which is convenient and easy to configure;

2. I tested master-slave replication, but the effect was not performed on a large scale. I don't know much about it. The master can read and write, but the slave can only read. This feature can be used for read/write splitting to improve throughput performance;

3. I accessed it with C # (servicestack. redis). Nothing special;

4. servicestack is not a traditional thread security. It is only applicable to each thread to use its own redisclient. Multiple Threads may still use the same client. Of course, the potential problem is deadlock.


Using (redisclient = new redisclient (host, 6379) {// gets the value of the specified key, not null; string thev = redisclient. get <string> (elementkey); this. textbox1.text = thev; // set a key-value pair. If the key exists, modify it. // This generic encapsulation is specially converted for the C # type in the author library, which can simplify your programming. redis itself does not have such a rich variety of types. redisclient. set <string> ("keyaaa", "sadfsdffdsa"); // transaction using (iredistransaction IRT = redisclient. createtransaction () {try {IRT. queuecommand (r => r. set ("Key A ", 20); IRT. queuecommand (r => r. increment ("Keya", 1); // Note: if the following statement exists, an error is returned when you submit the transaction, this indicates that all the // client operations after starting the transaction must be called within IRT. // redisclient. set <string> ("keyabc", "sadfsdffdsa"); // throw new exception ("database operation error! "); // Submit the transaction IRT. commit ();} catch {IRT. rollback ();} // Keya does not exist, but the keyabc value exists. string thev1 = redisclient. get <int> ("Keya "). tostring (); string thev2 = redisclient. get <string> ("keyabc"); // concurrent lock redisclient. add ("mykey", 1); // iredistypedclient and iredisclient are supported. // note that this is a form call, which cannot be tested. If it is a Web application, the lock effect can be obtained. using (redisclient. acquirelock ("testlock") {var counter = redisclient. get <int> ("mykey"); thread. sleep (100); redisclient. set ("mykey", counter + 1 );}}}

Redis study Note 1

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.