Command: STR.SET
Overview
The STR.SET
command stores or updates a string value associated with a specified key. If the key already exists, its value is overwritten.
Command Name
STR.SET
Description
STR.SET
is used to store a string data item under a key. If the key already exists, its value will be overwritten with the new string. This command is part of the string operations in the Fleare database engine.
Use Cases
-
Basic String Storage
- Use
STR.SET
to initialize a key with a string value (e.g.,"Welcome"
).
- Use
-
Update Existing Key
- Store dynamic strings like
"SessionToken"
,"GreetingMessage"
, or"Status"
by updating them withSTR.SET
.
- Store dynamic strings like
-
Command in Automation Scripts
- Automate inserting default configuration or cache values during service start-up.
-
Storing Logs or Short Status Messages
- Use for quick updates like
STR.SET service:health "OK"
orSTR.SET user:123:state "active"
.
- Use for quick updates like
Syntax
STR.SET <key> <value>
-
<key>
: The key under which the value will be stored (must be a valid string key). -
<value>
: The string value to store (can include spaces if quoted).
Permissions
-
Write access is required to the target keyspace/shard.
-
No special roles or privileges are required beyond basic write permissions.
Input Examples
Example 1: Basic Set
localhost:9219> STR.SET user:greeting "Hello"
Stores "Hello"
under key user:greeting
.
Example 2: Overwrite Existing Key
localhost:9219> STR.SET user:greeting "World World"
Overwrites the previous value ( "Hello"
) with "World World"
.
Output Examples
Successful Set
localhost:9219> STR.SET user:greeting "Hello"
Ok
Overwrite with New Value
localhost:9219> STR.SET user:greeting "World World"
Ok
Verification with GET
localhost:9219> GET user:greeting
Ok "World World"
Behavior on Error
Condition | Error Message |
---|---|
Missing arguments | InvalidKeyError: invalid number of arguments |
Missing key | InvalidKeyError: Key must be provided |
Invalid key format (e.g., empty) | InvalidKeyError: <reason> |