Renames key to newkey. It returns an error when the source and destination names are the same, or when key does not exist.

So first should know wherther the key exist.