def set_cache_token(self, token_data):
        """ Set Token with data in Redis """

        if self.conn is None:
            raise CacheException('Redis is not connected')

        token = token_data['auth_token']
        token_expires = token_data['expires_at']
        roles = token_data['roles']

        try:
            datetime_object = datetime.strptime(
                token_expires, '%Y-%m-%dT%H:%M:%S.%fZ')
        except ValueError:
            datetime_object = datetime.strptime(
                token_expires, '%Y-%m-%dT%H:%M:%SZ')

        ttl = (datetime.utcnow().now() - datetime_object)
        token_data = json.dumps({
            'expires_at': token_expires,
            'roles': roles,
            'user': token_data['user']
        })

        self.conn.set(token, token_data, ex=ttl.seconds)
Set Token with data in Redis