redismock icon indicating copy to clipboard operation
redismock copied to clipboard

Regexp is not applying on the key

Open rinormaloku opened this issue 1 year ago • 2 comments

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")

rinormaloku avatar Mar 23 '23 11:03 rinormaloku

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.

monkey92t avatar Mar 23 '23 12:03 monkey92t

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?

javking07 avatar Sep 08 '23 19:09 javking07