private static async ValueTask <RedisResult> JoinedParticipantsRepository_RemoveParticipantSafe( IKeyValueDatabaseActions actions, string participantId, string participantKey, string conferenceKeyTemplate, string connectionId) { var conferenceId = await actions.GetAsync(participantKey); if (conferenceId == null) { return(RedisResult.Create(RedisValue.Null)); } var conferenceKey = conferenceKeyTemplate.Replace("*", conferenceId); var actualConnectionId = await actions.HashGetAsync(conferenceKey, participantId); if (actualConnectionId == connectionId) { await actions.KeyDeleteAsync(participantKey); await actions.HashDeleteAsync(conferenceKey, participantId); return(RedisResult.Create(true)); } return(RedisResult.Create(false)); }
private void RemoveChannel(IKeyValueDatabaseActions actions, string conferenceId, string channel) { var messagesKey = GetKey(conferenceId, channel); var typingKey = GetKey(conferenceId, channel); _ = actions.KeyDeleteAsync(messagesKey); _ = actions.KeyDeleteAsync(typingKey); }
public static async ValueTask <T?> HashGetAsync <T>(this IKeyValueDatabaseActions database, string hashKey, string key) { var result = await database.HashGetAsync(hashKey, key); if (result == null) { return(default);
private static async ValueTask <bool?> RemoveParticipantSafe(IKeyValueDatabaseActions database, string participantId, string connectionId) { var participantToConferenceKey = GetParticipantToConferenceKey(participantId); var conferenceToParticipantsKey = GetConferenceToParticipantsKey("*"); var result = await database.ExecuteScriptAsync( RedisScript.JoinedParticipantsRepository_RemoveParticipantSafe, participantId, participantToConferenceKey, conferenceToParticipantsKey, connectionId); if (result.IsNull) { return(null); } return((bool)result); }
private static async ValueTask <PreviousParticipantState?> RemoveParticipant(IKeyValueDatabaseActions database, string participantId) { var participantToConferenceKey = GetParticipantToConferenceKey(participantId); var conferenceToParticipantsKey = GetConferenceToParticipantsKey("*"); var result = await database.ExecuteScriptAsync(RedisScript.JoinedParticipantsRepository_RemoveParticipant, participantId, participantToConferenceKey, conferenceToParticipantsKey); if (result.IsNull) { return(null); } var arr = (string[])result; return(new PreviousParticipantState(arr[0], arr[1])); }
private static async ValueTask <RedisResult> JoinedParticipantsRepository_RemoveParticipant( IKeyValueDatabaseActions actions, string participantId, string participantKey, string conferenceKeyTemplate) { var conferenceId = await actions.GetAsync(participantKey); if (conferenceId == null) { return(RedisResult.Create(RedisValue.Null)); } await actions.KeyDeleteAsync(participantKey); var conferenceKey = conferenceKeyTemplate.Replace("*", conferenceId); var previousConnectionId = await actions.HashGetAsync(conferenceKey, participantId); await actions.HashDeleteAsync(conferenceKey, participantId); return(RedisResult.Create(new RedisValue[] { conferenceId, previousConnectionId })); }
private static async ValueTask <RedisResult> RoomRepository_SetParticipantRoom(IKeyValueDatabaseActions actions, string roomMappingKey, string roomListKey, string participantId, string newRoomId) { var roomExists = await actions.HashExistsAsync(roomListKey, newRoomId); if (!roomExists) { return(RedisResult.Create(false)); } await actions.HashSetAsync(roomMappingKey, participantId, newRoomId); return(RedisResult.Create(true)); }