go-redis / redismock

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

Regexp is not applying on the key #65

Open rinormaloku opened 1 year ago

rinormaloku commented 1 year ago

Regexp applies only on the value. But there are cases where the key is generated and we need to match it as well.

This code works:

mockClient.Regexp().ExpectMSet("key", ".*").SetVal("OKX")
result := client.MSet(ctx, "key", "value")  

This code doesn't work:

mockClient.Regexp().ExpectMSet(".*", "value").SetVal("OKX")
result := client.MSet(ctx, "key", "value")
monkey92t commented 1 year ago
clientMock.Regexp().ExpectSet(".*", ".*", 1*time.Second).SetVal("regexp set val")
set = client.Set(ctx, "rand_key", "rand_value", 1*time.Second)
Expect(set.Err()).NotTo(HaveOccurred())
Expect(set.Val()).To(Equal("regexp set val"))

After testing, it can work normally.

javking07 commented 10 months ago
clientMock.Regexp().ExpectSet(".*", ".*", 1*time.Second).SetVal("regexp set val")
set = client.Set(ctx, "rand_key", "rand_value", 1*time.Second)
Expect(set.Err()).NotTo(HaveOccurred())
Expect(set.Val()).To(Equal("regexp set val"))

After testing, it can work normally.

Ran into this gotcha myself. Any way this info could be integrated into the package documentation?