Multi Set
Sets multiple key-value pairs in the database with optional expirations.
- Parameters:
entries
: An array of objects containing key, value, and optional expiresAt date as a Date object or number of milliseconds.
- Returns:
- The result of the operation, includes a boolean indicating whether the operation was successful or an error if the operation failed.
const result = db.multiSet<User>([
{
key: "user:1234",
value: { name: "Ahmad", age: 15 },
expiresAt: new Date("2025-12-31"), // 1 year in Date object
},
{
key: "user:5678",
value: { name: "Fatima", age: 30 },
expiresAt: 86400000, // 1 day in milliseconds
},
{ key: "user:7890", value: { name: "Mohamed", age: 25 } }, // No expiration
]);
if (result.success) {
console.log(result.data);
} else {
console.log(result.error.message);
}