Home

HGET

HGET is a command in the Redis in-memory data structure store. It retrieves the value associated with a given field inside a hash that is stored at a specified key. If the key does not exist or the field is not present, the command returns a nil value.

Syntax: HGET key field. The command returns the string value stored for the specified field within the

Example: To set a field and then retrieve it, you might use HSET user:1001 name "Ada"; HGET

Notes and related commands: HGET is often used with a hash data model to store related attributes

Performance and data model: HGET operates in O(1) time for a single field. Hashes are a memory-efficient

hash
identified
by
key.
If
the
key
exists
but
is
not
a
hash,
Redis
returns
a
type
error
indicating
the
wrong
kind
of
value.
user:1001
name
would
return
"Ada".
If
you
ask
for
a
non-existent
field,
HGET
returns
nil.
under
a
single
key.
If
you
need
multiple
fields
at
once,
HMGET
retrieves
several
fields
in
one
call.
Other
related
commands
include
HGETALL
(returns
all
fields
and
values),
HEXISTS
(checks
for
the
existence
of
a
field),
HDEL
(deletes
a
field),
HLEN
(returns
the
number
of
fields),
HKEYS
and
HVALS
(returning
keys
and
values,
respectively).
way
to
group
related
field-value
pairs
under
a
single
key,
making
HGET
a
fast
and
common
operation
for
accessing
individual
attributes
in
a
hash.