Arguments
string
required
The key of the hash.
integer
Optionally return more than one field.
boolean
Return the values of the fields as well.
Response
An object containing the fields and their values.
Documentation Index
Fetch the complete documentation index at: /docs/llms.txt
Use this file to discover all available pages before exploring further.
await redis.hset("key", {
id: 1,
username: "chronark",
name: "andreas"
});
const randomField = await redis.hrandfield("key");
console.log(randomField); // one of "id", "username" or "name"
await redis.hset("key", {
id: 1,
username: "chronark",
name: "andreas",
});
const randomFields = await redis.hrandfield("key", 2);
console.log(randomFields); // ["id", "username"] or any other combination
await redis.hset("key", {
id: 1,
username: "chronark",
name: "andreas",
});
const randomFields = await redis.hrandfield("key", 2, true);
console.log(randomFields); // { id: "1", username: "chronark" } or any other combination
Return a random field from a hash
await redis.hset("key", {
id: 1,
username: "chronark",
name: "andreas"
});
const randomField = await redis.hrandfield("key");
console.log(randomField); // one of "id", "username" or "name"
await redis.hset("key", {
id: 1,
username: "chronark",
name: "andreas",
});
const randomFields = await redis.hrandfield("key", 2);
console.log(randomFields); // ["id", "username"] or any other combination
await redis.hset("key", {
id: 1,
username: "chronark",
name: "andreas",
});
const randomFields = await redis.hrandfield("key", 2, true);
console.log(randomFields); // { id: "1", username: "chronark" } or any other combination
Was this page helpful?