Redis Keys: RENAME
RENAME key newkey
The Redis RENAME command is used to change the name of a key to newkey.
- It returns an error when the source and destination names are the same, or when a key does not exist.
- If newkey already exists it is overwritten, when this happens RENAME executes an implicit DEL operation, so if the deleted key contains a very big value
Syntax:
RENAME OLD_KEY_NAME NEW_KEY_NAME
Available since
1.0.0.
Return Value
String reply OK or error.
Return Value Type
String
Example - 1: Redis RENAME
First, create some keys in redis and set some values in it.
127.0.0.1:6379> SET key "PHP" OK 127.0.0.1:6379> RENAME key JavaScript OK 127.0.0.1:6379> GET JavaScript "PHP"
Example - 2: Redis RENAME
127.0.0.1:6379> MSET key "PHP" key1 "JavaScript" key2 "Redis" OK 127.0.0.1:6379> RENAME key key1 OK 127.0.0.1:6379> GET key1 "PHP"
Previous:
RANDOMKEY
Next:
RENAMENX
- New Content published on w3resource:
- HTML-CSS Practical: Exercises, Practice, Solution
- Java Regular Expression: Exercises, Practice, Solution
- Scala Programming Exercises, Practice, Solution
- Python Itertools exercises
- Python Numpy exercises
- Python GeoPy Package exercises
- Python Pandas exercises
- Python nltk exercises
- Python BeautifulSoup exercises
- Form Template
- Composer - PHP Package Manager
- PHPUnit - PHP Testing
- Laravel - PHP Framework
- Angular - JavaScript Framework
- Vue - JavaScript Framework
- Jest - JavaScript Testing Framework