Skip to content

Using a struct with HSet #2454

Closed Answered by monkey92t
xorduna asked this question in Q&A
Feb 22, 2023 · 7 comments · 6 replies
Discussion options

You must be logged in to vote

Note that in older versions of Redis server(redis-server < 4.0), HSet only supports a single key-value pair.

redis-docs: https://redis.io/commands/hset (Starting with Redis version 4.0.0: Accepts multiple field and value arguments.)

If you are using a Struct type and the number of fields is greater than one, you will receive an error similar to ERR wrong number of arguments, you can use HMSet as a substitute.

redis-server >= 4.0(HSet):

client.HSet(ctx, "myhash", Per{Name: "hi", Age: 20})

redis-server < 4.0(HMSet):

client.HMSet(ctx, "myhash", Per{Name: "hi", Age: 20})

Please note that in Redis, HMSet has been marked as deprecated, and it may not be supported in the future.

#2503

Replies: 7 comments 6 replies

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
1 reply
@monkey92t
Comment options

Comment options

You must be logged in to vote
0 replies
Answer selected by monkey92t
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
1 reply
@0x30c4
Comment options

Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
4 participants