import pickle


def pickle_to_bytes(redis_server, hkey, key):
    """Convert pickled matrix stored in entry under `key`
    in Redis hash under `hkey` to bytes. 

    Args:
        redis_server: Redis server containing hash under `hkey`.
        hkey (str): Key under which Redis hash is stored. 
        key (str): Key under which the pickled matrix is stored. 
    
    Returns:
        key_bytes: Matrix converted to bytes. 
    """
    key_pickled = redis_server.hget(hkey, key)
    key = pickle.loads(key_pickled)
    key_bytes = key.tobytes()
    return key_bytes