SET
Set a key to hold a string value.
Syntax
SET key valueDescription
The SET command stores a string value associated with a key. If the key already exists, the value is overwritten. The key can hold any string value, including binary data.
Arguments
key(required): The name of the key to set.value(required): The string value to store.
Return Value
Returns a Simple String: OK on success.
Examples
Basic SET
SET username "john_doe"Response:
OKSetting a Value
SET mykey "Hello ECHO DB"
GET mykeyResponse:
OK
"Hello ECHO DB"Overwriting an Existing Key
SET mykey "first value"
SET mykey "second value"
GET mykeyResponse:
OK
OK
"second value"Notes
- If the key already exists, the previous value is replaced
- Keys can store any string value, including binary data
- Keys are case-sensitive
- There is no limit on the size of the value (subject to available memory)
Use Cases
- Caching: Store cached values for fast retrieval
- Configuration: Store configuration strings
- Session Data: Store session information
- Simple Key-Value Storage: Basic data storage