Redis Keys: RENAMENX
RENAMENX key newkey
Redis RENAMENX command is used to change the name of a key to newkey if the new key does not exist. It returns an error under the same conditions as RENAME.
Syntax:
RENAMENX OLD_KEY_NAME NEW_KEY_NAME
Available since
1.0.0.
Return Value
Integer reply, specifically :
- 1, if the key is renamed to the new key.
- 0, if a new key already exists.
Return Value Type
Integer
Example - 1: Redis RENAMENX
First, create some keys in redis and set some values in it.
127.0.0.1:6379> SET key "Apple" OK 127.0.0.1:6379> SET key1 "Banana" OK 127.0.0.1:6379> RENAMENX key key1 (integer) 0 127.0.0.1:6379> GET key1 "Banana"
Example - 2: Redis RENAMENX
Now rename the key key1 to Python.
127.0.0.1:6379> MSET key "PHP" key1 "JavaScript" OK 127.0.0.1:6379> RENAMENX key key1 (integer) 0 127.0.0.1:6379> RENAMENX key Python (integer) 1
Previous:
RENAME
Next:
RESTORE
- 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