Redis Getset Command
--
- Home
- HTML
- JavaScript
- CSS
- Vue
- React
- Python3
- Java
- C
- C++
- C#
- AI
- Go
- SQL
- Linux
- VS Code
- Bootstrap
- Git
- Local Bookmarks
Redis Tutorial
Redis Tutorial
Redis Introduction
Redis Installation
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 Pub/Sub
Redis Transactions
Redis Scripting
Redis Connection
Redis Server
Redis GEO
Redis Stream
Redis Advanced Tutorial
Redis Backup and Recovery
Redis Security
Redis Performance Testing
Redis Client Connection
Redis Pipelining
Redis Partitioning
Java Using Redis
PHP Using Redis
Redis Getset Command
Redis Strings
Redis Getset command is used to set the value of a specified key and return the old value of the key.
Syntax
The basic syntax of redis Getset command is as follows:
redis 127.0.0.1:6379> GETSET KEY_NAME VALUE
Available Versions
>= 1.0.0
Return Value
Returns the old value of the given key. When the key has no old value, i.e., the key does not exist, it returns nil.
When the key exists but is not of string type, it returns an error.
Example
First, set the value of mykey and truncate the string.
redis> GETSET db mongodb # No old value, returns nil(nil)
redis> GET db "mongodb"
redis> GETSET db redis # Returns old value mongodb"mongodb"
redis> GET db "redis"
YouTip