<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def store_groups_in_session(sender, user, request, **kwargs):
 """ When a user logs in, fetch its groups and store them in the users session. This is required by ws4redis, since fetching groups accesses the database, which is a blocking operation and thus not allowed from within the websocket loop. """

    if hasattr(user, 'groups'):
        request.session['ws4redis:memberof'] = [g.name for g in user.groups.all()]