|
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
-
- namespace TelpoPush.WanJiaAn.Worker.Models.Config
- {
- /// <summary>
- /// Redis配置模板类
- /// </summary>
- public class RedisConfig
- {
- public string Server { get; set; }
- /// <summary>
- /// Redis server password
- /// </summary>
- public string Password { get; set; }
- /// <summary>
- /// Redis server database, default 0
- /// </summary>
- public int? DefaultDatabase { get; set; }
- /// <summary>
- /// The asynchronous method automatically uses pipeline, and the 10W concurrent time is 450ms(welcome to feedback)
- /// </summary>
- public bool? AsyncPipeline { get; set; }
- /// <summary>
- /// Connection pool size, default 50
- /// </summary>
- public int? Poolsize { get; set; }
- /// <summary>
- /// Idle time of elements in the connection pool(MS), suitable for connecting to remote redis server, default 20000
- /// </summary>
- public int? IdleTimeout { get; set; }
- /// <summary>
- /// Connection timeout(MS), default 5000
- /// </summary>
- public int? ConnectTimeout { get; set; }
- /// <summary>
- /// Send / receive timeout(MS), default 10000
- /// </summary>
- public int? SyncTimeout { get; set; }
- /// <summary>
- /// Preheat connections, receive values such as preheat = 5 preheat 5 connections, default 5
- /// </summary>
- public int? Preheat { get; set; }
- /// <summary>
- /// Follow system exit event to release automatically, default true
- /// </summary>
- public bool? AutoDispose { get; set; }
- /// <summary>
- /// Enable encrypted transmission, default false
- /// </summary>
- public bool? Ssl { get; set; }
- /// <summary>
- /// 是否尝试集群模式,阿里云、腾讯云集群需要设置此选项为 false, default true
- /// </summary>
- public bool? Testcluster { get; set; }
- /// <summary>
- /// Execution error, retry attempts, default 0
- /// </summary>
- public int? Tryit { get; set; }
- /// <summary>
- /// Connection name, use client list command to view
- /// </summary>
- public string Name { get; set; }
- /// <summary>
- /// key前辍,所有方法都会附带此前辍,csredis.Set(prefix + "key", 111)
- /// </summary>
- 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();
- }
- }
- }
|