Redis environment setup and use (C #),

Source: Internet
Author: User

Redis environment setup and use (C #),

Redis

Redis is an open-source log-type and Key-Value database written in ansi c language that supports Network, memory-based persistence, and provides APIs in multiple languages.

Redis is a key-value storage system. Similar to Memcached, Memcached supports more storage value types, including string, list, set, and zset) and hash (hash type ). These data types support push/pop, add/remove, Intersection Set and difference set, and more abundant operations, and these operations are atomic. On this basis, redis supports sorting in different ways. Like memcached, data is cached in the memory to ensure efficiency. The difference is that redis periodically writes the updated data to the disk or writes the modification operation to the append record file, and on this basis implements master-slave (master-slave) synchronization.

Redis is a high-performance key-value database. The emergence of redis largely compensates for the shortage of key/value storage such as memcached, and can play a good complementary role in relational databases in some cases. It provides clients such as Java, C/C ++, C #, PHP, JavaScript, Perl, Object-C, Python, Ruby, and Erlang for ease of use. Redis supports master-slave synchronization. Data can be synchronized from the master server to any number of slave servers. The slave server can be the master server associated with other slave servers. This allows Redis to perform single-layer tree replication. You can intentionally or unintentionally write data to a disk. Because the publishing/subscription mechanism is fully implemented, you can subscribe to a channel and receive the complete message publishing records of the master server when synchronizing the tree from the database anywhere. Synchronization is helpful for the scalability and data redundancy of read operations. Install and test my environment here is windows 7 installation address: https://github.com/dmajkic/redis/downloadsextract to any directory, double run resis-server.exe test needs to execute redis-cli.exe can also be registered to windows service, you need to download the service installation component https://github.com/rgl/redis/downloads to start the service after the test (get set) So far, the installation has been completed C # To create a C # project, add redis reference, use the Microsoft recommended ServiceStack. redis, VS2013 is recommended, otherwise the installation will fail.
Using ServiceStack. redis; using System. collections. generic; using System. linq; using System. text; using System. threading; namespace TestRedis {class Program {static void Main (string [] args) {PooledRedisClientManager prcm = CreateManager (); // read/write client using (IRedisClient Redis = prcm. getClient () {Redis. set ("test", "testvalue" + DateTime. now. toString (), DateTime. now. addDays (10);} // read-only client using (IRedisClient Redis = prcm. getReadOnlyClient () {Console. writeLine (Redis. get <string> ("test");} Console. writeLine ("-----"); Thread. sleep (1, 15000); Console. writeLine ("-----"); using (IRedisClient Redis = prcm. getReadOnlyClient () {Console. writeLine ("15 seconds later:" + Redis. get <string> ("test");} Console. read ();} public static PooledRedisClientManager CreateManager () {// supports Read/write splitting and Server Load balancer. You must separately deploy return new PooledRedisClientManager (new string [] {"10.58.8.239: 6379 "} // used for writing, new string [] {" 10.58.8.239: 6379 "} // used for reading, new RedisClientManagerConfig {MaxWritePoolSize = 10, // "write" link pool connection count MaxReadPoolSize = 10, // "write" link pool connection count AutoStart = true ,});}}}

 

 

Author: Sakya bitter monk Source: http://www.cnblogs.com/woxpp/p/5007623.html this article copyright belong to the author and blog park a total, welcome to reprint, but without the author's consent must retain this paragraph of the statement, and in the Article Page clearly given the original connection.

 

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.