Skip to content

Commit 4c72b4e

Browse files
monkey92tchayim
andauthored
docs: add instructions for the HSet api (redis#2503)
Signed-off-by: monkey92t <golang@88.com> Co-authored-by: Chayim <chayim@users.noreply.github.com>
1 parent 42d730c commit 4c72b4e

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

commands.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1444,7 +1444,7 @@ func (c cmdable) HMGet(ctx context.Context, key string, fields ...string) *Slice
14441444
// Playing struct With "redis" tag.
14451445
// type MyHash struct { Key1 string `redis:"key1"`; Key2 int `redis:"key2"` }
14461446
//
1447-
// - HSet("myhash", MyHash{"value1", "value2"})
1447+
// - HSet("myhash", MyHash{"value1", "value2"}) Warn: redis-server >= 4.0
14481448
//
14491449
// For struct, can be a structure pointer type, we only parse the field whose tag is redis.
14501450
// if you don't want the field to be read, you can use the `redis:"-"` flag to ignore it,
@@ -1453,7 +1453,10 @@ func (c cmdable) HMGet(ctx context.Context, key string, fields ...string) *Slice
14531453
// string, int/uint(8,16,32,64), float(32,64), time.Time(to RFC3339Nano), time.Duration(to Nanoseconds ),
14541454
// if you are other more complex or custom data types, please implement the encoding.BinaryMarshaler interface.
14551455
//
1456-
// Note that it requires Redis v4 for multiple field/value pairs support.
1456+
// Note that in older versions of Redis server(redis-server < 4.0), HSet only supports a single key-value pair.
1457+
// redis-docs: https://redis.io/commands/hset (Starting with Redis version 4.0.0: Accepts multiple field and value arguments.)
1458+
// If you are using a Struct type and the number of fields is greater than one,
1459+
// you will receive an error similar to "ERR wrong number of arguments", you can use HMSet as a substitute.
14571460
func (c cmdable) HSet(ctx context.Context, key string, values ...interface{}) *IntCmd {
14581461
args := make([]interface{}, 2, 2+len(values))
14591462
args[0] = "hset"

0 commit comments

Comments
 (0)