public async ValueTask DeletePollAndState(string conferenceId, string pollId) { var pollsKey = GetPollsKey(conferenceId); var stateKey = GetPollStateKey(conferenceId); using var transaction = _database.CreateTransaction(); _ = transaction.HashDeleteAsync(pollsKey, pollId); _ = transaction.HashDeleteAsync(stateKey, pollId); await transaction.ExecuteAsync(); }
public async ValueTask RemoveFromQueue(IEnumerable <Participant> participants, string roomId) { using var transaction = _database.CreateTransaction(); foreach (var participant in participants) { var queueKey = GetQueueKey(participant.ConferenceId, roomId); _ = transaction.ListRemoveAsync(queueKey, participant.Id); } await transaction.ExecuteAsync(); }
public async ValueTask <IReadOnlyList <string>?> GetSet(Participant participant, IReadOnlyList <string> subscriptions) { var key = GetKey(participant.ConferenceId); using (var transaction = _database.CreateTransaction()) { var previousSubs = transaction.HashGetAsync <List <string> >(key, participant.Id); _ = transaction.HashSetAsync(key, participant.Id, subscriptions); await transaction.ExecuteAsync(); return(await previousSubs); } }
public async ValueTask <int> AddChatMessageAndGetMessageCount(string conferenceId, string channel, ChatMessage message) { var chatKey = GetKey(conferenceId, channel); var channelsKey = GetChannelSetKey(conferenceId); using (var transaction = _database.CreateTransaction()) { _ = transaction.ListRightPushAsync(chatKey, message); _ = transaction.SetAddAsync(channelsKey, channel); var messagesCountTask = transaction.ListLenAsync(chatKey); await transaction.ExecuteAsync(); return(await messagesCountTask); } }
public async ValueTask <DeleteAllResult> DeleteAllRoomsAndMappingsOfConference(string conferenceId) { var mappingKey = GetRoomMappingKey(conferenceId); var roomListKey = GetRoomListKey(conferenceId); using (var trans = _database.CreateTransaction()) { var mappingTask = trans.HashGetAllAsync(mappingKey); var allRoomsTask = trans.HashGetAllAsync(roomListKey); _ = trans.KeyDeleteAsync(mappingKey); _ = trans.KeyDeleteAsync(roomListKey); await trans.ExecuteAsync(); var mapping = await mappingTask; var allRooms = await allRoomsTask; return(new DeleteAllResult(mapping, allRooms.Select(x => x.Key).ToList())); } }
private async Task ReplaceHashSet(string key, IEnumerable <KeyValuePair <string, string> > entries) { using (var trans = _database.CreateTransaction()) { var deleteTask = trans.KeyDeleteAsync(key); var _ = trans.HashSetAsync(key, entries); await trans.ExecuteAsync(); await deleteTask; // if the operation failed, this will throw an exception } }
public async ValueTask <PreviousParticipantState?> AddParticipant(Participant participant, string connectionId) { var participantToConferenceKey = GetParticipantToConferenceKey(participant.Id); var conferenceToParticipantsKey = GetConferenceToParticipantsKey(participant.ConferenceId); using (var trans = _database.CreateTransaction()) { var previousConferenceIdTask = RemoveParticipant(trans, participant.Id); _ = trans.SetAsync(participantToConferenceKey, participant.ConferenceId); _ = trans.HashSetAsync(conferenceToParticipantsKey, participant.Id, connectionId); await trans.ExecuteAsync(); var previousConferenceId = await previousConferenceIdTask; return(previousConferenceId); } }