From c57a377d7a73de0693deae732f8e5d4d740bfada Mon Sep 17 00:00:00 2001 From: zpc Date: Wed, 13 Nov 2024 22:36:33 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../CloudGaming.Code/Account/AccountBLL.cs | 11 +++--- .../Db_Phone/CloudGamingPhoneContext.cs | 6 ++-- .../Redis/RedisConnection.cs | 34 ++++++++++++++++++- 3 files changed, 42 insertions(+), 9 deletions(-) diff --git a/src/CloudGaming/Code/CloudGaming.Code/Account/AccountBLL.cs b/src/CloudGaming/Code/CloudGaming.Code/Account/AccountBLL.cs index 0b46f8c..8344312 100644 --- a/src/CloudGaming/Code/CloudGaming.Code/Account/AccountBLL.cs +++ b/src/CloudGaming/Code/CloudGaming.Code/Account/AccountBLL.cs @@ -129,10 +129,9 @@ namespace CloudGaming.Code.Account //创建设备号 var dev = await ManageUserDevicesAsync(user, account, jwt.AccessToken); var key = $"user:login:{user.Id}"; - var accountUserLoginInfos = await RedisCache.StringGetAsync>(key); - accountUserLoginInfos ??= new List(); + //创建redis缓存 - await RedisCache.StringSetAsync(key, $"{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")}", TimeSpan.FromHours(1)); + await RedisCache.StringSetAsync(key, $"1", TimeSpan.FromHours(1)); //accountUserLoginInfos.Add(new AccountUserLoginInfo()); T_User_Login_Log login_Log = new T_User_Login_Log() { @@ -221,7 +220,7 @@ namespace CloudGaming.Code.Account } // 管理用户设备 - private async Task ManageUserDevicesAsync(T_User user, IUserAccount account, string accessToken) + private async Task> ManageUserDevicesAsync(T_User user, IUserAccount account, string accessToken) { var currentTime = DateTime.Now; var dev = string.IsNullOrEmpty(account.DeviceNumber) @@ -265,7 +264,7 @@ namespace CloudGaming.Code.Account TokenMd5 = MD5Encryption.ComputeMD5Hash(accessToken) }; await Dao.DaoUser.Context.T_User_Token.AddAsync(existingDevice); - + userLoginList.Add(existingDevice); } } else @@ -275,7 +274,7 @@ namespace CloudGaming.Code.Account } await Dao.DaoUser.Context.SaveChangesAsync(); - return existingDevice; + return userLoginList; } // 更新设备令牌信息 diff --git a/src/CloudGaming/Model/CloudGaming.Model/DbSqlServer/Db_Phone/CloudGamingPhoneContext.cs b/src/CloudGaming/Model/CloudGaming.Model/DbSqlServer/Db_Phone/CloudGamingPhoneContext.cs index 59a0462..2b0ded4 100644 --- a/src/CloudGaming/Model/CloudGaming.Model/DbSqlServer/Db_Phone/CloudGamingPhoneContext.cs +++ b/src/CloudGaming/Model/CloudGaming.Model/DbSqlServer/Db_Phone/CloudGamingPhoneContext.cs @@ -1,5 +1,6 @@ -using System; +using System; using System.Collections.Generic; + using Microsoft.EntityFrameworkCore; namespace CloudGaming.Model.DbSqlServer.Db_Phone; @@ -144,7 +145,8 @@ public partial class CloudGamingPhoneContext : MultiTenantDbContext//DbContext public virtual DbSet T_Videos { get; set; } protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) - => optionsBuilder.UseSqlServer("Server=192.168.1.17;Database=CloudGamingPhone;User Id=sa;Password=Dbt@com@123;TrustServerCertificate=true;"); + { } + //=> optionsBuilder.UseSqlServer("Server=192.168.1.17;Database=CloudGamingPhone;User Id=sa;Password=Dbt@com@123;TrustServerCertificate=true;"); protected override void OnModelCreating(ModelBuilder modelBuilder) { diff --git a/src/CloudGaming/Utile/HuanMeng.DotNetCore/Redis/RedisConnection.cs b/src/CloudGaming/Utile/HuanMeng.DotNetCore/Redis/RedisConnection.cs index ca72093..cee90e6 100644 --- a/src/CloudGaming/Utile/HuanMeng.DotNetCore/Redis/RedisConnection.cs +++ b/src/CloudGaming/Utile/HuanMeng.DotNetCore/Redis/RedisConnection.cs @@ -25,6 +25,8 @@ namespace HuanMeng.DotNetCore.Redis /// public static ConcurrentDictionary Redis { get; set; } = new ConcurrentDictionary(); + public static ConcurrentDictionary RedisServer { get; set; } = new ConcurrentDictionary(); + /// /// @@ -37,11 +39,29 @@ namespace HuanMeng.DotNetCore.Redis { var redis = ConnectionMultiplexer.Connect(redisConnection); database = redis.GetDatabase(); + //server.key + //redis.GetServer() Redis.TryAdd(redisConnection, database); } return database; } - + /// + /// + /// + /// + /// + public static IServer GetServer(string redisConnection) + { + if (!RedisServer.TryGetValue(redisConnection, out var server)) + { + var redis = ConnectionMultiplexer.Connect(redisConnection); + server = redis.GetServer("", ""); + //server.key + //redis.GetServer() + RedisServer.TryAdd(redisConnection, server); + } + return server; + } /// /// @@ -112,5 +132,17 @@ namespace HuanMeng.DotNetCore.Redis // 将 RedisValue 转换为 T 类型 return JsonConvert.DeserializeObject(value); } + /// + /// 模糊查询key + /// + /// + /// + /// + /// + public static List ScanKeys(this IServer server, string pattern, int pageSize = 100) + { + var matchingKeys = server.Keys(pattern: pattern).Select(it => it.ToString()).ToList(); + return matchingKeys; + } } }