Arguments
str
required
The key of the hash.
int
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: /llms.txt
Use this file to discover all available pages before exploring further.
redis.hset("myhash", values={
"field1": "Hello",
"field2": "World"
})
assert redis.hrandfield("myhash") in ["field1", "field2"]
redis.hset("myhash", values={
"field1": "Hello",
"field2": "World"
})
assert redis.hrandfield("myhash", count=2) in [
["field1", "field2"],
["field2", "field1"]
]
redis.hset("myhash", values={
"field1": "Hello",
"field2": "World"
})
assert redis.hrandfield("myhash", count=1, withvalues=True) in [
{"field1": "Hello"},
{"field2": "World"}
]
Return a random field from a hash
redis.hset("myhash", values={
"field1": "Hello",
"field2": "World"
})
assert redis.hrandfield("myhash") in ["field1", "field2"]
redis.hset("myhash", values={
"field1": "Hello",
"field2": "World"
})
assert redis.hrandfield("myhash", count=2) in [
["field1", "field2"],
["field2", "field1"]
]
redis.hset("myhash", values={
"field1": "Hello",
"field2": "World"
})
assert redis.hrandfield("myhash", count=1, withvalues=True) in [
{"field1": "Hello"},
{"field2": "World"}
]
Was this page helpful?