Safe Haskell | None |
---|---|
Language | Haskell2010 |
- class MonadBase IO m => HasRedis m where
- getRedis :: m Connection
- newtype RedisReaderT m a = RedisReaderT {
- getRedisReader :: ReaderT Connection m a
- runRedisReaderT :: Connection -> RedisReaderT m a -> m a
- queryRedis :: HasRedis m => Redis a -> m a
- runRedisTrans :: Connection -> IO Int -> Int -> Redis (TxResult a) -> IO (TxResult a)
- queryRedisTrans :: HasRedis m => IO Int -> Int -> Redis (TxResult a) -> m (TxResult a)
Typeclass
class MonadBase IO m => HasRedis m where Source
Monad which has access to Redis connection
getRedis :: m Connection Source
HasRedis m => HasRedis (MaybeT m) | |
HasRedis m => HasRedis (IdentityT m) | |
HasRedis m => HasRedis (ContT r m) | |
HasRedis m => HasRedis (ReaderT r m) | |
HasRedis m => HasRedis (StateT s m) | |
HasRedis m => HasRedis (StateT s m) | |
HasRedis m => HasRedis (ExceptT e m) | |
(HasRedis m, Monoid w) => HasRedis (WriterT w m) | |
(HasRedis m, Monoid w) => HasRedis (WriterT w m) |
Default transformer
newtype RedisReaderT m a Source
MonadTrans RedisReaderT | |
MonadTransControl RedisReaderT | |
MonadBase b m => MonadBase b (RedisReaderT m) | |
MonadBaseControl b m => MonadBaseControl b (RedisReaderT m) | |
MonadError e m => MonadError e (RedisReaderT m) | |
MonadReader r m => MonadReader r (RedisReaderT m) | |
MonadState s m => MonadState s (RedisReaderT m) | |
MonadWriter w m => MonadWriter w (RedisReaderT m) | |
Alternative m => Alternative (RedisReaderT m) | |
Monad m => Monad (RedisReaderT m) | |
Functor m => Functor (RedisReaderT m) | |
MonadFix m => MonadFix (RedisReaderT m) | |
MonadPlus m => MonadPlus (RedisReaderT m) | |
Applicative m => Applicative (RedisReaderT m) | |
MonadIO m => MonadIO (RedisReaderT m) | |
MonadCont m => MonadCont (RedisReaderT m) | |
type StT RedisReaderT a = StT (ReaderT Connection) a | |
type StM (RedisReaderT m) a = StM (ReaderT Connection m) a |
runRedisReaderT :: Connection -> RedisReaderT m a -> m a Source
Redis interconnection
queryRedis :: HasRedis m => Redis a -> m a Source
:: Connection | |
-> IO Int | microseconds to wait between transaction retry |
-> Int | max transaction retries count |
-> Redis (TxResult a) | |
-> IO (TxResult a) |
Run redis transaction and try rerun it if it was aborted. Perform random delay between retries.
runRedisTrans con (randomRIO (100, 1000)) 10 $ do watch [key1, key2, key3] lIndex key3 0 >>= case Nothing -> unwatch *> pure TxAborted Just val -> multiExec $ do lRem key3 1 lPush key1 [val] lPush key2 [val]
In next example we copy first value to two different lists and remove
it from original list transactionally. If any value in either key1,
key2, or key3 was changed between watch
command and exec
(inside
multiExec
) then transaction will be aboretd, then thread will wait
for between 100 and 1000 microseconds, then whole action will be
relaunched.
User responsible do not perform mutating actions outside of multiExec
because this actions can be launched multiple times.
Look at next example:
runRedisTrans con (randomRIO (100, 1000)) 10 $ do watch [key1, key2, key3] lPop key3 >>= case Nothing -> unwatch *> pure TxAborted Just val -> multiExec $ do lPush key1 [val] lPush key2 [val]
It is highly unrecommended to do that, because if transaction aborted
lPop
will be performed several times (up to 10).