/// <summary> /// 根据用户名获取用户ID /// </summary> /// <param name="siteId"></param> /// <param name="userName"></param> /// <returns></returns> public int GetUserID(int siteId, string userName) { string key = $"{USERID}{siteId}:{ userName.GetHash() }"; RedisValue value = this.NewExecutor().HashGet(key, userName); return(value.IsNull ? 0 : value.GetRedisValue <int>()); }
/// <summary> /// 把Redis转成系统值 /// 如果redisValue为null则返回默认值 /// </summary> /// <typeparam name="T"></typeparam> /// <param name="value"></param> /// <returns></returns> public static T GetRedisValue <T>(this RedisValue value) { if (value.IsNull) { return(default(T)); } return((T)value.GetRedisValue(typeof(T))); }
/// <summary> /// 根据token得到ID /// </summary> /// <param name="KEY">前缀KEY</param> /// <param name="token">Token内容</param> /// <returns></returns> protected virtual int GetTokenID(string KEY, Guid token) { string tokenKey = this.GetTokenKey(KEY, token); RedisValue value = this.NewExecutor().HashGet(tokenKey, token.GetRedisValue()); if (value.IsNull) { return(0); } return(value.GetRedisValue <int>()); }
/// <summary> /// 获取商户模板所属的平台类型 /// </summary> /// <param name="templateId"></param> /// <returns></returns> public PlatformSource?GetSiteTemplatePlatform(int templateId) { string key = $"{TEMPLATEINFO}{templateId}"; RedisValue value = this.NewExecutor().HashGet(key, "Platform"); if (value.IsNull) { return(null); } return(value.GetRedisValue <PlatformSource>()); }
/// <summary> /// 取出任务,并且更新进度 /// </summary> /// <typeparam name="T"></typeparam> /// <param name="jobName"></param> /// <returns></returns> protected virtual IEnumerable <T> ExecuteJob <T>(string jobName) { string key = $"{JOB}{jobName}"; string progress = $"{JOB_PROGRESS}{jobName}"; while (true) { RedisValue value = this.NewExecutor().ListLeftPop(key); if (value.IsNull) { this.NewExecutor().KeyDelete(progress); break; } this.NewExecutor().HashIncrement(progress, JOB_COUNT); yield return(value.GetRedisValue <T>()); } }