I use Redis
as a backplane, but I'm also using SQL to map users to connections. This is taking a toll on my I/O - every time I send a message through my hub, I do this:
private readonly ConnectionService _connectionService;
public AppHub() {
_connectionService = new ConnectionService();
}
public void SendClientNotification(string notification, string key) {
List<string> navbarClients = _connectionService.GetConnections(key); // yuck
foreach (string connectionId in navbarClients) {
Clients.Client(connectionId).clientNotification(notification);
}
}
Where GetConnections
is this:
public List<string> GetConnections(string key) {
using (DbContext db = new DbContext()) {
return db.SignalConnections
.Where(s => s.Key == key)
.Select(s => s.ConnectionGuid)
.ToList();
}
}
I also do a whole bunch of I/O to periodically delete inactive connections.
Can SignalR somehow infer the username (say from User.Identity.Name
) and automatically handle the mapping and connection expiration so I can just wipe out this SQL dependency from my SignalR implementation?