Map functions link The mapSet function allows you to store or update a key-value pair within a map-type data structure under a specified top-level key. If the map does not already exist, it will be created automatically. This enables structured data to be efficiently grouped and manipulated under a single key.
-> Read More
Example:
const res = await client.mapSet("user-001:devices", "device-6d6f6sa66d", {
"deviceName": "Pixel 7 Pro",
"osVersion": "Android 14",
"batteryLevel": "85%"
});
console.log(res);
Full Example
async function main() {
const client = fleare.createClient("127.0.0.1", 9219);
...
try {
await client.connect();
const res = await client.mapSet("user-001:devices", "device-6d6f6sa66d", {
"deviceName": "Pixel 7 Pro",
"osVersion": "Android 14",
"batteryLevel": "85%"
});
console.log(res);
} catch (err) {
console.error(err);
} finally {
await client.close();
}
}
Output
Example:
res, err := client.MapSet("user-001:devices", "device-001", map[string]interface{}{
"deviceName": "Pixel 7 Pro",
"osVersion": "Android 14",
"batteryLevel": "85%",
})
if err != nil {
fmt.Println("Error checking existence:", err)
return
}
fmt.Println(res)
Full Example
func main() {
// Create a client with options
client := fleare.CreateClient(&fleare.Options{
Host: "127.0.0.1",
Port: 9219,
PoolSize: 1,
})
err := client.Connect()
if err != nil {
fmt.Println(err)
return
}
res, err := client.MapSet("user-001:devices", "device-001", map[string]interface{}{
"deviceName": "Pixel 7 Pro",
"osVersion": "Android 14",
"batteryLevel": "85%",
})
if err != nil {
fmt.Println("Error checking existence:", err)
return
}
fmt.Println(res)
}
Output
The mapCSet function is used to create or overwrite a map at a specified key with a single key-value entry. If the key already exists, the previous map is completely replaced with the new one containing just the given mapKey and value .
-> Read More
Example:
const res = await client.mapCSet("user-001:devices", "device-6d6f6sa66d", {
"deviceName": "Pixel 7 Pro",
"osVersion": "Android 14",
"batteryLevel": "85%"
});
console.log(res);
Output:
Example:
res, err := client.MapCSet("user-001:devices", "device-001", map[string]interface{}{
"deviceName": "Pixel 7 Pro",
"osVersion": "Android 14",
"batteryLevel": "85%",
})
if err != nil {
fmt.Println("Error checking existence:", err)
return
}
fmt.Println(res)
Output:
The mapDel function is used to delete either an entire map stored at a specific key or a specific field within that map. It supports both single-key and key-field deletion operations, ensuring efficient and flexible map data handling in memory.
-> Read More
Example:
const res = await client.mapDel("user-001:devices", "device-6d6f6sa66d");
console.log(res);
Output:
res, err := client.MapDel("user-001:devices", "device-001")
if err != nil {
fmt.Println("Error checking existence:", err)
return
}
fmt.Println(res)
Output:
The mapGet function allows users to retrieve values from a stored map object in the database. The user can either fetch the entire map stored at a given key or a specific field value inside the map using an optional mapKey .
-> Read More
Example:
const res = await client.mapGet("user-001:devices");
console.log(res);
Output:
{
"device-663abc5352": {
"batteryLevel": "75%",
"deviceName": "iPhone 14 Pro",
"osVersion": "iOS 16"
},
"device-6d6f6sa66d": {
"batteryLevel": "85%",
"deviceName": "Pixel 7 Pro",
"osVersion": "Android 14"
}
}
Example with mapKye
const res = await client.mapGet("user-001:devices", "device-6d6f6sa66d");
console.log(res);
Output:
{
"batteryLevel": "85%",
"deviceName": "Pixel 7 Pro",
"osVersion": "Android 14"
}
res, err := client.MapGet("user-001:devices")
if err != nil {
fmt.Println("Error checking existence:", err)
return
}
fmt.Println(res)
Output:
{
"device-663abc5352": {
"batteryLevel": "75%",
"deviceName": "iPhone 14 Pro",
"osVersion": "iOS 16"
},
"device-6d6f6sa66d": {
"batteryLevel": "85%",
"deviceName": "Pixel 7 Pro",
"osVersion": "Android 14"
}
}
Example with mapKye
res, err := client.MapGet("user-001:devices", "device-6d6f6sa66d")
if err != nil {
fmt.Println("Error checking existence:", err)
return
}
fmt.Println(res)
Output:
{
"batteryLevel": "85%",
"deviceName": "Pixel 7 Pro",
"osVersion": "Android 14"
}