Hashes API
Object-like data structures with field-value pairs for profiles, metadata, and records
Hashes are ideal for object-like data. A single key contains multiple field-value pairs, which makes hashes a great fit for user profiles, counters, metadata, and cached records.
Endpoints
| Method | Endpoint | Description |
|---|---|---|
| POST | /{plateId}/hashes/set | Set one field or many fields |
| GET | /{plateId}/hashes/get/{key} | Get all fields |
| GET | /{plateId}/hashes/get/{key}/{field} | Get one field |
| POST | /{plateId}/hashes/get | Get many fields |
| DELETE | /{plateId}/hashes/delete/{key}/{field} | Delete one field |
| DELETE | /{plateId}/hashes/delete/{key}?allow_delete_key=true | Delete the full hash key |
| POST | /{plateId}/hashes/delete | Delete many fields |
| GET | /{plateId}/hashes/exists/{key}/{field} | Check field existence |
| GET | /{plateId}/hashes/keys/{key} | List fields |
| GET | /{plateId}/hashes/values/{key} | List values |
| GET | /{plateId}/hashes/length/{key} | Count fields |
| POST | /{plateId}/hashes/increment | Increment numeric field |
| POST | /{plateId}/hashes/set-if-absent | HSETNX wrapper |
| GET | /{plateId}/hashes/random/{key} | Random field(s) |
| POST | /{plateId}/hashes/command | Execute allowed hash commands |
| POST | /{plateId}/hashes/{key}/command | Execute key-specific hash commands |
What Gets Stored
Set a Single Field
const plateId = "[id]";
const apiKey = "your-api-key";
const baseUrl = "[base-url]";
const response = await fetch(`${baseUrl}/$[id]/hashes/set`, {
method: "POST",
headers: {
"Authorization": apiKey,
"Content-Type": "application/json"
},
body: JSON.stringify({
key: "user:1",
field: "name",
value: "Ada"
})
});
const data = await response.json();
console.log(data);Set Many Fields from an Object
const plateId = "[id]";
const apiKey = "your-api-key";
const baseUrl = "[base-url]";
const response = await fetch(`${baseUrl}/$[id]/hashes/set`, {
method: "POST",
headers: {
"Authorization": apiKey,
"Content-Type": "application/json"
},
body: JSON.stringify({
key: "user:1",
value: {
name: "Ada",
age: 30,
email: "ada@example.com"
}
})
});
const data = await response.json();
console.log(data);Set Many Fields from a Stringified JSON Object
const plateId = "[id]";
const apiKey = "your-api-key";
const baseUrl = "[base-url]";
const response = await fetch(`${baseUrl}/$[id]/hashes/set`, {
method: "POST",
headers: {
"Authorization": apiKey,
"Content-Type": "application/json"
},
body: JSON.stringify({
key: "user:1",
value: '{"name":"Ada","age":30}'
})
});
const data = await response.json();
console.log(data);Top-level object keys become hash fields automatically. Nested objects and arrays are JSON-stringified per field instead of flattened.
Reads
Get One Field
const plateId = "[id]";
const apiKey = "your-api-key";
const baseUrl = "[base-url]";
const response = await fetch(`${baseUrl}/$[id]/hashes/get/user:1/name`, {
headers: {
"Authorization": apiKey,
"Content-Type": "application/json"
}
});
const data = await response.json();
console.log(data);Get All Fields
const plateId = "[id]";
const apiKey = "your-api-key";
const baseUrl = "[base-url]";
const response = await fetch(`${baseUrl}/$[id]/hashes/get/user:1`, {
headers: {
"Authorization": apiKey,
"Content-Type": "application/json"
}
});
const data = await response.json();
console.log(data);Get Multiple Fields
const plateId = "[id]";
const apiKey = "your-api-key";
const baseUrl = "[base-url]";
const response = await fetch(`${baseUrl}/$[id]/hashes/get`, {
method: "POST",
headers: {
"Authorization": apiKey,
"Content-Type": "application/json"
},
body: JSON.stringify({
key: "user:1",
fields: ["name", "age", "email"]
})
});
const data = await response.json();
console.log(data);Check Existence
const plateId = "[id]";
const apiKey = "your-api-key";
const baseUrl = "[base-url]";
const response = await fetch(`${baseUrl}/$[id]/hashes/exists/user:1/name`, {
headers: {
"Authorization": apiKey,
"Content-Type": "application/json"
}
});
const data = await response.json();
console.log(data);Delete Safety
Deleting fields is the default:
const plateId = "[id]";
const apiKey = "your-api-key";
const baseUrl = "[base-url]";
const response = await fetch(`${baseUrl}/$[id]/hashes/delete/user:1/age`, {
method: "DELETE",
headers: {
"Authorization": apiKey,
"Content-Type": "application/json"
}
});
const data = await response.json();
console.log(data);Delete many fields:
const plateId = "[id]";
const apiKey = "your-api-key";
const baseUrl = "[base-url]";
const response = await fetch(`${baseUrl}/$[id]/hashes/delete`, {
method: "POST",
headers: {
"Authorization": apiKey,
"Content-Type": "application/json"
},
body: JSON.stringify({
key: "user:1",
fields: ["age", "email"]
})
});
const data = await response.json();
console.log(data);Deleting the whole hash key is intentionally blocked unless you opt in:
const plateId = "[id]";
const apiKey = "your-api-key";
const baseUrl = "[base-url]";
const response = await fetch(`${baseUrl}/$[id]/hashes/delete/user:1?allow_delete_key=true`, {
method: "DELETE",
headers: {
"Authorization": apiKey,
"Content-Type": "application/json"
}
});
const data = await response.json();
console.log(data);Numeric Updates
const plateId = "[id]";
const apiKey = "your-api-key";
const baseUrl = "[base-url]";
const response = await fetch(`${baseUrl}/$[id]/hashes/increment`, {
method: "POST",
headers: {
"Authorization": apiKey,
"Content-Type": "application/json"
},
body: JSON.stringify({
key: "user:1",
field: "points",
amount: 5
})
});
const data = await response.json();
console.log(data);Floating-point amounts automatically use HINCRBYFLOAT.
Other Examples
Set if absent
const plateId = "[id]";
const apiKey = "your-api-key";
const baseUrl = "[base-url]";
const response = await fetch(`${baseUrl}/$[id]/hashes/set-if-absent`, {
method: "POST",
headers: {
"Authorization": apiKey,
"Content-Type": "application/json"
},
body: JSON.stringify({
key: "user:1",
field: "nickname",
value: "A"
})
});
const data = await response.json();
console.log(data);Random fields
const plateId = "[id]";
const apiKey = "your-api-key";
const baseUrl = "[base-url]";
const response = await fetch(`${baseUrl}/$[id]/hashes/random/user:1?count=2&with_values=true`, {
headers: {
"Authorization": apiKey,
"Content-Type": "application/json"
}
});
const data = await response.json();
console.log(data);Command Compatibility
const plateId = "[id]";
const apiKey = "your-api-key";
const baseUrl = "[base-url]";
const response = await fetch(`${baseUrl}/$[id]/hashes/command`, {
method: "POST",
headers: {
"Authorization": apiKey,
"Content-Type": "application/json"
},
body: JSON.stringify({
command: "HSET",
args: ["user:1", "name", "Ada", "age", "30"]
})
});
const data = await response.json();
console.log(data);Command Endpoints
POST /[id]/hashes/command
Execute allowed hash commands across the plate.
Allowed Commands:
| Command | Description |
|---|---|
| HSET | Set field(s) |
| HGET | Get one field |
| HMGET | Get multiple fields |
| HGETALL | Get all fields |
| HDEL | Delete field(s) |
| HEXISTS | Check field existence |
| HINCRBY | Increment integer |
| HINCRBYFLOAT | Increment float |
| HKEYS | Get all field names |
| HVALS | Get all values |
| HLEN | Get field count |
| HSETNX | Set if absent |
| HRANDFIELD | Get random field(s) |
Query Parameters for HRANDFIELD:
count(optional): Number of fields to return (negative for distinct)with_values(optional): Include values in response
POST /[id]/hashes/[key]/command
Execute allowed commands on a specific hash key.
Allowed Commands: Same as above.
Request:
const plateId = "[id]";
const apiKey = "your-api-key";
const baseUrl = "[base-url]";
const response = await fetch(`${baseUrl}/$[id]/hashes/user:1/command`, {
method: "POST",
headers: {
"Authorization": apiKey,
"Content-Type": "application/json"
},
body: JSON.stringify({
command: "HLEN"
})
});
const data = await response.json();
console.log(data);