- Redis Basics
- Redis - Home
- Redis - Overview
- Redis - Environment
- Redis - Configuration
- Redis - Data types
- Redis Commands
- Redis - Commands
- Redis - Keys
- Redis - Strings
- Redis - Hashes
- Redis - Lists
- Redis - Sets
- Redis - Sorted Sets
- Redis - HyperLogLog
- Redis - Publish Subscribe
- Redis - Transactions
- Redis - Scripting
- Redis - Connections
- Redis - Server
- Redis Advanced
- Redis - Backup
- Redis - Security
- Redis - Benchmarks
- Redis - Client Connection
- Redis - Pipelining
- Redis - Partitioning
- Redis - Java
- Redis - Php
- Redis Useful Resources
- Redis - Quick Guide
- Redis - Useful Resources
- Redis - Discussion
Redis - Keys Renamenx Command
Redis RENAMENX command is used to change the name of a key, if the new key does not exist.
Return Value
Integer reply 1 or 0.
- 1, if key is renamed to new key.
- 0, if a new key already exists.
Syntax
Following is the basic syntax of Redis RENAMENX command.
redis 127.0.0.1:6379> RENAMENX OLD_KEY_NAME NEW_KEY_NAME
Example
First, create some keys in Redis and set some values in it.
redis 127.0.0.1:6379> SET tutorial1 redis OK redis 127.0.0.1:6379> SET tutorial2 mongodb OK
Now, rename the key ‘tutorial1’ to ‘new-tutorial’.
redis 127.0.0.1:6379> RENAMENX tutorial1 new-tutorial (integer) 1 redis 127.0.0.1:6379> RENAMENX tutorial2 new-tutorial (integer) 0
redis_keys.htm
Advertisements