Admin-Client Issue with updating user's realmRoles

Hello,
I’m writting a spring boot application using the admin-client api.
My scenario needs to update a user and assign that user to a realm role.
The code executes successfully, however the user roles are not updated in Admin console.
Please find my configurations and code snippet below:

realm: test-realm
server-url: http://localhost:8080
client-id: admin-cli
grant-type: password
name: admin
password: xxx
Keycloak keycloak=keycloakUtil.getKeycloakInstance();
        List<UserRepresentation> users=keycloak.realm(realm).users().searchByEmail(email,true);;
        UserRepresentation user=users.get(0);
        //update user roles
        List<String> roles=user.getRealmRoles();
        if(roles==null) {
            roles=List.of("publisher");
        }
        else{
            roles.add("publisher");
        }
        user.setRealmRoles(roles);
        keycloak.realm(realm).users().get(user.getId()).update(user);

If you are issuing a request from the Admin console, then you need to make sure to refresh the underlying data after the fact. This can be using typically via a “refresh” function for that view by incrementing the “key” value.

const refresh = () => setKey(key + 1);