scala-redis-nb
scala-redis-nb copied to clipboard
withTransaction signature includes private RedisOps making utility functions difficult
I want to write a function which retries a transaction a fixed number of times.
I wanted it to have a signature like this:
def retryingTransaction(count: Int)(f: RedisOps => Unit): Future[Product]
Since RedisClient.withTransaction
takes a RedisOps => Unit
.
But this is not possible because RedisOps
is private, so I have to resort to a hack of using asInstanceOf
to (possibly wrongly) coerce RedisOps
to RedisClient
so I can receive a function that takes it:
def retryingTransaction(count: Int)(f: RedisClient => Unit): Future[Product]
I believe RedisOps
should be split into two traits, for public and private interfaces, or withTransaction
should be changed to use RedisClient
instead.
Sorry for late response. I agree with your point and personally prefer the latter not to make users take care of internal classes, but am not 100% sure because the available commands may be restricted in a transaction context or in a cluster.
As we've been too busy to find a better abstraction thoroughly at this point, it would be a valid workaround to change the signature of withTransaction
as you suggested. What do you think, @debasishg?
Agree it's a hack when you have to cast :-) but doesn't look like there's a way out right now. Will definitely keep this use case in mind and try to find a better workaround.