This chapter mainly writes about the Stackexchange.redis configuration and the less frequently used functions
Database connection
Here is my connection string, which specifies the address, password, and default database
Redis startup is divided into 0-15 databases by default, keys can be duplicated between different databases, Stackexchange.redis's Getdatabase function provides an optional DB parameter
The default-1 is actually 0, and you can specify which database to connect by setting the DefaultDatabase in the connection string.
The operation of the specified database is more appropriate to be divided by business
Execute
Redis commands can be executed directly in Stackexchange.redis through the execute function, but for most command stackexchange.redis the Database will provide a way to encapsulate , so theoretically it is not necessary to call the Execute function
The following code is equivalent to calling the stringset and stringget functions of idatabase
Getserver
However, there are some more common functions that cannot be performed by the functions provided in idababase, such as Keys,flushdb,scan. What is this for?
The reason for this is that Stackexchange.redis provides functions such as stringset,setadd for a db cluster , so actually adding a key is not necessarily added to a single server.
Operations such as FLUSHDB are operations on a single database on a specific server (server) . Imagine if you provide a FLUSHDB operation for the entire cluster, in case of accidental deletion, the consequences are unthinkable ...
Of course Stackexchange.redis also provides relevant functions for the server. You can specify the specific server through the getserver of the connectionmultiplexer instance, where you need to set up the specific servers address and port number.
You can then call the related function that it provides.
About server address parameters We do not need handwriting, connection has provided a getendpoints function that can be called directly
Stackexchange.redis Study Notes (iii) database and password configuration getserver function