go-redis / redismock

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

Support for TxPipeline #2

Closed zedar closed 3 years ago

zedar commented 3 years ago

What is the best way of mocking client.TxPipeline? When expectations are define for the following: HSet, ZAddNX

pipe := client.TxPipeline()
pipe.HSet
pipe.ZAddNX
pipe.Exec()

the following error is returned: call to cmd '[multi]' was not expected

monkey92t commented 3 years ago

support for txpipeline has been added:

mock.ExpectTxPipeline()
mock.ExpectGet("key").SetVal("value")
mock.ExpectSet("key", "value", 1).SetVal("OK")
mock.ExpectTxPipelineExec()

pipe = db.TxPipeline()
pipe.Get(ctx, "key")
pipe.Set(ctx, "key", "value", 1)
pipe.Exec(ctx)