C # Redis

Source: Internet
Author: User
Tags net thread redis server

C # Redis
    1. Publish subscription model
    2. Publish subscriptions in Redis
    3. Client Programming examples
    4. 0.3 version Hredis
Publish subscription model

At the application level its role is to reduce dependencies, often also called observer patterns. The main point is to separate the coupling points out as a third party, isolating the easily changing sender and receiver.

Sender: Only responsible for sending messages to third parties. (the magazine gives the reader magazine to the Post Office)
Receiver: passively receives the message. (1: Subscribe to the Post Office Reader magazine, 2: The door to the magazine to receive mail)
Third-party functions: Store subscribers to the magazine and send it to the receiver when the magazine comes in. Post Office

C # example, the sender puts the magazine inside the Post office:

    if (QA. Addbug ())            emailnotify ();
The receiving party to the Post Office to register the address, has the magazine to come home delivery:
    Emailnotify + = () = {Console.WriteLine ("a June");};    Emailnotify + = () = {Console.WriteLine ("b June");};

The third-party post office receives the reader magazine subscription and dispatches it when it receives the magazine:

    public delegate void MessageHandler ();    public static event MessageHandler  emailnotify;        if (QA. Addbug ())            emailnotify ();

When we zoom in on the observer pattern to the system level, it is the Publish subscription (Pub/sub). It is mainly used to reduce the coupling between publishers and subscribers and improve the throughput of the front-end system. Structure

Publish subscriptions in Redis

Redis implements a full publish-subscribe paradigm, which means that any Redis server can be used as a publishing subscriber after startup.

General Subscription

Start subscriber Client.

Redis-cli.exe-h 127.0.0.1-p 6379

Subscribe to the Bar channel. Format: SUBSCRIBE name1 name2.
A successful subscription response, corresponding to the subscription type, subscription channel, number of subscriptions.

127.0.0.1:6379> SUBSCRIBE barreading Messages ... (Press Ctrl-c to quit) 1) "Subscribe" 2) "Bar" 3) (integer) 1

A new publisher client, sending a message. Format: Publish ChannelName Message.

127.0.0.1:6379> Publish bar val (integer) 1

Subscribe to the client reply, corresponding to the message type, channel, message.

1) "Message" 2) "bar" 3) "Val"

Legend

Mode subscription

Redis supports pattern matching subscriptions, * for fuzzy matches.
Subscribe to all channel messages

Psubscribe *  

Subscribe to all channels that start with news.

Psubscribe news.*
Cancel Subscription

The command to cancel the normal and cancel mode subscriptions.

Unsubscribe  barpunsubscribe  ba*

Cancellation cannot be simulated in the official connection tool.

View subscription information

Viewing subscription messages is one of the commands that Redis adds to the 2.8 center.

PubSub channels [pattern].

Returns all the channels that the current server is subscribed to.

127.0.0.1:6379> pubsub channels1) "Bar"

Specify the matching parameters to return all channels that match the pattern.

127.0.0.1:6379> pubsub channels ba*1) "Bar"
PubSub numsub [channel-1 channel-2 ... channel-n]

Accept as many channels as input parameters to return the number of subscribers to these channels.

127.0.0.1:6379> pubsub numsub  bar bar21) "Bar" 2) (integer) "Bar2" 4) (integer) 0
Client Programming examples
            Redispubsub client = new Redispubsub ("127.0.0.1", 6381);            Client. Onunsubscribe + = (obj) = {                Console.WriteLine ();            };            Client. OnMessage = (sender, Arcgs) =>{                Console.WriteLine (ARCGS);            };            Client. OnError = (Exception) = {                 Console.WriteLine (exception.message);            };            Client. Subscribe ("Bar");            Console.ReadLine ();
0.3 version Hredis Basic use
    using (redisclient client = new Redisclient ("127.0.0.1", 6381))        {            client. Set ("Key", "value");            Client. Get ("key");        }
Use connection pooling to automatically reclaim connections.
        Poolredisclient PRC = new Poolredisclient (new Poolconfiguration ());        Prc. Single.set ("Key", "value");        Prc. Single.get ("key");
and the above subscription.

C # Redis Series (ii)-hredis client design and open source 2015-04-18 08:02 by Mr. Mushroom, 1155 Read, collection, compilationAfter the implementation of the C # Redis client (a), re-organized the next. Reading table of Contents: Project description Hredis Design Unit Test Scenario Summary Project description background: Because there is a place to use, but did not find a good support for sentinel NET client, so simply rewrite. Objective: As simple as possible, lightweight, not excessive encapsulation, easy to use. Code Description: 1. With Redis ...
    • 6 Comment
AutoMapper User Manual (i) 2015-02-14 18:00 by Mr. Mushroom, 948 read, collection, compilationRead Catalogue 1. Introduction 2. Basic use 3. Auto-split mapping (Flattening) 4. Custom field Mapping (Projection) 5. Validation configuration (configuration validation) Introduction AutoMapper is a lightweight class library, The main function is to convert an object into another object, and avoid each of us ...
    • 1 Comment
NET job scheduling (v)-quartz.net dynamic Add job design 2015-01-19 08:42 by Mr. Mushroom, 1623 Read, collection, compilationIntroduction in the actual project use in the Quartz.net, want to have a management interface can dynamically add job, and avoid every time to launch. Also saw the garden classmate asked. Here is the introduction of the implementation of dynamic add job several ways, but also two times the core module development. Catalog One: Traditional way two: Frame reflection mode Three: Process mode four: URL way five: Framework configuration Way Six: summary one: Traditional Way 1: ...
    • Comment
NET job scheduling (iv)-quartz.net persistence and clustering 2015-01-18 15:17 by Mr. Mushroom, 1240 Read, collection, compilationIntroduced in the actual use of quartz.net. Persistence can ensure that the job is not lost after the instance restarts, the cluster can balance the server pressure and solve the single point problem. Quartz.net in this two block configuration is more convenient, look. One: Persistent quartz.net is the persistence of the job, trigger some information stored in the database in order to resolve the memory storage restart loss. 1: Download SQL script ...
    • 5 Comment
C # Implementing Redis Client (i) 2015-01-12 08:55 by Mr. Mushroom, 1678 Read, collection, compilationThe Redis client is being modified in the recent project use. Just read the following document, summarize and share a bit. Directory One: Protocol Specification II: Basic communication three: status Command four: set, get command five: Pipeline, transaction Six: Summary one: Protocol specification Redis allows clients to connect in TCP, the default 6379 port. The transfer data ends with \ r \ n. Request Format *\r\n$\r\n\r\n Example: *1\r\n$ ...
    • 0 Comment
Log system Combat (iii)-NET implementation of distributed tracking 2014-12-13 20:16 by Mr. Mushroom, 1728 Read, collection, compilationIn the development and debugging of large-scale systems, the interlock between the cross-systems began to become less. Inexplicably a mistake burst out, although the log has a record, but in the end is where the problem? is the iOS side parameter transmitted wrong? Or is the interface provided by a system or B system caused? I believe we have met a lot, most of the problems are not big, but difficult to troubleshoot. Let's take a look at the concrete implementation. Catalog One: Overview Two: Web Ring ...
    • 8 Comment
Log system Combat (ii)-AOP Dynamic acquisition of runtime data 2014-11-27 08:22 by Mr. Mushroom, 1624 Read, collection, compilationThe introduction of this article from the previous one has been dragged for 3 months, criticized himself under. Through the previous article. We can take out compiled static data, such as method parameter information, through the mono reflection code. But the reality is: I need to run the data, is the user input and other external dynamic data. Since it is dynamic, it is unknown. How do we get through the pre-injected code? Actually this is a question of thinking, below ...
    • 7 Comment
NET job scheduling (iii)-quartz.net advanced 2014-11-17 22:32 by Mr. Mushroom, 488 Read, collection, compilationWe introduce the basic usage of quartz.net in front of us, but in practical applications, there are often more characteristic requirements. For example, record the execution history of job execution, send mail and so on. Directory 1:quartz.net plug-in 2:triggerlistener,joblistener3:cron expression 4:quartz.net thread pool 5: summary quartz.net plugin ...
    • 2 Comment
NET job scheduling (ii)-crystalquartz remote Management 2014-11-01 18:21 by Mr. Mushroom, 712 Read, collection, compilationSource Code-1.6m Introduction then the previous article. We've already started using quartz.net. But if you want to easily know the execution of a job, and pause, start, and so on, you need a management interface. This article describes quartz.net remote management. : Combat one: Job server static void Main (string[] args) ...
    • Ten Comment
NET job scheduling (i)-quartz.net Getting Started 2014-11-01 13:14 by Mr. Mushroom, 850 read, collection, compilationBackground a lot of times, projects need to perform one or many different jobs at different times. The Windows execution plan does not meet the requirements very well at this time. At this time, a more powerful, easy to manage, set deployment of job scheduling. Introduction Quartz an open source job scheduling framework, Opensymphony Open source project. Quartz.net is a C # ported version of Quartz. It's a ...
    • 0 Comment
Log system Combat (i)-AOP static injection 2014-08-24 13:00 by Mr. Mushroom, 659 Read, collection, compilationBackground in the recent writing log system, it is necessary to inject log records within the function at runtime, with function information. This is the way to think about AOP. Technical Analysis AOP Sub-dynamic injection and static injection. Dynamic Injection Mode 1: Use Remoting's ContextBoundObject or MarshalByRefObject. 2: Dynamic Proxy (reflection), most AOP frameworks are used this way ...
    • 4 Comment
Column Storage Design Tips 2014-06-02 11:37 by Mr. Mushroom, 191 read, collection, compilationBackground: Develop a student system, database design. Design and implementation: Traditional database student table design number name Gender Age 1 Three men 162 Li Hong Female 153 Wang 16 when you want to extend the property, the field is incremented. School name Gender age address 1 Three men 16 Henan 2 Li Hong Female 15 Hubei 3 Wang 16 Beijing actual development in the shortcomings: 1: Attribute field to the main table adds, will cause more and more columns, increase the table ...
    • 0 Comment

Open Source Address Https://github.com/mushroomsir/HRedis

C # 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.