The jsonSet function allows clients to store structured JSON objects under a specific key in a distributed, in-memory data store. If the key already exists, the stored JSON value is overwritten. This is particularly useful for schema-less data use cases like storing user profiles, configurations, and nested records.
The jsonAdd function allows users to insert or append a key-value pair into an existing JSON object stored at a given key. If the key does not exist, a new JSON object will be created. This command supports adding data at any depth using dot-notation paths.
Description
Adds a key-value pair to a JSON object stored at the specified key in the database.
If the key doesn’t exist, a new JSON object will be initialized with the provided path and value.
Nested paths are supported using . (dot) notation. Intermediate objects will be created if they do not already exist.
The value must be a valid JSON string or primitive (string, number, boolean, array, etc.).
The jsonMerge function allows users to merge a new JSON object into an existing JSON object stored at a given key. This enables incremental updates to structured JSON data without overwriting the entire value.
The jsonRemove function allows users to delete a specific field or the entire JSON object associated with a key stored in the Fleare in-memory database. It supports nested paths using dot notation and ensures safe deletion based on key validation and type checking.
The jsonSetRes function stores a JSON object at a specified key in the database and simultaneously replaces specified fields with reference pointers to other keys. This allows relational-like linking between JSON documents using reference tags. This command is useful for creating relationships between JSON documents.
await client.jsonSetRef("orders:OD001", {"orderId":"orders:OD001","details":"This order is for a new laptop.","status":"pending"}, {"userId":"users:001"});
const res = await client.jsonGet("orders:OD001", "", "userId");
console.log(res);
Output
{
"_userId": { "age": 30, "hobbies": [ "reading", "hiking" ], "name": "John" },
"details": "This order is for a new laptop.",
"orderId": "orders:OD001",
"status": "pending",
"userId": "$ref:users:001"
}
The jsonGet function retrieves JSON data stored at a specified key. You can optionally query nested fields within the JSON object using a dot-path syntax. Additionally, the command supports resolving references (e.g., $ref: values) and attaching the referenced data inline in the response.
const res = await client.jsonGet("orders:OD001", "hobbies");
console.log(res);
Output
["reading","hiking"]
Example ref
await client.jsonSetRef("orders:OD001", {"orderId":"orders:OD001","details":"This order is for a new laptop.","status":"pending"}, {"userId":"users:001"});
const res = await client.jsonGet("orders:OD001", "", "userId");
console.log(res);
Output
{
"_userId": { "age": 30, "hobbies": [ "reading", "hiking" ], "name": "John" },
"details": "This order is for a new laptop.",
"orderId": "orders:OD001",
"status": "pending",
"userId": "$ref:users:001"
}