using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace GpsCardGatewayPosition.Model.Config { /// /// Redis配置模板类 /// public class RedisConfig { public string Server { get; set; } /// /// Redis server password /// public string Password { get; set; } /// /// Redis server database, default 0 /// public int? DefaultDatabase { get; set; } /// /// The asynchronous method automatically uses pipeline, and the 10W concurrent time is 450ms(welcome to feedback) /// public bool? AsyncPipeline { get; set; } /// /// Connection pool size, default 50 /// public int? Poolsize { get; set; } /// /// Idle time of elements in the connection pool(MS), suitable for connecting to remote redis server, default 20000 /// public int? IdleTimeout { get; set; } /// /// Connection timeout(MS), default 5000 /// public int? ConnectTimeout { get; set; } /// /// Send / receive timeout(MS), default 10000 /// public int? SyncTimeout { get; set; } /// /// Preheat connections, receive values such as preheat = 5 preheat 5 connections, default 5 /// public int? Preheat { get; set; } /// /// Follow system exit event to release automatically, default true /// public bool? AutoDispose { get; set; } /// /// Enable encrypted transmission, default false /// public bool? Ssl { get; set; } /// /// 是否尝试集群模式,阿里云、腾讯云集群需要设置此选项为 false, default true /// public bool? Testcluster { get; set; } /// /// Execution error, retry attempts, default 0 /// public int? Tryit { get; set; } /// /// Connection name, use client list command to view /// public string Name { get; set; } /// /// key前辍,所有方法都会附带此前辍,csredis.Set(prefix + "key", 111) /// public string Prefix { get; set; } public override string ToString() { if (string.IsNullOrWhiteSpace(Server)) throw new ArgumentNullException(nameof(Server)); var sb = new StringBuilder(Server); if (!string.IsNullOrWhiteSpace(Password)) sb.Append($",password={Password}"); if (DefaultDatabase.HasValue) sb.Append($",defaultDatabase={DefaultDatabase}"); if (AsyncPipeline.HasValue) sb.Append($",asyncPipeline={AsyncPipeline}"); if (Poolsize.HasValue) sb.Append($",poolsize={Poolsize}"); if (IdleTimeout.HasValue) sb.Append($",idleTimeout={IdleTimeout}"); if (ConnectTimeout.HasValue) sb.Append($",connectTimeout={ConnectTimeout}"); if (SyncTimeout.HasValue) sb.Append($",syncTimeout={0}"); if (Preheat.HasValue) sb.Append($",preheat={Preheat}"); if (AutoDispose.HasValue) sb.Append($",autoDispose={AutoDispose}"); if (Ssl.HasValue) sb.Append($",ssl={Ssl}"); if (Testcluster.HasValue) sb.Append($",testcluster={Testcluster}"); if (Tryit.HasValue) sb.Append($",tryit={Tryit}"); if (!string.IsNullOrWhiteSpace(Name)) sb.Append($",name={Name}"); if (!string.IsNullOrWhiteSpace(Prefix)) sb.Append($",prefix={Prefix}"); return sb.ToString(); } } }