go-redis / redismock

Redis client Mock
https://redis.uptrace.dev
BSD 2-Clause "Simplified" License
272 stars 59 forks source link

Checking a hash set created with map is failing #7

Closed 8tomat8 closed 3 years ago

8tomat8 commented 3 years ago

In one of our applications, we are using HSet to create a Redis hash map. We've been using the map syntax:

cmd, err := redisCli.HSet("key", map[string]interface{}{"1": "one", "2": "two"})

The request is later unpacked into a slice of arguments (which is native for Redis). But as it was passed as a map, the order every time is different. Then in the mock.match function we iterate over the list of expected args and comparing it to the list of cmd args. This function accesses the elements by index, so chances of getting a match decrease with each new item added into the hash :smile:

Workaround: Use the slice syntax instead:

cmd, err := redisCli.HSet("key", []string{"1", "one", "2", "two"})

It is more confusing but works :slightly_smiling_face:

I'm not really sure what could be a good approach to handle this :confused: Possible solutions on my mind:

monkey92t commented 3 years ago

sorry, i just saw your problem, i will fix it today.

8tomat8 commented 3 years ago

@monkey92t thanks a lot!