diff --git a/MareSynchronosServer/MareSynchronosAuthService/Controllers/JwtController.cs b/MareSynchronosServer/MareSynchronosAuthService/Controllers/JwtController.cs index 11323db..0770d7d 100644 --- a/MareSynchronosServer/MareSynchronosAuthService/Controllers/JwtController.cs +++ b/MareSynchronosServer/MareSynchronosAuthService/Controllers/JwtController.cs @@ -16,6 +16,7 @@ using StackExchange.Redis.Extensions.Core.Abstractions; using System.IdentityModel.Tokens.Jwt; using System.Security.Claims; using System.Text; +using StackExchange.Redis; namespace MareSynchronosAuthService.Controllers; @@ -112,7 +113,7 @@ public class JwtController : Controller return Unauthorized("You are permanently banned."); } - var existingIdent = await _redis.GetAsync("UID:" + authResult.Uid); + var existingIdent = await _redis.GetAsync("UID:" + authResult.Uid, CommandFlags.PreferReplica); if (!string.IsNullOrEmpty(existingIdent)) return Unauthorized("Already logged in to this account. Reconnect in 60 seconds. If you keep seeing this issue, restart your game."); var token = CreateToken(new List() diff --git a/MareSynchronosServer/MareSynchronosAuthService/Services/AccountRegistrationService.cs b/MareSynchronosServer/MareSynchronosAuthService/Services/AccountRegistrationService.cs index 8eb811e..c15044c 100644 --- a/MareSynchronosServer/MareSynchronosAuthService/Services/AccountRegistrationService.cs +++ b/MareSynchronosServer/MareSynchronosAuthService/Services/AccountRegistrationService.cs @@ -46,7 +46,7 @@ public class AccountRegistrationService return reply; } - var registrationsByIp = await _redis.GetAsync("IPREG:" + ip).ConfigureAwait(false); + var registrationsByIp = await _redis.GetAsync("IPREG:" + ip, CommandFlags.PreferReplica).ConfigureAwait(false); if (registrationsByIp >= _configurationService.GetValueOrDefault(nameof(AuthServiceConfiguration.RegisterIpLimit), 3)) { reply.ErrorMessage = "Too many registrations from this IP. Please try again later."; diff --git a/MareSynchronosServer/MareSynchronosServer/Hubs/MareHub.Functions.cs b/MareSynchronosServer/MareSynchronosServer/Hubs/MareHub.Functions.cs index c1a7944..669a627 100644 --- a/MareSynchronosServer/MareSynchronosServer/Hubs/MareHub.Functions.cs +++ b/MareSynchronosServer/MareSynchronosServer/Hubs/MareHub.Functions.cs @@ -6,6 +6,7 @@ using MareSynchronos.API.Data; using MareSynchronos.API.Dto.Group; using MareSynchronosShared.Metrics; using Microsoft.AspNetCore.SignalR; +using StackExchange.Redis; namespace MareSynchronosServer.Hubs; @@ -118,14 +119,14 @@ public partial class MareHub private async Task> GetOnlineUsers(List uids) { - var result = await _redis.GetAllAsync(uids.Select(u => "UID:" + u).ToHashSet(StringComparer.Ordinal)).ConfigureAwait(false); + var result = await _redis.GetAllAsync(uids.Select(u => "UID:" + u).ToHashSet(StringComparer.Ordinal), CommandFlags.PreferReplica).ConfigureAwait(false); return uids.Where(u => result.TryGetValue("UID:" + u, out var ident) && !string.IsNullOrEmpty(ident)).ToDictionary(u => u, u => result["UID:" + u], StringComparer.Ordinal); } private async Task GetUserIdent(string uid) { if (string.IsNullOrEmpty(uid)) return string.Empty; - return await _redis.GetAsync("UID:" + uid).ConfigureAwait(false); + return await _redis.GetAsync("UID:" + uid, CommandFlags.PreferReplica).ConfigureAwait(false); } private async Task RemoveUserFromRedis() diff --git a/MareSynchronosServer/MareSynchronosServer/Hubs/MareHub.GposeLobby.cs b/MareSynchronosServer/MareSynchronosServer/Hubs/MareHub.GposeLobby.cs index b6f0f1a..5e0a53c 100644 --- a/MareSynchronosServer/MareSynchronosServer/Hubs/MareHub.GposeLobby.cs +++ b/MareSynchronosServer/MareSynchronosServer/Hubs/MareHub.GposeLobby.cs @@ -6,6 +6,7 @@ using MareSynchronosShared.Utils; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.SignalR; using Microsoft.EntityFrameworkCore; +using StackExchange.Redis; namespace MareSynchronosServer.Hubs; @@ -13,12 +14,12 @@ public partial class MareHub { private async Task GetUserGposeLobby() { - return await _redis.GetAsync(GposeLobbyUser).ConfigureAwait(false); + return await _redis.GetAsync(GposeLobbyUser, CommandFlags.PreferReplica).ConfigureAwait(false); } private async Task> GetUsersInLobby(string lobbyId, bool includeSelf = false) { - var users = await _redis.GetAsync>($"GposeLobby:{lobbyId}").ConfigureAwait(false); + var users = await _redis.GetAsync>($"GposeLobby:{lobbyId}", CommandFlags.PreferReplica).ConfigureAwait(false); return users?.Where(u => includeSelf || !string.Equals(u, UserUID, StringComparison.Ordinal)).ToList() ?? []; } @@ -68,7 +69,7 @@ public partial class MareHub while (string.IsNullOrEmpty(lobbyId)) { lobbyId = StringUtils.GenerateRandomString(30, "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"); - var result = await _redis.GetAsync>($"GposeLobby:{lobbyId}").ConfigureAwait(false); + var result = await _redis.GetAsync>($"GposeLobby:{lobbyId}", CommandFlags.PreferReplica).ConfigureAwait(false); if (result != null) lobbyId = string.Empty; } diff --git a/MareSynchronosServer/MareSynchronosServer/Services/GPoseLobbyDistributionService.cs b/MareSynchronosServer/MareSynchronosServer/Services/GPoseLobbyDistributionService.cs index 249407d..14725be 100644 --- a/MareSynchronosServer/MareSynchronosServer/Services/GPoseLobbyDistributionService.cs +++ b/MareSynchronosServer/MareSynchronosServer/Services/GPoseLobbyDistributionService.cs @@ -3,6 +3,7 @@ using MareSynchronos.API.SignalR; using MareSynchronosServer.Hubs; using Microsoft.AspNetCore.SignalR; using StackExchange.Redis.Extensions.Core.Abstractions; +using StackExchange.Redis; namespace MareSynchronosServer.Services; @@ -153,7 +154,7 @@ public sealed class GPoseLobbyDistributionService : IHostedService, IDisposable if (!lobbyId.Value.Values.Any()) continue; - var gposeLobbyUsers = await _redisDb.GetAsync>($"GposeLobby:{lobbyId.Key}").ConfigureAwait(false); + var gposeLobbyUsers = await _redisDb.GetAsync>($"GposeLobby:{lobbyId.Key}", CommandFlags.PreferReplica).ConfigureAwait(false); if (gposeLobbyUsers == null) continue; @@ -200,7 +201,7 @@ public sealed class GPoseLobbyDistributionService : IHostedService, IDisposable if (!lobbyId.Value.Values.Any()) continue; - var gposeLobbyUsers = await _redisDb.GetAsync>($"GposeLobby:{lobbyId.Key}").ConfigureAwait(false); + var gposeLobbyUsers = await _redisDb.GetAsync>($"GposeLobby:{lobbyId.Key}", CommandFlags.PreferReplica).ConfigureAwait(false); if (gposeLobbyUsers == null) continue; diff --git a/MareSynchronosServer/MareSynchronosServices/Discord/MareModule.cs b/MareSynchronosServer/MareSynchronosServices/Discord/MareModule.cs index 21392f7..62b34c6 100644 --- a/MareSynchronosServer/MareSynchronosServices/Discord/MareModule.cs +++ b/MareSynchronosServer/MareSynchronosServices/Discord/MareModule.cs @@ -646,7 +646,7 @@ public class MareModule : InteractionModuleBase var auth = await db.Auth.Include(u => u.PrimaryUser).SingleOrDefaultAsync(u => u.UserUID == dbUser.UID).ConfigureAwait(false); var groups = await db.Groups.Where(g => g.OwnerUID == dbUser.UID).ToListAsync().ConfigureAwait(false); var groupsJoined = await db.GroupPairs.Where(g => g.GroupUserUID == dbUser.UID).ToListAsync().ConfigureAwait(false); - var identity = await _connectionMultiplexer.GetDatabase().StringGetAsync("UID:" + dbUser.UID).ConfigureAwait(false); + var identity = await _connectionMultiplexer.GetDatabase().StringGetAsync("UID:" + dbUser.UID, CommandFlags.PreferReplica).ConfigureAwait(false); eb.WithTitle("User Information"); eb.WithDescription("This is the user information for Discord User <@" + userToCheckForDiscordId + ">" + Environment.NewLine + Environment.NewLine diff --git a/MareSynchronosServer/MareSynchronosShared/RequirementHandlers/UserRequirementHandler.cs b/MareSynchronosServer/MareSynchronosShared/RequirementHandlers/UserRequirementHandler.cs index 5cc38e5..e82907a 100644 --- a/MareSynchronosServer/MareSynchronosShared/RequirementHandlers/UserRequirementHandler.cs +++ b/MareSynchronosServer/MareSynchronosShared/RequirementHandlers/UserRequirementHandler.cs @@ -30,7 +30,7 @@ public class UserRequirementHandler : AuthorizationHandler("UID:" + uid).ConfigureAwait(false); + var ident = await _redis.GetAsync("UID:" + uid, CommandFlags.PreferReplica).ConfigureAwait(false); if (ident == RedisValue.EmptyString) context.Fail(); }