Stackexchange.redis Use-synchronous asynchronous instant discard (iii)

Source: Internet
Author: User

Accessing a single server

Sometimes you need to specify a specific command for a single server.

IServer Server = Redis. Getserver ("localhost", 6379);

The Getserver method receives a endpoint class or a key-value pair that uniquely identifies a single server. The Getserver method returns a Iserver object. Method can also be asynchronous and only need to pass in a async-state

You can use the following methods to get all available endpoints:
endpoint[] Endpoints = Redis. Getendpoints ();

Using Iserver, you can use all of the shell commands, such as:

DateTime lastsave = server. Lastsave ();
clientinfo[] Clients = server. Clientlist ();

If the error is added after the connection string, allowadmin=true;


synchronous, asynchronous, ready-to-discard

This is the three main use mechanism of Stackexchange.redis:
Synchronous-Blocks the caller before the method returns (although it blocks the caller but never blocks other threads, the key in Stackexchange.redis is the connection between the shared callers)

Asynchronous-At some point in the future, a Task or task<t> will be returned immediately after the operation is completed:
. Wait () blocks the current thread until processing is complete.
ContinueWith Add a callback function
Using await this is an advanced feature that simplifies the operation

That is, discard-

The method of synchronous invocation has been demonstrated in the previous example.

Asynchronous invocation:
String value = "ABCDEFG";
Await DB. Stringsetasync ("MyKey", value);
...
String value = Await db. Stringgetasync ("MyKey");
Console.WriteLine (value); Writes: "ABCDEFG"


That is, discard: by configuring the Commandflags to implement the Discard function, in which the method returns immediately, if it is a string returns null if it is an int returns 0. This operation will continue to run in the background, a typical usage page counter implementation:
Db. Stringincrement (Pagekey, flags:CommandFlags.FireAndForget);

Stackexchange.redis Use-synchronous asynchronous instant discard (iii)

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.