![]() Var database = _conn.GetDatabase (DbNum) Var prefixKey = CustomKey ? RedisConnectionHelp.SysCustomKey Private string AddSysCustomKey (string oldKey) RedisConnectionHelp.GetConnectionMultiplexer (readWriteHosts) String.IsNullOrWhiteSpace (readWriteHosts)? Public RedisHelper (int dbNum, string readWriteHosts) Private readonly ConnectionMultiplexer _conn Private static void MuxerInternalError (object sender, InternalErrorEventArgs e)Ĭonsole.WriteLine ("InternalError: Message" + e.Exception.Message) Private static void MuxerHashSlotMoved (object sender, HashSlotMovedEventArgs e)Ĭonsole.WriteLine ("HashSlotMoved: NewEndPoint" + e.NewEndPoint + ", OldEndPoint" + e.OldEndPoint) Private static void MuxerConnectionFailed (object sender, ConnectionFailedEventArgs e)Ĭonsole.WriteLine ("Reconnect: Endpoint failed:" + e.EndPoint + "," + e.FailureType + (e.Exception = null? "": ("," + E.Exception.Message))) / connection failed, you will not receive this notification if the reconnection is successful Private static void MuxerConnectionRestored (object sender, ConnectionFailedEventArgs e)Ĭonsole.WriteLine ("ConnectionRestored:" + e.EndPoint) / error before re-establishing the connection Private static void MuxerErrorMessage (object sender, RedisErrorEventArgs e)Ĭonsole.WriteLine ("ErrorMessage:" + e.Message) Private static void MuxerConfigurationChanged (object sender, EndPointEventArgs e)Ĭonsole.WriteLine ("Configuration changed:" + e.EndPoint) Var connect = ConnectionMultiplexer.Connect (connectionString) Ĭonnect.ConnectionFailed + = MuxerConnectionFailed Ĭonnect.ConnectionRestored + = MuxerConnectionRestored Ĭonnect.ErrorMessage + = MuxerErrorMessage Ĭonnect.ConfigurationChanged + = MuxerConfigurationChanged Ĭonnect.HashSlotMoved + = MuxerHashSlotMoved Ĭonnect.InternalError + = MuxerInternalError Private static ConnectionMultiplexer GetManager (string connectionString = null)ĬonnectionString = connectionString ? RedisConnectionString If (! ConnectionCache.ContainsKey (connectionString))ĬonnectionCache = GetManager (connectionString) Public static ConnectionMultiplexer GetConnectionMultiplexer (string connectionString) ![]() If (_instance = null ||! _instance.IsConnected) Public static ConnectionMultiplexer Instance Private static readonly ConcurrentDictionary ConnectionCache = new ConcurrentDictionary () Private static ConnectionMultiplexer _instance Private static readonly object Locker = new object () Private static readonly string RedisConnectionString = ConfigurationManager.ConnectionStrings. Public static readonly string SysCustomKey = ConfigurationManager.AppSettings ? "" / ConnectionMultiplexer object management helper class ![]() Instances of this class need to be shared and reused by the entire application domain, so there is no need to create an instance of the object in every operation, typically by using a single example to create and store the object, as explained on the official web site. The first is the encapsulation of the Connectionmultiplexer, the Connectionmultiplexer object is the Stackexchange.redis most central object. After reference to some articles and source code, here to provide a class of their own encapsulation, the basic provision for various types of use of encapsulation, provided to everyone to learn to use, if there is no bad, we can communicate with each other. The use of Stackexchange.redis on the internet is much less than Servicestack.redis, not to say that no one to use, but I checked, most of them are based on string type of data used in the encapsulation class, for the List,sortedset,hash encapsulation operations are very Less, the basic is to write a little, the West write a little, it is difficult to find complete. Stackexchange.redis documents, not to mention the domestic documents, even github the corresponding introductory documents are very one-sided, I really think that Stackexchange.redis the author at least to improve the following documents, many are to see the source code examples. However, Servicestack.redis compared with Stackexchange.redis, aside from the charges, confirm more advantages than Stackexchange.redis. In fact, personally feel that two drivers are good, just because Servicestack.redis charges lead to many companies are based on the V3 version of the use, others said V3 version has a lot of bugs, no maintenance and upgrades, but at least for now I do not find bugs. ![]() Two days ago, my friend asked me if I have used Stackexchange.redis, asked me to have a package class, because before the use of Servicestack.redis, due to the Servicestack.redis V4 version is the charge version, So now there are companies that are using Stackexchange.redis to abandon Servicestack.redis.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |