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)