Skip to content

XAddArgs is a map and does not preserve fields order #1388

Closed as not planned
Closed as not planned
@adambabik

Description

@adambabik

From the docs about XADD:

An entry is composed of a set of field-value pairs, it is basically a small dictionary. The field-value pairs are stored in the same order they are given by the user, and commands to read the stream such as XRANGE or XREAD are guaranteed to return the fields and values exactly in the same order they were added by XADD.

This means that I can rely on the order of field-value pairs in an entry added to a stream.

However, Client.XAdd passes key-value pairs using map which does not preserve the order of fields. For example, this code:

rdb.XAdd(context.Background(), &redis.XAddArgs{
	Stream: "my-stream",
	Values: map[string]interface{}{
		"field1": "value1",
		"field2": "value2",
		"field3": "value3",
	},
})

may produce arbitrary order of the key-value pairs in the stream entry.

My proposal is to replace map with []interface{}{"key1", "value1", ...}, however, this is not backward compatible.

Alternatively, it can work similarly to Client.HSet so ofer all three ways to specify the pairs:

- HSet("myhash", "key1", "value1", "key2", "value2")
- HSet("myhash", []string{"key1", "value1", "key2", "value2"})
- HSet("myhash", map[string]interface{}{"key1": "value1", "key2": "value2"})

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions