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
- Weekly Trends
- Python Interview Questions and Answers: Comprehensive Guide
- Scala Exercises, Practice, Solution
- Kotlin Exercises practice with solution
- MongoDB Exercises, Practice, Solution
- SQL Exercises, Practice, Solution - JOINS
- Java Basic Programming Exercises
- SQL Subqueries
- Adventureworks Database Exercises
- C# Sharp Basic Exercises
- SQL COUNT() with distinct
- JavaScript String Exercises
- JavaScript HTML Form Validation
- Java Collection Exercises
- SQL COUNT() function
- SQL Inner Join
We are closing our Disqus commenting system for some maintenanace issues. You may write to us at reach[at]yahoo[dot]com or visit us at Facebook