Stackexchange.redis Use-Configuration (iv)

Source: Internet
Author: User
Tags redis version redis server

Configuration
Redis has a number of different ways to configure the connection string, and Stackexchange.redis provides a rich configuration model that needs to be passed in when connect or ConnectAsync is called.

var conn = connectionmultiplexer.connect (configuration);

The configuration parameters here can be:
1. An instance of Configurationoptions
2. A string

The second approach is fundamentally configurationoptions.


Configuring Connections Through strings

The simplest configuration requires only one host name

var conn = Connectionmultiplexer.connect ("localhost");

It will connect to the local Redis server, the default 6379 port, and multiple connections are separated by commas. The other options include a "=" after the name. For example
var conn = Connectionmultiplexer.connect ("Redis0:6380,redis1:6380,allowadmin=true");

You can convert a string to configurationoptions or convert a configurationoptions to a string.
Configurationoptions options = Configurationoptions.parse (configstring);
OR
String configstring = Options. ToString ();

The recommended usage is to save the underlying information in a string, and then to change the other information in the run through Configurationoptions.
String configstring = Getredisconfiguration ();
var options = Configurationoptions.parse (configstring);
Options. ClientName = Getappname (); Only known at runtime
Options. Allowadmin = true;
conn = Connectionmultiplexer.connect (options);

You can also specify a password
var conn = Connectionmultiplexer.connect ("contoso5.redis.cache.windows.net,ssl=true,password= ...");

Configuration options
Configurationoptions contains a number of configuration options, some of which are commonly configured as follows:

Abortconnect: When True, a connection is not created when no server is available
Allowadmin: When True, you can use a number of commands that are considered dangerous
Channelprefix: Prefixes for all pub/sub channels
Connectretry: Number of retry connections
ConnectTimeout: Timeout period
Configchannel:broadcast channel name for communicating configuration changes
DefaultDatabase: Default 0 to-1
KeepAlive: Saves active connections for x seconds
Name:clientname
Password:password
Proxy: Agent such as Twemproxy
Resolvedns: Specifying DNS Resolution
Servicename:not currently implemented (intended for use with Sentinel)
Ssl={bool}: Using SLL encryption
Sslhost={string}: Forcing the server to use a specific SSL identity
Synctimeout={int}: Asynchronous Time-out
Tiebreaker={string}:key to selecting a server in an ambiguous master scenario
Version={string}: Redis version level (useful if the server does not do this available)
Writebuffer={int}: Size of output buffers

Each configuration item is separated by commas


Automatic and manual configuration
In most cases, Stackexchange.redis will automatically help us configure many options. such as server type, version, time-out, master-slave server, etc...
However, sometimes we need to exclude some commands from the server, in which case it is necessary to provide more information
configurationoptions config = new configurationoptions
{
Endpoints =
{
{"Redis0", 6379},
{"Redis1", 6380}
},
Commandmap = commandmap.create (New hashset<string>
{//EXCLUDE a few commands
"INFO", "CONFIG", "CLUSTER",
"PING", "ECHO", "CLIENT"
}, Available:false),
KeepAlive = 180,
Defaultversion = new Version (2, 8, 8),
Password = "Changeme"
};

You can also use the following string to set:

redis0:6379,redis1:6380,keepalive=180,version=2.8.8, $CLIENT =, $CLUSTER =, $CONFIG =, $ECHO =, $INFO =, $PING =

Rename command
You can disable or rename a command. This is done by Commandmap, as shown in the previous example, but with create (new hashset<string>) configured above, we use dictionary<string,string>. Set NULL on behalf of the command is disabled


var commands = new Dictionary<string,string> {
{"info", null},//disabled
{"Select", "Use"},//renamed to SQL equivalent for some reason
};
var options = new Configurationoptions {
// ...
Commandmap = commandmap.create (commands),
// ...
}

You can also use the following string to set:

$INFO =, $SELECT =use

Stackexchange.redis Use-Configuration (iv)

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.