Safe Haskell | None |
---|---|
Language | Haskell2010 |
Database.Redis like interface with connection through Redis Sentinel.
More details here: https://redis.io/topics/sentinel.
Example:
conn <-connect
SentinelConnectionInfo
(("localhost", PortNumber 26379) :| []) "mymaster"defaultConnectInfo
runRedis
conn $ doset
"hello" "world"
When connection is opened, the Sentinels will be queried to get current master. Subsequent runRedis
calls will talk to that master.
If runRedis
call fails, the next call will choose a new master to talk to.
This implementation is based on Gist by Emanuel Borsboom at https://gist.github.com/borsboom/681d37d273d5c4168723
Synopsis
- data SentinelConnectInfo = SentinelConnectInfo {}
- data SentinelConnection
- connect :: SentinelConnectInfo -> IO SentinelConnection
- runRedis :: SentinelConnection -> Redis (Either Reply a) -> IO (Either Reply a)
- data RedisSentinelException = NoSentinels (NonEmpty (HostName, PortID))
- data HashSlot
- keyToSlot :: ByteString -> HashSlot
- data PortID
- data ConnectionLostException = ConnectionLost
- newtype ConnectTimeout = ConnectTimeout ConnectPhase
- data Reply
- = SingleLine ByteString
- | Error ByteString
- | Integer Integer
- | Bulk (Maybe ByteString)
- | MultiBulk (Maybe [Reply])
- data RedisType
- data Status
- = Ok
- | Pong
- | Status ByteString
- class RedisResult a where
- data Redis a
- class Monad m => MonadRedis m where
- class MonadRedis m => RedisCtx m f | m -> f where
- returnDecode :: RedisResult a => Reply -> m (f a)
- unRedis :: Redis a -> ReaderT RedisEnv IO a
- reRedis :: ReaderT RedisEnv IO a -> Redis a
- sendRequest :: (RedisCtx m f, RedisResult a) => [ByteString] -> m (f a)
- data TxResult a
- data Queued a
- data RedisTx a
- watch :: [ByteString] -> Redis (Either Reply Status)
- unwatch :: Redis (Either Reply Status)
- multiExec :: RedisTx (Queued a) -> Redis (TxResult a)
- data ClusterSlotsResponseEntry = ClusterSlotsResponseEntry {}
- data ClusterSlotsNode = ClusterSlotsNode {}
- data ClusterSlotsResponse = ClusterSlotsResponse {}
- data ClusterNodesResponseSlotSpec
- data ClusterNodesResponseEntry = ClusterNodesResponseEntry {
- clusterNodesResponseNodeId :: ByteString
- clusterNodesResponseNodeIp :: ByteString
- clusterNodesResponseNodePort :: Integer
- clusterNodesResponseNodeFlags :: [ByteString]
- clusterNodesResponseMasterId :: Maybe ByteString
- clusterNodesResponsePingSent :: Integer
- clusterNodesResponsePongReceived :: Integer
- clusterNodesResponseConfigEpoch :: Integer
- clusterNodesResponseLinkState :: ByteString
- clusterNodesResponseSlots :: [ClusterNodesResponseSlotSpec]
- data ClusterNodesResponse = ClusterNodesResponse {}
- data XInfoStreamResponse = XInfoStreamResponse {}
- data XInfoGroupsResponse = XInfoGroupsResponse {}
- data XInfoConsumersResponse = XInfoConsumersResponse {}
- data XClaimOpts = XClaimOpts {}
- data XPendingDetailRecord = XPendingDetailRecord {}
- data XPendingSummaryResponse = XPendingSummaryResponse {}
- data XReadResponse = XReadResponse {
- stream :: ByteString
- records :: [StreamsRecord]
- data XReadOpts = XReadOpts {}
- data StreamsRecord = StreamsRecord {
- recordId :: ByteString
- keyValues :: [(ByteString, ByteString)]
- data TrimOpts
- data RangeLex a
- data ScanOpts = ScanOpts {}
- data Cursor
- data ReplyMode
- data ZaddOpts = ZaddOpts {}
- data DebugMode
- data SetOpts = SetOpts {}
- data Condition
- data MigrateOpts = MigrateOpts {}
- data Aggregate
- data SortOrder
- data SortOpts = SortOpts {}
- data Slowlog = Slowlog {}
- objectRefcount :: RedisCtx m f => ByteString -> m (f Integer)
- objectIdletime :: RedisCtx m f => ByteString -> m (f Integer)
- objectEncoding :: RedisCtx m f => ByteString -> m (f ByteString)
- linsertBefore :: RedisCtx m f => ByteString -> ByteString -> ByteString -> m (f Integer)
- linsertAfter :: RedisCtx m f => ByteString -> ByteString -> ByteString -> m (f Integer)
- getType :: RedisCtx m f => ByteString -> m (f RedisType)
- slowlogGet :: RedisCtx m f => Integer -> m (f [Slowlog])
- slowlogLen :: RedisCtx m f => m (f Integer)
- slowlogReset :: RedisCtx m f => m (f Status)
- zrange :: RedisCtx m f => ByteString -> Integer -> Integer -> m (f [ByteString])
- zrangeWithscores :: RedisCtx m f => ByteString -> Integer -> Integer -> m (f [(ByteString, Double)])
- zrevrange :: RedisCtx m f => ByteString -> Integer -> Integer -> m (f [ByteString])
- zrevrangeWithscores :: RedisCtx m f => ByteString -> Integer -> Integer -> m (f [(ByteString, Double)])
- zrangebyscore :: RedisCtx m f => ByteString -> Double -> Double -> m (f [ByteString])
- zrangebyscoreWithscores :: RedisCtx m f => ByteString -> Double -> Double -> m (f [(ByteString, Double)])
- zrangebyscoreLimit :: RedisCtx m f => ByteString -> Double -> Double -> Integer -> Integer -> m (f [ByteString])
- zrangebyscoreWithscoresLimit :: RedisCtx m f => ByteString -> Double -> Double -> Integer -> Integer -> m (f [(ByteString, Double)])
- zrevrangebyscore :: RedisCtx m f => ByteString -> Double -> Double -> m (f [ByteString])
- zrevrangebyscoreWithscores :: RedisCtx m f => ByteString -> Double -> Double -> m (f [(ByteString, Double)])
- zrevrangebyscoreLimit :: RedisCtx m f => ByteString -> Double -> Double -> Integer -> Integer -> m (f [ByteString])
- zrevrangebyscoreWithscoresLimit :: RedisCtx m f => ByteString -> Double -> Double -> Integer -> Integer -> m (f [(ByteString, Double)])
- defaultSortOpts :: SortOpts
- sortStore :: RedisCtx m f => ByteString -> ByteString -> SortOpts -> m (f Integer)
- sort :: RedisCtx m f => ByteString -> SortOpts -> m (f [ByteString])
- zunionstore :: RedisCtx m f => ByteString -> [ByteString] -> Aggregate -> m (f Integer)
- zunionstoreWeights :: RedisCtx m f => ByteString -> [(ByteString, Double)] -> Aggregate -> m (f Integer)
- zinterstore :: RedisCtx m f => ByteString -> [ByteString] -> Aggregate -> m (f Integer)
- zinterstoreWeights :: RedisCtx m f => ByteString -> [(ByteString, Double)] -> Aggregate -> m (f Integer)
- eval :: (RedisCtx m f, RedisResult a) => ByteString -> [ByteString] -> [ByteString] -> m (f a)
- evalsha :: (RedisCtx m f, RedisResult a) => ByteString -> [ByteString] -> [ByteString] -> m (f a)
- bitcount :: RedisCtx m f => ByteString -> m (f Integer)
- bitcountRange :: RedisCtx m f => ByteString -> Integer -> Integer -> m (f Integer)
- bitopAnd :: RedisCtx m f => ByteString -> [ByteString] -> m (f Integer)
- bitopOr :: RedisCtx m f => ByteString -> [ByteString] -> m (f Integer)
- bitopXor :: RedisCtx m f => ByteString -> [ByteString] -> m (f Integer)
- bitopNot :: RedisCtx m f => ByteString -> ByteString -> m (f Integer)
- migrate :: RedisCtx m f => ByteString -> ByteString -> ByteString -> Integer -> Integer -> m (f Status)
- defaultMigrateOpts :: MigrateOpts
- migrateMultiple :: RedisCtx m f => ByteString -> ByteString -> Integer -> Integer -> MigrateOpts -> [ByteString] -> m (f Status)
- restore :: RedisCtx m f => ByteString -> Integer -> ByteString -> m (f Status)
- restoreReplace :: RedisCtx m f => ByteString -> Integer -> ByteString -> m (f Status)
- set :: RedisCtx m f => ByteString -> ByteString -> m (f Status)
- setOpts :: RedisCtx m f => ByteString -> ByteString -> SetOpts -> m (f Status)
- scriptDebug :: RedisCtx m f => DebugMode -> m (f Bool)
- zadd :: RedisCtx m f => ByteString -> [(Double, ByteString)] -> m (f Integer)
- defaultZaddOpts :: ZaddOpts
- zaddOpts :: RedisCtx m f => ByteString -> [(Double, ByteString)] -> ZaddOpts -> m (f Integer)
- clientReply :: RedisCtx m f => ReplyMode -> m (f Bool)
- srandmember :: RedisCtx m f => ByteString -> m (f (Maybe ByteString))
- srandmemberN :: RedisCtx m f => ByteString -> Integer -> m (f [ByteString])
- spop :: RedisCtx m f => ByteString -> m (f (Maybe ByteString))
- spopN :: RedisCtx m f => ByteString -> Integer -> m (f [ByteString])
- info :: RedisCtx m f => m (f ByteString)
- infoSection :: RedisCtx m f => ByteString -> m (f ByteString)
- exists :: RedisCtx m f => ByteString -> m (f Bool)
- cursor0 :: Cursor
- scan :: RedisCtx m f => Cursor -> m (f (Cursor, [ByteString]))
- defaultScanOpts :: ScanOpts
- scanOpts :: RedisCtx m f => Cursor -> ScanOpts -> m (f (Cursor, [ByteString]))
- sscan :: RedisCtx m f => ByteString -> Cursor -> m (f (Cursor, [ByteString]))
- sscanOpts :: RedisCtx m f => ByteString -> Cursor -> ScanOpts -> m (f (Cursor, [ByteString]))
- hscan :: RedisCtx m f => ByteString -> Cursor -> m (f (Cursor, [(ByteString, ByteString)]))
- hscanOpts :: RedisCtx m f => ByteString -> Cursor -> ScanOpts -> m (f (Cursor, [(ByteString, ByteString)]))
- zscan :: RedisCtx m f => ByteString -> Cursor -> m (f (Cursor, [(ByteString, Double)]))
- zscanOpts :: RedisCtx m f => ByteString -> Cursor -> ScanOpts -> m (f (Cursor, [(ByteString, Double)]))
- zrangebylex :: RedisCtx m f => ByteString -> RangeLex ByteString -> RangeLex ByteString -> m (f [ByteString])
- zrangebylexLimit :: RedisCtx m f => ByteString -> RangeLex ByteString -> RangeLex ByteString -> Integer -> Integer -> m (f [ByteString])
- xaddOpts :: RedisCtx m f => ByteString -> ByteString -> [(ByteString, ByteString)] -> TrimOpts -> m (f ByteString)
- xadd :: RedisCtx m f => ByteString -> ByteString -> [(ByteString, ByteString)] -> m (f ByteString)
- defaultXreadOpts :: XReadOpts
- xreadOpts :: RedisCtx m f => [(ByteString, ByteString)] -> XReadOpts -> m (f (Maybe [XReadResponse]))
- xread :: RedisCtx m f => [(ByteString, ByteString)] -> m (f (Maybe [XReadResponse]))
- xreadGroupOpts :: RedisCtx m f => ByteString -> ByteString -> [(ByteString, ByteString)] -> XReadOpts -> m (f (Maybe [XReadResponse]))
- xreadGroup :: RedisCtx m f => ByteString -> ByteString -> [(ByteString, ByteString)] -> m (f (Maybe [XReadResponse]))
- xgroupCreate :: RedisCtx m f => ByteString -> ByteString -> ByteString -> m (f Status)
- xgroupSetId :: RedisCtx m f => ByteString -> ByteString -> ByteString -> m (f Status)
- xgroupDelConsumer :: RedisCtx m f => ByteString -> ByteString -> ByteString -> m (f Integer)
- xgroupDestroy :: RedisCtx m f => ByteString -> ByteString -> m (f Bool)
- xack :: RedisCtx m f => ByteString -> ByteString -> [ByteString] -> m (f Integer)
- xrange :: RedisCtx m f => ByteString -> ByteString -> ByteString -> Maybe Integer -> m (f [StreamsRecord])
- xrevRange :: RedisCtx m f => ByteString -> ByteString -> ByteString -> Maybe Integer -> m (f [StreamsRecord])
- xlen :: RedisCtx m f => ByteString -> m (f Integer)
- xpendingSummary :: RedisCtx m f => ByteString -> ByteString -> Maybe ByteString -> m (f XPendingSummaryResponse)
- xpendingDetail :: RedisCtx m f => ByteString -> ByteString -> ByteString -> ByteString -> Integer -> Maybe ByteString -> m (f [XPendingDetailRecord])
- defaultXClaimOpts :: XClaimOpts
- xclaim :: RedisCtx m f => ByteString -> ByteString -> ByteString -> Integer -> XClaimOpts -> [ByteString] -> m (f [StreamsRecord])
- xclaimJustIds :: RedisCtx m f => ByteString -> ByteString -> ByteString -> Integer -> XClaimOpts -> [ByteString] -> m (f [ByteString])
- xinfoConsumers :: RedisCtx m f => ByteString -> ByteString -> m (f [XInfoConsumersResponse])
- xinfoGroups :: RedisCtx m f => ByteString -> m (f [XInfoGroupsResponse])
- xinfoStream :: RedisCtx m f => ByteString -> m (f XInfoStreamResponse)
- xdel :: RedisCtx m f => ByteString -> [ByteString] -> m (f Integer)
- xtrim :: RedisCtx m f => ByteString -> TrimOpts -> m (f Integer)
- inf :: RealFloat a => a
- auth :: RedisCtx m f => ByteString -> m (f Status)
- select :: RedisCtx m f => Integer -> m (f Status)
- ping :: RedisCtx m f => m (f Status)
- clusterNodes :: RedisCtx m f => m (f ClusterNodesResponse)
- clusterSlots :: RedisCtx m f => m (f ClusterSlotsResponse)
- clusterSetSlotImporting :: RedisCtx m f => Integer -> ByteString -> m (f Status)
- clusterSetSlotMigrating :: RedisCtx m f => Integer -> ByteString -> m (f Status)
- clusterSetSlotStable :: RedisCtx m f => Integer -> m (f Status)
- clusterSetSlotNode :: RedisCtx m f => Integer -> ByteString -> m (f Status)
- clusterGetKeysInSlot :: RedisCtx m f => Integer -> Integer -> m (f [ByteString])
- command :: RedisCtx m f => m (f [CommandInfo])
- ttl :: RedisCtx m f => ByteString -> m (f Integer)
- setnx :: RedisCtx m f => ByteString -> ByteString -> m (f Bool)
- pttl :: RedisCtx m f => ByteString -> m (f Integer)
- commandCount :: RedisCtx m f => m (f Integer)
- clientSetname :: RedisCtx m f => ByteString -> m (f ByteString)
- zrank :: RedisCtx m f => ByteString -> ByteString -> m (f (Maybe Integer))
- zremrangebyscore :: RedisCtx m f => ByteString -> Double -> Double -> m (f Integer)
- hkeys :: RedisCtx m f => ByteString -> m (f [ByteString])
- slaveof :: RedisCtx m f => ByteString -> ByteString -> m (f Status)
- rpushx :: RedisCtx m f => ByteString -> ByteString -> m (f Integer)
- debugObject :: RedisCtx m f => ByteString -> m (f ByteString)
- bgsave :: RedisCtx m f => m (f Status)
- hlen :: RedisCtx m f => ByteString -> m (f Integer)
- rpoplpush :: RedisCtx m f => ByteString -> ByteString -> m (f (Maybe ByteString))
- brpop :: RedisCtx m f => [ByteString] -> Integer -> m (f (Maybe (ByteString, ByteString)))
- bgrewriteaof :: RedisCtx m f => m (f Status)
- zincrby :: RedisCtx m f => ByteString -> Integer -> ByteString -> m (f Double)
- hgetall :: RedisCtx m f => ByteString -> m (f [(ByteString, ByteString)])
- hmset :: RedisCtx m f => ByteString -> [(ByteString, ByteString)] -> m (f Status)
- sinter :: RedisCtx m f => [ByteString] -> m (f [ByteString])
- pfadd :: RedisCtx m f => ByteString -> [ByteString] -> m (f Integer)
- zremrangebyrank :: RedisCtx m f => ByteString -> Integer -> Integer -> m (f Integer)
- flushdb :: RedisCtx m f => m (f Status)
- sadd :: RedisCtx m f => ByteString -> [ByteString] -> m (f Integer)
- lindex :: RedisCtx m f => ByteString -> Integer -> m (f (Maybe ByteString))
- lpush :: RedisCtx m f => ByteString -> [ByteString] -> m (f Integer)
- hstrlen :: RedisCtx m f => ByteString -> ByteString -> m (f Integer)
- smove :: RedisCtx m f => ByteString -> ByteString -> ByteString -> m (f Bool)
- zscore :: RedisCtx m f => ByteString -> ByteString -> m (f (Maybe Double))
- configResetstat :: RedisCtx m f => m (f Status)
- pfcount :: RedisCtx m f => [ByteString] -> m (f Integer)
- hdel :: RedisCtx m f => ByteString -> [ByteString] -> m (f Integer)
- incrbyfloat :: RedisCtx m f => ByteString -> Double -> m (f Double)
- setbit :: RedisCtx m f => ByteString -> Integer -> ByteString -> m (f Integer)
- flushall :: RedisCtx m f => m (f Status)
- incrby :: RedisCtx m f => ByteString -> Integer -> m (f Integer)
- time :: RedisCtx m f => m (f (Integer, Integer))
- smembers :: RedisCtx m f => ByteString -> m (f [ByteString])
- zlexcount :: RedisCtx m f => ByteString -> ByteString -> ByteString -> m (f Integer)
- sunion :: RedisCtx m f => [ByteString] -> m (f [ByteString])
- sinterstore :: RedisCtx m f => ByteString -> [ByteString] -> m (f Integer)
- hvals :: RedisCtx m f => ByteString -> m (f [ByteString])
- configSet :: RedisCtx m f => ByteString -> ByteString -> m (f Status)
- scriptFlush :: RedisCtx m f => m (f Status)
- dbsize :: RedisCtx m f => m (f Integer)
- wait :: RedisCtx m f => Integer -> Integer -> m (f Integer)
- lpop :: RedisCtx m f => ByteString -> m (f (Maybe ByteString))
- clientPause :: RedisCtx m f => Integer -> m (f Status)
- expire :: RedisCtx m f => ByteString -> Integer -> m (f Bool)
- mget :: RedisCtx m f => [ByteString] -> m (f [Maybe ByteString])
- bitpos :: RedisCtx m f => ByteString -> Integer -> Integer -> Integer -> m (f Integer)
- lastsave :: RedisCtx m f => m (f Integer)
- pexpire :: RedisCtx m f => ByteString -> Integer -> m (f Bool)
- clientList :: RedisCtx m f => m (f [ByteString])
- renamenx :: RedisCtx m f => ByteString -> ByteString -> m (f Bool)
- pfmerge :: RedisCtx m f => ByteString -> [ByteString] -> m (f ByteString)
- lrem :: RedisCtx m f => ByteString -> Integer -> ByteString -> m (f Integer)
- sdiff :: RedisCtx m f => [ByteString] -> m (f [ByteString])
- get :: RedisCtx m f => ByteString -> m (f (Maybe ByteString))
- getrange :: RedisCtx m f => ByteString -> Integer -> Integer -> m (f ByteString)
- sdiffstore :: RedisCtx m f => ByteString -> [ByteString] -> m (f Integer)
- zcount :: RedisCtx m f => ByteString -> Double -> Double -> m (f Integer)
- scriptLoad :: RedisCtx m f => ByteString -> m (f ByteString)
- getset :: RedisCtx m f => ByteString -> ByteString -> m (f (Maybe ByteString))
- dump :: RedisCtx m f => ByteString -> m (f ByteString)
- keys :: RedisCtx m f => ByteString -> m (f [ByteString])
- configGet :: RedisCtx m f => ByteString -> m (f [(ByteString, ByteString)])
- rpush :: RedisCtx m f => ByteString -> [ByteString] -> m (f Integer)
- randomkey :: RedisCtx m f => m (f (Maybe ByteString))
- hsetnx :: RedisCtx m f => ByteString -> ByteString -> ByteString -> m (f Bool)
- mset :: RedisCtx m f => [(ByteString, ByteString)] -> m (f Status)
- setex :: RedisCtx m f => ByteString -> Integer -> ByteString -> m (f Status)
- psetex :: RedisCtx m f => ByteString -> Integer -> ByteString -> m (f Status)
- scard :: RedisCtx m f => ByteString -> m (f Integer)
- scriptExists :: RedisCtx m f => [ByteString] -> m (f [Bool])
- sunionstore :: RedisCtx m f => ByteString -> [ByteString] -> m (f Integer)
- persist :: RedisCtx m f => ByteString -> m (f Bool)
- strlen :: RedisCtx m f => ByteString -> m (f Integer)
- lpushx :: RedisCtx m f => ByteString -> ByteString -> m (f Integer)
- hset :: RedisCtx m f => ByteString -> ByteString -> ByteString -> m (f Integer)
- brpoplpush :: RedisCtx m f => ByteString -> ByteString -> Integer -> m (f (Maybe ByteString))
- zrevrank :: RedisCtx m f => ByteString -> ByteString -> m (f (Maybe Integer))
- scriptKill :: RedisCtx m f => m (f Status)
- setrange :: RedisCtx m f => ByteString -> Integer -> ByteString -> m (f Integer)
- del :: RedisCtx m f => [ByteString] -> m (f Integer)
- hincrbyfloat :: RedisCtx m f => ByteString -> ByteString -> Double -> m (f Double)
- hincrby :: RedisCtx m f => ByteString -> ByteString -> Integer -> m (f Integer)
- zremrangebylex :: RedisCtx m f => ByteString -> ByteString -> ByteString -> m (f Integer)
- rpop :: RedisCtx m f => ByteString -> m (f (Maybe ByteString))
- rename :: RedisCtx m f => ByteString -> ByteString -> m (f Status)
- zrem :: RedisCtx m f => ByteString -> [ByteString] -> m (f Integer)
- hexists :: RedisCtx m f => ByteString -> ByteString -> m (f Bool)
- clientGetname :: RedisCtx m f => m (f Status)
- configRewrite :: RedisCtx m f => m (f Status)
- decr :: RedisCtx m f => ByteString -> m (f Integer)
- hmget :: RedisCtx m f => ByteString -> [ByteString] -> m (f [Maybe ByteString])
- lrange :: RedisCtx m f => ByteString -> Integer -> Integer -> m (f [ByteString])
- decrby :: RedisCtx m f => ByteString -> Integer -> m (f Integer)
- llen :: RedisCtx m f => ByteString -> m (f Integer)
- append :: RedisCtx m f => ByteString -> ByteString -> m (f Integer)
- incr :: RedisCtx m f => ByteString -> m (f Integer)
- hget :: RedisCtx m f => ByteString -> ByteString -> m (f (Maybe ByteString))
- pexpireat :: RedisCtx m f => ByteString -> Integer -> m (f Bool)
- ltrim :: RedisCtx m f => ByteString -> Integer -> Integer -> m (f Status)
- zcard :: RedisCtx m f => ByteString -> m (f Integer)
- lset :: RedisCtx m f => ByteString -> Integer -> ByteString -> m (f Status)
- expireat :: RedisCtx m f => ByteString -> Integer -> m (f Bool)
- save :: RedisCtx m f => m (f Status)
- move :: RedisCtx m f => ByteString -> Integer -> m (f Bool)
- getbit :: RedisCtx m f => ByteString -> Integer -> m (f Integer)
- msetnx :: RedisCtx m f => [(ByteString, ByteString)] -> m (f Bool)
- commandInfo :: RedisCtx m f => [ByteString] -> m (f [ByteString])
- quit :: RedisCtx m f => m (f Status)
- blpop :: RedisCtx m f => [ByteString] -> Integer -> m (f (Maybe (ByteString, ByteString)))
- srem :: RedisCtx m f => ByteString -> [ByteString] -> m (f Integer)
- echo :: RedisCtx m f => ByteString -> m (f ByteString)
- sismember :: RedisCtx m f => ByteString -> ByteString -> m (f Bool)
- data ConnectError
- data ConnectInfo = ConnInfo {}
- defaultConnectInfo :: ConnectInfo
- checkedConnect :: ConnectInfo -> IO Connection
- disconnect :: Connection -> IO ()
- withConnect :: (MonadMask m, MonadIO m) => ConnectInfo -> (Connection -> m c) -> m c
- withCheckedConnect :: ConnectInfo -> (Connection -> IO c) -> IO c
- connectCluster :: ConnectInfo -> IO Connection
- data PubSubController
- type UnregisterCallbacksAction = IO ()
- type PMessageCallback = RedisChannel -> ByteString -> IO ()
- type MessageCallback = ByteString -> IO ()
- type RedisPChannel = ByteString
- type RedisChannel = ByteString
- data Message
- data PubSub
- publish :: RedisCtx m f => ByteString -> ByteString -> m (f Integer)
- subscribe :: [ByteString] -> PubSub
- unsubscribe :: [ByteString] -> PubSub
- psubscribe :: [ByteString] -> PubSub
- punsubscribe :: [ByteString] -> PubSub
- pubSub :: PubSub -> (Message -> IO PubSub) -> Redis ()
- newPubSubController :: MonadIO m => [(RedisChannel, MessageCallback)] -> [(RedisPChannel, PMessageCallback)] -> m PubSubController
- currentChannels :: MonadIO m => PubSubController -> m [RedisChannel]
- currentPChannels :: MonadIO m => PubSubController -> m [RedisPChannel]
- addChannels :: MonadIO m => PubSubController -> [(RedisChannel, MessageCallback)] -> [(RedisPChannel, PMessageCallback)] -> m UnregisterCallbacksAction
- addChannelsAndWait :: MonadIO m => PubSubController -> [(RedisChannel, MessageCallback)] -> [(RedisPChannel, PMessageCallback)] -> m UnregisterCallbacksAction
- removeChannels :: MonadIO m => PubSubController -> [RedisChannel] -> [RedisPChannel] -> m ()
- removeChannelsAndWait :: MonadIO m => PubSubController -> [RedisChannel] -> [RedisPChannel] -> m ()
- pubSubForever :: Connection -> PubSubController -> IO () -> IO ()
- parseConnectInfo :: String -> Either String ConnectInfo
Connection
data SentinelConnectInfo Source #
Configuration of Sentinel hosts.
SentinelConnectInfo | |
|
Instances
Show SentinelConnectInfo Source # | |
Defined in Database.Redis.Sentinel showsPrec :: Int -> SentinelConnectInfo -> ShowS # show :: SentinelConnectInfo -> String # showList :: [SentinelConnectInfo] -> ShowS # |
data SentinelConnection Source #
runRedis with Sentinel support
runRedis :: SentinelConnection -> Redis (Either Reply a) -> IO (Either Reply a) Source #
Interact with a Redis datastore. See runRedis
for details.
data RedisSentinelException Source #
Exception thrown by Database.Redis.Sentinel.
NoSentinels (NonEmpty (HostName, PortID)) | Thrown if no sentinel can be reached. |
Instances
Show RedisSentinelException Source # | |
Defined in Database.Redis.Sentinel showsPrec :: Int -> RedisSentinelException -> ShowS # show :: RedisSentinelException -> String # showList :: [RedisSentinelException] -> ShowS # | |
Exception RedisSentinelException Source # | |
Re-export Database.Redis
Instances
Enum HashSlot Source # | |
Defined in Database.Redis.Cluster.HashSlot | |
Eq HashSlot Source # | |
Integral HashSlot Source # | |
Defined in Database.Redis.Cluster.HashSlot | |
Num HashSlot Source # | |
Ord HashSlot Source # | |
Defined in Database.Redis.Cluster.HashSlot | |
Real HashSlot Source # | |
Defined in Database.Redis.Cluster.HashSlot toRational :: HashSlot -> Rational # | |
Show HashSlot Source # | |
keyToSlot :: ByteString -> HashSlot Source #
Compute the hashslot associated with a key
Instances
data ConnectionLostException Source #
Instances
newtype ConnectTimeout Source #
ConnectTimeout ConnectPhase |
Instances
Show ConnectTimeout Source # | |
Defined in Database.Redis.ConnectionContext showsPrec :: Int -> ConnectTimeout -> ShowS # show :: ConnectTimeout -> String # showList :: [ConnectTimeout] -> ShowS # | |
Exception ConnectTimeout Source # | |
Defined in Database.Redis.ConnectionContext |
Low-level representation of replies from the Redis server.
SingleLine ByteString | |
Error ByteString | |
Integer Integer | |
Bulk (Maybe ByteString) | |
MultiBulk (Maybe [Reply]) |
Instances
Instances
Eq Status Source # | |
Show Status Source # | |
Generic Status Source # | |
NFData Status Source # | |
Defined in Database.Redis.Types | |
RedisResult Status Source # | |
type Rep Status Source # | |
Defined in Database.Redis.Types type Rep Status = D1 ('MetaData "Status" "Database.Redis.Types" "hedis-0.14.2-6awqAJzDqBjD7lj5RyLFIN" 'False) (C1 ('MetaCons "Ok" 'PrefixI 'False) (U1 :: Type -> Type) :+: (C1 ('MetaCons "Pong" 'PrefixI 'False) (U1 :: Type -> Type) :+: C1 ('MetaCons "Status" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 ByteString)))) |
class RedisResult a where Source #
Instances
Context for normal command execution, outside of transactions. Use
runRedis
to run actions of this type.
In this context, each result is wrapped in an Either
to account for the
possibility of Redis returning an Error
reply.
Instances
Monad Redis Source # | |
Functor Redis Source # | |
MonadFail Redis Source # | |
Defined in Database.Redis.Core.Internal | |
Applicative Redis Source # | |
MonadIO Redis Source # | |
Defined in Database.Redis.Core.Internal | |
MonadRedis Redis Source # | |
RedisCtx Redis (Either Reply) Source # | |
Defined in Database.Redis.Core returnDecode :: RedisResult a => Reply -> Redis (Either Reply a) Source # |
class Monad m => MonadRedis m where Source #
Instances
class MonadRedis m => RedisCtx m f | m -> f where Source #
This class captures the following behaviour: In a context m
, a command
will return its result wrapped in a "container" of type f
.
Please refer to the Command Type Signatures section of this page for more information.
returnDecode :: RedisResult a => Reply -> m (f a) Source #
Instances
RedisCtx RedisTx Queued Source # | |
Defined in Database.Redis.Transactions returnDecode :: RedisResult a => Reply -> RedisTx (Queued a) Source # | |
RedisCtx Redis (Either Reply) Source # | |
Defined in Database.Redis.Core returnDecode :: RedisResult a => Reply -> Redis (Either Reply a) Source # |
sendRequest :: (RedisCtx m f, RedisResult a) => [ByteString] -> m (f a) Source #
sendRequest
can be used to implement commands from experimental
versions of Redis. An example of how to implement a command is given
below.
-- |Redis DEBUG OBJECT command debugObject :: ByteString ->Redis
(EitherReply
ByteString) debugObject key =sendRequest
["DEBUG", "OBJECT", key]
Result of a multiExec
transaction.
TxSuccess a | Transaction completed successfully. The wrapped value corresponds to
the |
TxAborted | Transaction aborted due to an earlier |
TxError String | At least one of the commands returned an |
Instances
Eq a => Eq (TxResult a) Source # | |
Show a => Show (TxResult a) Source # | |
Generic (TxResult a) Source # | |
NFData a => NFData (TxResult a) Source # | |
Defined in Database.Redis.Transactions | |
type Rep (TxResult a) Source # | |
Defined in Database.Redis.Transactions type Rep (TxResult a) = D1 ('MetaData "TxResult" "Database.Redis.Transactions" "hedis-0.14.2-6awqAJzDqBjD7lj5RyLFIN" 'False) (C1 ('MetaCons "TxSuccess" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 a)) :+: (C1 ('MetaCons "TxAborted" 'PrefixI 'False) (U1 :: Type -> Type) :+: C1 ('MetaCons "TxError" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 String)))) |
A Queued
value represents the result of a command inside a transaction. It
is a proxy object for the actual result, which will only be available
after returning from a multiExec
transaction.
Queued
values are composable by utilizing the Functor
, Applicative
or
Monad
interfaces.
Command-context inside of MULTI/EXEC transactions. Use multiExec
to run
actions of this type.
In the RedisTx
context, all commands return a Queued
value. It is a
proxy object for the actual result, which will only be available after
finishing the transaction.
Instances
Monad RedisTx Source # | |
Functor RedisTx Source # | |
Applicative RedisTx Source # | |
MonadIO RedisTx Source # | |
Defined in Database.Redis.Transactions | |
MonadRedis RedisTx Source # | |
RedisCtx RedisTx Queued Source # | |
Defined in Database.Redis.Transactions returnDecode :: RedisResult a => Reply -> RedisTx (Queued a) Source # |
:: [ByteString] | key |
-> Redis (Either Reply Status) |
Watch the given keys to determine execution of the MULTI/EXEC block (http://redis.io/commands/watch).
unwatch :: Redis (Either Reply Status) Source #
Forget about all watched keys (http://redis.io/commands/unwatch).
multiExec :: RedisTx (Queued a) -> Redis (TxResult a) Source #
Run commands inside a transaction. For documentation on the semantics of Redis transaction see http://redis.io/topics/transactions.
Inside the transaction block, command functions return their result wrapped
in a Queued
. The Queued
result is a proxy object for the actual
command's result, which will only be available after EXEC
ing the
transaction.
Example usage (note how Queued
's Applicative
instance is used to
combine the two individual results):
runRedis conn $ do
set "hello" "hello"
set "world" "world"
helloworld <- multiExec
$ do
hello <- get "hello"
world <- get "world"
return $ (,) <$> hello <*> world
liftIO (print helloworld)
data ClusterSlotsResponseEntry Source #
Instances
Show ClusterSlotsResponseEntry Source # | |
Defined in Database.Redis.ManualCommands showsPrec :: Int -> ClusterSlotsResponseEntry -> ShowS # show :: ClusterSlotsResponseEntry -> String # showList :: [ClusterSlotsResponseEntry] -> ShowS # | |
RedisResult ClusterSlotsResponseEntry Source # | |
Defined in Database.Redis.ManualCommands |
data ClusterSlotsNode Source #
Instances
Show ClusterSlotsNode Source # | |
Defined in Database.Redis.ManualCommands showsPrec :: Int -> ClusterSlotsNode -> ShowS # show :: ClusterSlotsNode -> String # showList :: [ClusterSlotsNode] -> ShowS # | |
RedisResult ClusterSlotsNode Source # | |
Defined in Database.Redis.ManualCommands |
data ClusterSlotsResponse Source #
Instances
Show ClusterSlotsResponse Source # | |
Defined in Database.Redis.ManualCommands showsPrec :: Int -> ClusterSlotsResponse -> ShowS # show :: ClusterSlotsResponse -> String # showList :: [ClusterSlotsResponse] -> ShowS # | |
RedisResult ClusterSlotsResponse Source # | |
Defined in Database.Redis.ManualCommands |
data ClusterNodesResponseSlotSpec Source #
ClusterNodesResponseSingleSlot Integer | |
ClusterNodesResponseSlotRange Integer Integer | |
ClusterNodesResponseSlotImporting Integer ByteString | |
ClusterNodesResponseSlotMigrating Integer ByteString |
Instances
data ClusterNodesResponseEntry Source #
Instances
Eq ClusterNodesResponseEntry Source # | |
Defined in Database.Redis.ManualCommands | |
Show ClusterNodesResponseEntry Source # | |
Defined in Database.Redis.ManualCommands showsPrec :: Int -> ClusterNodesResponseEntry -> ShowS # show :: ClusterNodesResponseEntry -> String # showList :: [ClusterNodesResponseEntry] -> ShowS # |
data ClusterNodesResponse Source #
Instances
Eq ClusterNodesResponse Source # | |
Defined in Database.Redis.ManualCommands (==) :: ClusterNodesResponse -> ClusterNodesResponse -> Bool # (/=) :: ClusterNodesResponse -> ClusterNodesResponse -> Bool # | |
Show ClusterNodesResponse Source # | |
Defined in Database.Redis.ManualCommands showsPrec :: Int -> ClusterNodesResponse -> ShowS # show :: ClusterNodesResponse -> String # showList :: [ClusterNodesResponse] -> ShowS # | |
RedisResult ClusterNodesResponse Source # | |
Defined in Database.Redis.ManualCommands |
data XInfoStreamResponse Source #
Instances
Eq XInfoStreamResponse Source # | |
Defined in Database.Redis.ManualCommands (==) :: XInfoStreamResponse -> XInfoStreamResponse -> Bool # (/=) :: XInfoStreamResponse -> XInfoStreamResponse -> Bool # | |
Show XInfoStreamResponse Source # | |
Defined in Database.Redis.ManualCommands showsPrec :: Int -> XInfoStreamResponse -> ShowS # show :: XInfoStreamResponse -> String # showList :: [XInfoStreamResponse] -> ShowS # | |
RedisResult XInfoStreamResponse Source # | |
Defined in Database.Redis.ManualCommands |
data XInfoGroupsResponse Source #
Instances
Eq XInfoGroupsResponse Source # | |
Defined in Database.Redis.ManualCommands (==) :: XInfoGroupsResponse -> XInfoGroupsResponse -> Bool # (/=) :: XInfoGroupsResponse -> XInfoGroupsResponse -> Bool # | |
Show XInfoGroupsResponse Source # | |
Defined in Database.Redis.ManualCommands showsPrec :: Int -> XInfoGroupsResponse -> ShowS # show :: XInfoGroupsResponse -> String # showList :: [XInfoGroupsResponse] -> ShowS # | |
RedisResult XInfoGroupsResponse Source # | |
Defined in Database.Redis.ManualCommands |
data XInfoConsumersResponse Source #
Instances
Eq XInfoConsumersResponse Source # | |
Defined in Database.Redis.ManualCommands | |
Show XInfoConsumersResponse Source # | |
Defined in Database.Redis.ManualCommands showsPrec :: Int -> XInfoConsumersResponse -> ShowS # show :: XInfoConsumersResponse -> String # showList :: [XInfoConsumersResponse] -> ShowS # | |
RedisResult XInfoConsumersResponse Source # | |
Defined in Database.Redis.ManualCommands |
data XClaimOpts Source #
XClaimOpts | |
|
Instances
Eq XClaimOpts Source # | |
Defined in Database.Redis.ManualCommands (==) :: XClaimOpts -> XClaimOpts -> Bool # (/=) :: XClaimOpts -> XClaimOpts -> Bool # | |
Show XClaimOpts Source # | |
Defined in Database.Redis.ManualCommands showsPrec :: Int -> XClaimOpts -> ShowS # show :: XClaimOpts -> String # showList :: [XClaimOpts] -> ShowS # |
data XPendingDetailRecord Source #
Instances
Eq XPendingDetailRecord Source # | |
Defined in Database.Redis.ManualCommands (==) :: XPendingDetailRecord -> XPendingDetailRecord -> Bool # (/=) :: XPendingDetailRecord -> XPendingDetailRecord -> Bool # | |
Show XPendingDetailRecord Source # | |
Defined in Database.Redis.ManualCommands showsPrec :: Int -> XPendingDetailRecord -> ShowS # show :: XPendingDetailRecord -> String # showList :: [XPendingDetailRecord] -> ShowS # | |
RedisResult XPendingDetailRecord Source # | |
Defined in Database.Redis.ManualCommands |
data XPendingSummaryResponse Source #
Instances
Eq XPendingSummaryResponse Source # | |
Defined in Database.Redis.ManualCommands | |
Show XPendingSummaryResponse Source # | |
Defined in Database.Redis.ManualCommands showsPrec :: Int -> XPendingSummaryResponse -> ShowS # show :: XPendingSummaryResponse -> String # showList :: [XPendingSummaryResponse] -> ShowS # | |
RedisResult XPendingSummaryResponse Source # | |
Defined in Database.Redis.ManualCommands |
data XReadResponse Source #
Instances
Eq XReadResponse Source # | |
Defined in Database.Redis.ManualCommands (==) :: XReadResponse -> XReadResponse -> Bool # (/=) :: XReadResponse -> XReadResponse -> Bool # | |
Show XReadResponse Source # | |
Defined in Database.Redis.ManualCommands showsPrec :: Int -> XReadResponse -> ShowS # show :: XReadResponse -> String # showList :: [XReadResponse] -> ShowS # | |
RedisResult XReadResponse Source # | |
Defined in Database.Redis.ManualCommands |
data StreamsRecord Source #
StreamsRecord | |
|
Instances
Eq StreamsRecord Source # | |
Defined in Database.Redis.ManualCommands (==) :: StreamsRecord -> StreamsRecord -> Bool # (/=) :: StreamsRecord -> StreamsRecord -> Bool # | |
Show StreamsRecord Source # | |
Defined in Database.Redis.ManualCommands showsPrec :: Int -> StreamsRecord -> ShowS # show :: StreamsRecord -> String # showList :: [StreamsRecord] -> ShowS # | |
RedisResult StreamsRecord Source # | |
Defined in Database.Redis.ManualCommands |
Instances
data MigrateOpts Source #
Options for the migrate
command.
Instances
Eq MigrateOpts Source # | |
Defined in Database.Redis.ManualCommands (==) :: MigrateOpts -> MigrateOpts -> Bool # (/=) :: MigrateOpts -> MigrateOpts -> Bool # | |
Show MigrateOpts Source # | |
Defined in Database.Redis.ManualCommands showsPrec :: Int -> MigrateOpts -> ShowS # show :: MigrateOpts -> String # showList :: [MigrateOpts] -> ShowS # |
A single entry from the slowlog.
Slowlog | |
|
:: RedisCtx m f | |
=> ByteString | key |
-> m (f Integer) |
:: RedisCtx m f | |
=> ByteString | key |
-> m (f Integer) |
:: RedisCtx m f | |
=> ByteString | key |
-> m (f ByteString) |
:: RedisCtx m f | |
=> ByteString | key |
-> ByteString | pivot |
-> ByteString | value |
-> m (f Integer) |
:: RedisCtx m f | |
=> ByteString | key |
-> ByteString | pivot |
-> ByteString | value |
-> m (f Integer) |
slowlogLen :: RedisCtx m f => m (f Integer) Source #
slowlogReset :: RedisCtx m f => m (f Status) Source #
:: RedisCtx m f | |
=> ByteString | key |
-> Integer | start |
-> Integer | stop |
-> m (f [ByteString]) |
:: RedisCtx m f | |
=> ByteString | key |
-> Integer | start |
-> Integer | stop |
-> m (f [(ByteString, Double)]) |
:: RedisCtx m f | |
=> ByteString | key |
-> Integer | start |
-> Integer | stop |
-> m (f [ByteString]) |
:: RedisCtx m f | |
=> ByteString | key |
-> Integer | start |
-> Integer | stop |
-> m (f [(ByteString, Double)]) |
:: RedisCtx m f | |
=> ByteString | key |
-> Double | min |
-> Double | max |
-> m (f [ByteString]) |
zrangebyscoreWithscores Source #
:: RedisCtx m f | |
=> ByteString | key |
-> Double | min |
-> Double | max |
-> m (f [(ByteString, Double)]) |
:: RedisCtx m f | |
=> ByteString | key |
-> Double | min |
-> Double | max |
-> Integer | offset |
-> Integer | count |
-> m (f [ByteString]) |
zrangebyscoreWithscoresLimit Source #
:: RedisCtx m f | |
=> ByteString | key |
-> Double | min |
-> Double | max |
-> Integer | offset |
-> Integer | count |
-> m (f [(ByteString, Double)]) |
:: RedisCtx m f | |
=> ByteString | key |
-> Double | max |
-> Double | min |
-> m (f [ByteString]) |
zrevrangebyscoreWithscores Source #
:: RedisCtx m f | |
=> ByteString | key |
-> Double | max |
-> Double | min |
-> m (f [(ByteString, Double)]) |
zrevrangebyscoreLimit Source #
:: RedisCtx m f | |
=> ByteString | key |
-> Double | max |
-> Double | min |
-> Integer | offset |
-> Integer | count |
-> m (f [ByteString]) |
zrevrangebyscoreWithscoresLimit Source #
:: RedisCtx m f | |
=> ByteString | key |
-> Double | max |
-> Double | min |
-> Integer | offset |
-> Integer | count |
-> m (f [(ByteString, Double)]) |
defaultSortOpts :: SortOpts Source #
Redis default SortOpts
. Equivalent to omitting all optional parameters.
SortOpts { sortBy = Nothing -- omit the BY option , sortLimit = (0,-1) -- return entire collection , sortGet = [] -- omit the GET option , sortOrder = Asc -- sort in ascending order , sortAlpha = False -- sort numerically, not lexicographically }
:: RedisCtx m f | |
=> ByteString | key |
-> ByteString | destination |
-> SortOpts | |
-> m (f Integer) |
:: RedisCtx m f | |
=> ByteString | key |
-> SortOpts | |
-> m (f [ByteString]) |
:: RedisCtx m f | |
=> ByteString | destination |
-> [ByteString] | keys |
-> Aggregate | |
-> m (f Integer) |
:: RedisCtx m f | |
=> ByteString | destination |
-> [(ByteString, Double)] | weighted keys |
-> Aggregate | |
-> m (f Integer) |
:: RedisCtx m f | |
=> ByteString | destination |
-> [ByteString] | keys |
-> Aggregate | |
-> m (f Integer) |
:: RedisCtx m f | |
=> ByteString | destination |
-> [(ByteString, Double)] | weighted keys |
-> Aggregate | |
-> m (f Integer) |
:: (RedisCtx m f, RedisResult a) | |
=> ByteString | script |
-> [ByteString] | keys |
-> [ByteString] | args |
-> m (f a) |
:: (RedisCtx m f, RedisResult a) | |
=> ByteString | base16-encoded sha1 hash of the script |
-> [ByteString] | keys |
-> [ByteString] | args |
-> m (f a) |
:: RedisCtx m f | |
=> ByteString | key |
-> Integer | start |
-> Integer | end |
-> m (f Integer) |
:: RedisCtx m f | |
=> ByteString | destkey |
-> [ByteString] | srckeys |
-> m (f Integer) |
:: RedisCtx m f | |
=> ByteString | destkey |
-> [ByteString] | srckeys |
-> m (f Integer) |
:: RedisCtx m f | |
=> ByteString | destkey |
-> [ByteString] | srckeys |
-> m (f Integer) |
:: RedisCtx m f | |
=> ByteString | destkey |
-> ByteString | srckey |
-> m (f Integer) |
:: RedisCtx m f | |
=> ByteString | host |
-> ByteString | port |
-> ByteString | key |
-> Integer | destinationDb |
-> Integer | timeout |
-> m (f Status) |
defaultMigrateOpts :: MigrateOpts Source #
Redis default MigrateOpts
. Equivalent to omitting all optional parameters.
MigrateOpts { migrateCopy = False -- remove the key from the local instance , migrateReplace = False -- don't replace existing key on the remote instance }
:: RedisCtx m f | |
=> ByteString | host |
-> ByteString | port |
-> Integer | destinationDb |
-> Integer | timeout |
-> MigrateOpts | |
-> [ByteString] | keys |
-> m (f Status) |
:: RedisCtx m f | |
=> ByteString | key |
-> Integer | timeToLive |
-> ByteString | serializedValue |
-> m (f Status) |
:: RedisCtx m f | |
=> ByteString | key |
-> Integer | timeToLive |
-> ByteString | serializedValue |
-> m (f Status) |
:: RedisCtx m f | |
=> ByteString | key |
-> ByteString | value |
-> m (f Status) |
:: RedisCtx m f | |
=> ByteString | key |
-> ByteString | value |
-> SetOpts | |
-> m (f Status) |
:: RedisCtx m f | |
=> ByteString | key |
-> [(Double, ByteString)] | scoreMember |
-> m (f Integer) |
defaultZaddOpts :: ZaddOpts Source #
Redis default ZaddOpts
. Equivalent to omitting all optional parameters.
ZaddOpts { zaddCondition = Nothing -- omit NX and XX options , zaddChange = False -- don't modify the return value from the number of new elements added, to the total number of elements changed , zaddIncrement = False -- don't add like ZINCRBY }
:: RedisCtx m f | |
=> ByteString | key |
-> [(Double, ByteString)] | scoreMember |
-> ZaddOpts | options |
-> m (f Integer) |
:: RedisCtx m f | |
=> ByteString | key |
-> m (f (Maybe ByteString)) |
:: RedisCtx m f | |
=> ByteString | key |
-> Integer | count |
-> m (f [ByteString]) |
:: RedisCtx m f | |
=> ByteString | key |
-> m (f (Maybe ByteString)) |
:: RedisCtx m f | |
=> ByteString | key |
-> Integer | count |
-> m (f [ByteString]) |
info :: RedisCtx m f => m (f ByteString) Source #
:: RedisCtx m f | |
=> ByteString | section |
-> m (f ByteString) |
defaultScanOpts :: ScanOpts Source #
Redis default ScanOpts
. Equivalent to omitting all optional parameters.
ScanOpts
{ scanMatch = Nothing -- don't match any pattern
, scanCount = Nothing -- don't set any requirements on number elements returned (works like value COUNT 10
)
}
:: RedisCtx m f | |
=> Cursor | |
-> ScanOpts | |
-> m (f (Cursor, [ByteString])) | next cursor and values |
:: RedisCtx m f | |
=> ByteString | key |
-> Cursor | |
-> m (f (Cursor, [ByteString])) | next cursor and values |
:: RedisCtx m f | |
=> ByteString | key |
-> Cursor | |
-> ScanOpts | |
-> m (f (Cursor, [ByteString])) | next cursor and values |
:: RedisCtx m f | |
=> ByteString | key |
-> Cursor | |
-> m (f (Cursor, [(ByteString, ByteString)])) | next cursor and values |
:: RedisCtx m f | |
=> ByteString | key |
-> Cursor | |
-> ScanOpts | |
-> m (f (Cursor, [(ByteString, ByteString)])) | next cursor and values |
:: RedisCtx m f | |
=> ByteString | key |
-> Cursor | |
-> m (f (Cursor, [(ByteString, Double)])) | next cursor and values |
:: RedisCtx m f | |
=> ByteString | key |
-> Cursor | |
-> ScanOpts | |
-> m (f (Cursor, [(ByteString, Double)])) | next cursor and values |
:: RedisCtx m f | |
=> ByteString | key |
-> RangeLex ByteString | min |
-> RangeLex ByteString | max |
-> m (f [ByteString]) |
:: RedisCtx m f | |
=> ByteString | key |
-> RangeLex ByteString | min |
-> RangeLex ByteString | max |
-> Integer | offset |
-> Integer | count |
-> m (f [ByteString]) |
:: RedisCtx m f | |
=> ByteString | key |
-> ByteString | id |
-> [(ByteString, ByteString)] | (field, value) |
-> TrimOpts | |
-> m (f ByteString) |
:: RedisCtx m f | |
=> ByteString | stream |
-> ByteString | id |
-> [(ByteString, ByteString)] | (field, value) |
-> m (f ByteString) |
defaultXreadOpts :: XReadOpts Source #
Redis default XReadOpts
. Equivalent to omitting all optional parameters.
XReadOpts { block = Nothing -- Don't block waiting for more records , recordCount = Nothing -- no record count }
:: RedisCtx m f | |
=> [(ByteString, ByteString)] | (stream, id) pairs |
-> XReadOpts | Options |
-> m (f (Maybe [XReadResponse])) |
:: RedisCtx m f | |
=> [(ByteString, ByteString)] | (stream, id) pairs |
-> m (f (Maybe [XReadResponse])) |
:: RedisCtx m f | |
=> ByteString | group name |
-> ByteString | consumer name |
-> [(ByteString, ByteString)] | (stream, id) pairs |
-> XReadOpts | Options |
-> m (f (Maybe [XReadResponse])) |
:: RedisCtx m f | |
=> ByteString | group name |
-> ByteString | consumer name |
-> [(ByteString, ByteString)] | (stream, id) pairs |
-> m (f (Maybe [XReadResponse])) |
:: RedisCtx m f | |
=> ByteString | stream |
-> ByteString | group name |
-> ByteString | start ID |
-> m (f Status) |
:: RedisCtx m f | |
=> ByteString | stream |
-> ByteString | group |
-> ByteString | id |
-> m (f Status) |
:: RedisCtx m f | |
=> ByteString | stream |
-> ByteString | group |
-> ByteString | consumer |
-> m (f Integer) |
:: RedisCtx m f | |
=> ByteString | stream |
-> ByteString | group |
-> m (f Bool) |
:: RedisCtx m f | |
=> ByteString | stream |
-> ByteString | group name |
-> [ByteString] | message IDs |
-> m (f Integer) |
:: RedisCtx m f | |
=> ByteString | stream |
-> ByteString | start |
-> ByteString | end |
-> Maybe Integer | COUNT |
-> m (f [StreamsRecord]) |
:: RedisCtx m f | |
=> ByteString | stream |
-> ByteString | end |
-> ByteString | start |
-> Maybe Integer | COUNT |
-> m (f [StreamsRecord]) |
:: RedisCtx m f | |
=> ByteString | stream |
-> ByteString | group |
-> Maybe ByteString | consumer |
-> m (f XPendingSummaryResponse) |
:: RedisCtx m f | |
=> ByteString | stream |
-> ByteString | group |
-> ByteString | startId |
-> ByteString | endId |
-> Integer | count |
-> Maybe ByteString | consumer |
-> m (f [XPendingDetailRecord]) |
:: RedisCtx m f | |
=> ByteString | stream |
-> ByteString | group |
-> ByteString | consumer |
-> Integer | min idle time |
-> XClaimOpts | optional arguments |
-> [ByteString] | message IDs |
-> m (f [StreamsRecord]) |
:: RedisCtx m f | |
=> ByteString | stream |
-> ByteString | group |
-> ByteString | consumer |
-> Integer | min idle time |
-> XClaimOpts | optional arguments |
-> [ByteString] | message IDs |
-> m (f [ByteString]) |
:: RedisCtx m f | |
=> ByteString | stream |
-> ByteString | group |
-> m (f [XInfoConsumersResponse]) |
:: RedisCtx m f | |
=> ByteString | stream |
-> m (f [XInfoGroupsResponse]) |
:: RedisCtx m f | |
=> ByteString | stream |
-> m (f XInfoStreamResponse) |
:: RedisCtx m f | |
=> ByteString | stream |
-> [ByteString] | message IDs |
-> m (f Integer) |
clusterNodes :: RedisCtx m f => m (f ClusterNodesResponse) Source #
clusterSlots :: RedisCtx m f => m (f ClusterSlotsResponse) Source #
clusterSetSlotImporting :: RedisCtx m f => Integer -> ByteString -> m (f Status) Source #
clusterSetSlotMigrating :: RedisCtx m f => Integer -> ByteString -> m (f Status) Source #
clusterSetSlotNode :: RedisCtx m f => Integer -> ByteString -> m (f Status) Source #
clusterGetKeysInSlot :: RedisCtx m f => Integer -> Integer -> m (f [ByteString]) Source #
:: RedisCtx m f | |
=> ByteString | key |
-> ByteString | value |
-> m (f Bool) |
commandCount :: RedisCtx m f => m (f Integer) Source #
:: RedisCtx m f | |
=> ByteString | connectionName |
-> m (f ByteString) |
:: RedisCtx m f | |
=> ByteString | key |
-> ByteString | member |
-> m (f (Maybe Integer)) |
:: RedisCtx m f | |
=> ByteString | key |
-> Double | min |
-> Double | max |
-> m (f Integer) |
:: RedisCtx m f | |
=> ByteString | key |
-> m (f [ByteString]) |
:: RedisCtx m f | |
=> ByteString | host |
-> ByteString | port |
-> m (f Status) |
:: RedisCtx m f | |
=> ByteString | key |
-> ByteString | value |
-> m (f Integer) |
:: RedisCtx m f | |
=> ByteString | key |
-> m (f ByteString) |
:: RedisCtx m f | |
=> ByteString | source |
-> ByteString | destination |
-> m (f (Maybe ByteString)) |
:: RedisCtx m f | |
=> [ByteString] | key |
-> Integer | timeout |
-> m (f (Maybe (ByteString, ByteString))) |
bgrewriteaof :: RedisCtx m f => m (f Status) Source #
:: RedisCtx m f | |
=> ByteString | key |
-> Integer | increment |
-> ByteString | member |
-> m (f Double) |
:: RedisCtx m f | |
=> ByteString | key |
-> m (f [(ByteString, ByteString)]) |
:: RedisCtx m f | |
=> ByteString | key |
-> [(ByteString, ByteString)] | fieldValue |
-> m (f Status) |
:: RedisCtx m f | |
=> [ByteString] | key |
-> m (f [ByteString]) |
:: RedisCtx m f | |
=> ByteString | key |
-> [ByteString] | value |
-> m (f Integer) |
:: RedisCtx m f | |
=> ByteString | key |
-> Integer | start |
-> Integer | stop |
-> m (f Integer) |
:: RedisCtx m f | |
=> ByteString | key |
-> [ByteString] | member |
-> m (f Integer) |
:: RedisCtx m f | |
=> ByteString | key |
-> Integer | index |
-> m (f (Maybe ByteString)) |
:: RedisCtx m f | |
=> ByteString | key |
-> [ByteString] | value |
-> m (f Integer) |
:: RedisCtx m f | |
=> ByteString | key |
-> ByteString | field |
-> m (f Integer) |
:: RedisCtx m f | |
=> ByteString | source |
-> ByteString | destination |
-> ByteString | member |
-> m (f Bool) |
:: RedisCtx m f | |
=> ByteString | key |
-> ByteString | member |
-> m (f (Maybe Double)) |
configResetstat :: RedisCtx m f => m (f Status) Source #
:: RedisCtx m f | |
=> ByteString | key |
-> [ByteString] | field |
-> m (f Integer) |
:: RedisCtx m f | |
=> ByteString | key |
-> Double | increment |
-> m (f Double) |
:: RedisCtx m f | |
=> ByteString | key |
-> Integer | offset |
-> ByteString | value |
-> m (f Integer) |
:: RedisCtx m f | |
=> ByteString | key |
-> m (f [ByteString]) |
:: RedisCtx m f | |
=> ByteString | key |
-> ByteString | min |
-> ByteString | max |
-> m (f Integer) |
:: RedisCtx m f | |
=> [ByteString] | key |
-> m (f [ByteString]) |
:: RedisCtx m f | |
=> ByteString | destination |
-> [ByteString] | key |
-> m (f Integer) |
:: RedisCtx m f | |
=> ByteString | key |
-> m (f [ByteString]) |
:: RedisCtx m f | |
=> ByteString | parameter |
-> ByteString | value |
-> m (f Status) |
scriptFlush :: RedisCtx m f => m (f Status) Source #
:: RedisCtx m f | |
=> ByteString | key |
-> m (f (Maybe ByteString)) |
:: RedisCtx m f | |
=> [ByteString] | key |
-> m (f [Maybe ByteString]) |
clientList :: RedisCtx m f => m (f [ByteString]) Source #
:: RedisCtx m f | |
=> ByteString | key |
-> ByteString | newkey |
-> m (f Bool) |
:: RedisCtx m f | |
=> ByteString | destkey |
-> [ByteString] | sourcekey |
-> m (f ByteString) |
:: RedisCtx m f | |
=> ByteString | key |
-> Integer | count |
-> ByteString | value |
-> m (f Integer) |
:: RedisCtx m f | |
=> [ByteString] | key |
-> m (f [ByteString]) |
:: RedisCtx m f | |
=> ByteString | key |
-> m (f (Maybe ByteString)) |
:: RedisCtx m f | |
=> ByteString | key |
-> Integer | start |
-> Integer | end |
-> m (f ByteString) |
:: RedisCtx m f | |
=> ByteString | destination |
-> [ByteString] | key |
-> m (f Integer) |
:: RedisCtx m f | |
=> ByteString | script |
-> m (f ByteString) |
:: RedisCtx m f | |
=> ByteString | key |
-> ByteString | value |
-> m (f (Maybe ByteString)) |
:: RedisCtx m f | |
=> ByteString | key |
-> m (f ByteString) |
:: RedisCtx m f | |
=> ByteString | pattern |
-> m (f [ByteString]) |
:: RedisCtx m f | |
=> ByteString | parameter |
-> m (f [(ByteString, ByteString)]) |
:: RedisCtx m f | |
=> ByteString | key |
-> [ByteString] | value |
-> m (f Integer) |
:: RedisCtx m f | |
=> ByteString | key |
-> ByteString | field |
-> ByteString | value |
-> m (f Bool) |
:: RedisCtx m f | |
=> [(ByteString, ByteString)] | keyValue |
-> m (f Status) |
:: RedisCtx m f | |
=> ByteString | key |
-> Integer | seconds |
-> ByteString | value |
-> m (f Status) |
:: RedisCtx m f | |
=> ByteString | key |
-> Integer | milliseconds |
-> ByteString | value |
-> m (f Status) |
:: RedisCtx m f | |
=> [ByteString] | script |
-> m (f [Bool]) |
:: RedisCtx m f | |
=> ByteString | destination |
-> [ByteString] | key |
-> m (f Integer) |
:: RedisCtx m f | |
=> ByteString | key |
-> ByteString | value |
-> m (f Integer) |
:: RedisCtx m f | |
=> ByteString | key |
-> ByteString | field |
-> ByteString | value |
-> m (f Integer) |
:: RedisCtx m f | |
=> ByteString | source |
-> ByteString | destination |
-> Integer | timeout |
-> m (f (Maybe ByteString)) |
:: RedisCtx m f | |
=> ByteString | key |
-> ByteString | member |
-> m (f (Maybe Integer)) |
scriptKill :: RedisCtx m f => m (f Status) Source #
:: RedisCtx m f | |
=> ByteString | key |
-> Integer | offset |
-> ByteString | value |
-> m (f Integer) |
:: RedisCtx m f | |
=> ByteString | key |
-> ByteString | field |
-> Double | increment |
-> m (f Double) |
:: RedisCtx m f | |
=> ByteString | key |
-> ByteString | field |
-> Integer | increment |
-> m (f Integer) |
:: RedisCtx m f | |
=> ByteString | key |
-> ByteString | min |
-> ByteString | max |
-> m (f Integer) |
:: RedisCtx m f | |
=> ByteString | key |
-> m (f (Maybe ByteString)) |
:: RedisCtx m f | |
=> ByteString | key |
-> ByteString | newkey |
-> m (f Status) |
:: RedisCtx m f | |
=> ByteString | key |
-> [ByteString] | member |
-> m (f Integer) |
:: RedisCtx m f | |
=> ByteString | key |
-> ByteString | field |
-> m (f Bool) |
clientGetname :: RedisCtx m f => m (f Status) Source #
configRewrite :: RedisCtx m f => m (f Status) Source #
:: RedisCtx m f | |
=> ByteString | key |
-> [ByteString] | field |
-> m (f [Maybe ByteString]) |
:: RedisCtx m f | |
=> ByteString | key |
-> Integer | start |
-> Integer | stop |
-> m (f [ByteString]) |
:: RedisCtx m f | |
=> ByteString | key |
-> ByteString | value |
-> m (f Integer) |
:: RedisCtx m f | |
=> ByteString | key |
-> ByteString | field |
-> m (f (Maybe ByteString)) |
:: RedisCtx m f | |
=> ByteString | key |
-> Integer | index |
-> ByteString | value |
-> m (f Status) |
:: RedisCtx m f | |
=> [(ByteString, ByteString)] | keyValue |
-> m (f Bool) |
:: RedisCtx m f | |
=> [ByteString] | commandName |
-> m (f [ByteString]) |
:: RedisCtx m f | |
=> [ByteString] | key |
-> Integer | timeout |
-> m (f (Maybe (ByteString, ByteString))) |
:: RedisCtx m f | |
=> ByteString | key |
-> [ByteString] | member |
-> m (f Integer) |
:: RedisCtx m f | |
=> ByteString | message |
-> m (f ByteString) |
:: RedisCtx m f | |
=> ByteString | key |
-> ByteString | member |
-> m (f Bool) |
data ConnectError Source #
Instances
Eq ConnectError Source # | |
Defined in Database.Redis.Connection (==) :: ConnectError -> ConnectError -> Bool # (/=) :: ConnectError -> ConnectError -> Bool # | |
Show ConnectError Source # | |
Defined in Database.Redis.Connection showsPrec :: Int -> ConnectError -> ShowS # show :: ConnectError -> String # showList :: [ConnectError] -> ShowS # | |
Exception ConnectError Source # | |
Defined in Database.Redis.Connection |
data ConnectInfo Source #
Information for connnecting to a Redis server.
It is recommended to not use the ConnInfo
data constructor directly.
Instead use defaultConnectInfo
and update it with record syntax. For
example to connect to a password protected Redis server running on localhost
and listening to the default port:
myConnectInfo :: ConnectInfo myConnectInfo = defaultConnectInfo {connectAuth = Just "secret"}
ConnInfo | |
|
Instances
Show ConnectInfo Source # | |
Defined in Database.Redis.Connection showsPrec :: Int -> ConnectInfo -> ShowS # show :: ConnectInfo -> String # showList :: [ConnectInfo] -> ShowS # |
defaultConnectInfo :: ConnectInfo Source #
Default information for connecting:
connectHost = "localhost" connectPort = PortNumber 6379 -- Redis default port connectAuth = Nothing -- No password connectDatabase = 0 -- SELECT database 0 connectMaxConnections = 50 -- Up to 50 connections connectMaxIdleTime = 30 -- Keep open for 30 seconds connectTimeout = Nothing -- Don't add timeout logic connectTLSParams = Nothing -- Do not use TLS
checkedConnect :: ConnectInfo -> IO Connection Source #
Constructs a Connection
pool to a Redis server designated by the
given ConnectInfo
, then tests if the server is actually there.
Throws an exception if the connection to the Redis server can't be
established.
disconnect :: Connection -> IO () Source #
Destroy all idle resources in the pool.
withConnect :: (MonadMask m, MonadIO m) => ConnectInfo -> (Connection -> m c) -> m c Source #
Memory bracket around connect
and disconnect
.
withCheckedConnect :: ConnectInfo -> (Connection -> IO c) -> IO c Source #
Memory bracket around checkedConnect
and disconnect
connectCluster :: ConnectInfo -> IO Connection Source #
Constructs a ShardMap
of connections to clustered nodes. The argument is
a ConnectInfo
for any node in the cluster
Some Redis commands are currently not supported in cluster mode - CONFIG, AUTH - SCAN - MOVE, SELECT - PUBLISH, SUBSCRIBE, PSUBSCRIBE, UNSUBSCRIBE, PUNSUBSCRIBE, RESET
data PubSubController Source #
A controller that stores a set of channels, pattern channels, and callbacks.
It allows you to manage Pub/Sub subscriptions and pattern subscriptions and alter them at
any time throughout the life of your program.
You should typically create the controller at the start of your program and then store it
through the life of your program, using addChannels
and removeChannels
to update the
current subscriptions.
type UnregisterCallbacksAction = IO () Source #
An action that when executed will unregister the callbacks. It is returned from addChannels
or addChannelsAndWait
and typically you would use it in bracket
to guarantee that you
unsubscribe from channels. For example, if you are using websockets to distribute messages to
clients, you could use something such as:
websocketConn <- Network.WebSockets.acceptRequest pending let mycallback msg = Network.WebSockets.sendTextData websocketConn msg bracket (addChannelsAndWait ctrl [("hello", mycallback)] []) id $ const $ do {- loop here calling Network.WebSockets.receiveData -}
type PMessageCallback = RedisChannel -> ByteString -> IO () Source #
A handler for a message from a psubscribed channel. The callback is passed the channel the message was sent on plus the message content.
Similar to MessageCallback
, callbacks are executed synchronously and any exceptions
are rethrown from pubSubForever
.
type MessageCallback = ByteString -> IO () Source #
A handler for a message from a subscribed channel. The callback is passed the message content.
Messages are processed synchronously in the receiving thread, so if the callback
takes a long time it will block other callbacks and other messages from being
received. If you need to move long-running work to a different thread, we suggest
you use TBQueue
with a reasonable bound, so that if messages are arriving faster
than you can process them, you do eventually block.
If the callback throws an exception, the exception will be thrown from pubSubForever
which will cause the entire Redis connection for all subscriptions to be closed.
As long as you call pubSubForever
in a loop you will reconnect to your subscribed
channels, but you should probably add an exception handler to each callback to
prevent this.
type RedisPChannel = ByteString Source #
A Redis pattern channel name
type RedisChannel = ByteString Source #
A Redis channel name
Encapsulates subscription changes. Use subscribe
, unsubscribe
,
psubscribe
, punsubscribe
or mempty
to construct a value. Combine
values by using the Monoid
interface, i.e. mappend
and mconcat
.
:: RedisCtx m f | |
=> ByteString | channel |
-> ByteString | message |
-> m (f Integer) |
Post a message to a channel (http://redis.io/commands/publish).
:: [ByteString] | channel |
-> PubSub |
Listen for messages published to the given channels (http://redis.io/commands/subscribe).
:: [ByteString] | channel |
-> PubSub |
Stop listening for messages posted to the given channels (http://redis.io/commands/unsubscribe).
:: [ByteString] | pattern |
-> PubSub |
Listen for messages published to channels matching the given patterns (http://redis.io/commands/psubscribe).
:: [ByteString] | pattern |
-> PubSub |
Stop listening for messages posted to channels matching the given patterns (http://redis.io/commands/punsubscribe).
Listens to published messages on subscribed channels and channels matching the subscribed patterns. For documentation on the semantics of Redis Pub/Sub see http://redis.io/topics/pubsub.
The given callback function is called for each received message.
Subscription changes are triggered by the returned PubSub
. To keep
subscriptions unchanged, the callback can return mempty
.
Example: Subscribe to the "news" channel indefinitely.
pubSub (subscribe ["news"]) $ \msg -> do putStrLn $ "Message from " ++ show (msgChannel msg) return mempty
Example: Receive a single message from the "chat" channel.
pubSub (subscribe ["chat"]) $ \msg -> do putStrLn $ "Message from " ++ show (msgChannel msg) return $ unsubscribe ["chat"]
It should be noted that Redis Pub/Sub by its nature is asynchronous
so returning unsubscribe
does not mean that callback won't be able
to receive any further messages. And to guarantee that you won't
won't process messages after unsubscription and won't unsubscribe
from the same channel more than once you need to use IORef
or
something similar
:: MonadIO m | |
=> [(RedisChannel, MessageCallback)] | the initial subscriptions |
-> [(RedisPChannel, PMessageCallback)] | the initial pattern subscriptions |
-> m PubSubController |
Create a new PubSubController
. Note that this does not subscribe to any channels, it just
creates the controller. The subscriptions will happen once pubSubForever
is called.
currentChannels :: MonadIO m => PubSubController -> m [RedisChannel] Source #
Get the list of current channels in the PubSubController
. WARNING! This might not
exactly reflect the subscribed channels in the Redis server, because there is a delay
between adding or removing a channel in the PubSubController
and when Redis receives
and processes the subscription change request.
currentPChannels :: MonadIO m => PubSubController -> m [RedisPChannel] Source #
Get the list of current pattern channels in the PubSubController
. WARNING! This might not
exactly reflect the subscribed channels in the Redis server, because there is a delay
between adding or removing a channel in the PubSubController
and when Redis receives
and processes the subscription change request.
:: MonadIO m | |
=> PubSubController | |
-> [(RedisChannel, MessageCallback)] | the channels to subscribe to |
-> [(RedisPChannel, PMessageCallback)] | the channels to pattern subscribe to |
-> m UnregisterCallbacksAction |
Add channels into the PubSubController
, and if there is an active pubSubForever
, send the subscribe
and psubscribe commands to Redis. The addChannels
function is thread-safe. This function
does not wait for Redis to acknowledge that the channels have actually been subscribed; use
addChannelsAndWait
for that.
You can subscribe to the same channel or pattern channel multiple times; the PubSubController
keeps
a list of callbacks and executes each callback in response to a message.
The return value is an action UnregisterCallbacksAction
which will unregister the callbacks,
which should typically used with bracket
.
:: MonadIO m | |
=> PubSubController | |
-> [(RedisChannel, MessageCallback)] | the channels to subscribe to |
-> [(RedisPChannel, PMessageCallback)] | the channels to psubscribe to |
-> m UnregisterCallbacksAction |
Call addChannels
and then wait for Redis to acknowledge that the channels are actually subscribed.
Note that this function waits for all pending subscription change requests, so if you for example call
addChannelsAndWait
from multiple threads simultaneously, they all will wait for all pending
subscription changes to be acknowledged by Redis (this is due to the fact that we just track the total
number of pending change requests sent to Redis and just wait until that count reaches zero).
This also correctly waits if the network connection dies during the subscription change. Say that the
network connection dies right after we send a subscription change to Redis. pubSubForever
will throw
ConnectionLost
and addChannelsAndWait
will continue to wait. Once you recall pubSubForever
with the same PubSubController
, pubSubForever
will open a new connection, send subscription commands
for all channels in the PubSubController
(which include the ones we are waiting for),
and wait for the responses from Redis. Only once we receive the response from Redis that it has subscribed
to all channels in PubSubController
will addChannelsAndWait
unblock and return.
removeChannels :: MonadIO m => PubSubController -> [RedisChannel] -> [RedisPChannel] -> m () Source #
Remove channels from the PubSubController
, and if there is an active pubSubForever
, send the
unsubscribe commands to Redis. Note that as soon as this function returns, no more callbacks will be
executed even if more messages arrive during the period when we request to unsubscribe from the channel
and Redis actually processes the unsubscribe request. This function is thread-safe.
If you remove all channels, the connection in pubSubForever
to redis will stay open and waiting for
any new channels from a call to addChannels
. If you really want to close the connection,
use killThread
or cancel
to kill the thread running
pubSubForever
.
removeChannelsAndWait :: MonadIO m => PubSubController -> [RedisChannel] -> [RedisPChannel] -> m () Source #
Call removeChannels
and then wait for all pending subscription change requests to be acknowledged
by Redis. This uses the same waiting logic as addChannelsAndWait
. Since removeChannels
immediately
notifies the PubSubController
to start discarding messages, you likely don't need this function and
can just use removeChannels
.
:: Connection | The connection pool |
-> PubSubController | The controller which keeps track of all subscriptions and handlers |
-> IO () | This action is executed once Redis acknowledges that all the subscriptions in
the controller are now subscribed. You can use this after an exception (such as
|
-> IO () |
Open a connection to the Redis server, register to all channels in the PubSubController
,
and process messages and subscription change requests forever. The only way this will ever
exit is if there is an exception from the network code or an unhandled exception
in a MessageCallback
or PMessageCallback
. For example, if the network connection to Redis
dies, pubSubForever
will throw a ConnectionLost
. When such an exception is
thrown, you can recall pubSubForever
with the same PubSubController
which will open a
new connection and resubscribe to all the channels which are tracked in the PubSubController
.
The general pattern is therefore during program startup create a PubSubController
and fork
a thread which calls pubSubForever
in a loop (using an exponential backoff algorithm
such as the retry package to not hammer the Redis
server if it does die). For example,
myhandler :: ByteString -> IO () myhandler msg = putStrLn $ unpack $ decodeUtf8 msg onInitialComplete :: IO () onInitialComplete = putStrLn "Redis acknowledged that mychannel is now subscribed" main :: IO () main = do conn <- connect defaultConnectInfo pubSubCtrl <- newPubSubController [("mychannel", myhandler)] [] forkIO $ forever $ pubSubForever conn pubSubCtrl onInitialComplete `catch` (\(e :: SomeException) -> do putStrLn $ "Got error: " ++ show e threadDelay $ 50*1000) -- TODO: use exponential backoff {- elsewhere in your program, use pubSubCtrl to change subscriptions -}
At most one active pubSubForever
can be running against a single PubSubController
at any time. If
two active calls to pubSubForever
share a single PubSubController
there will be deadlocks. If
you do want to process messages using multiple connections to Redis, you can create more than one
PubSubController
. For example, create one PubSubController for each getNumCapabilities
and then create a Haskell thread bound to each capability each calling pubSubForever
in a loop.
This will create one network connection per controller/capability and allow you to
register separate channels and callbacks for each controller, spreading the load across the capabilities.
parseConnectInfo :: String -> Either String ConnectInfo Source #
Parse a
from a URLConnectInfo
Username is ignored, path is used to specify the database:
>>>
parseConnectInfo "redis://username:password@host:42/2"
Right (ConnInfo {connectHost = "host", connectPort = PortNumber 42, connectAuth = Just "password", connectDatabase = 2, connectMaxConnections = 50, connectMaxIdleTime = 30s, connectTimeout = Nothing, connectTLSParams = Nothing})
>>>
parseConnectInfo "redis://username:password@host:42/db"
Left "Invalid port: db"
The scheme is validated, to prevent mixing up configurations:
>>>
parseConnectInfo "postgres://"
Left "Wrong scheme"
Beyond that, all values are optional. Omitted values are taken from
:defaultConnectInfo
>>>
parseConnectInfo "redis://"
Right (ConnInfo {connectHost = "localhost", connectPort = PortNumber 6379, connectAuth = Nothing, connectDatabase = 0, connectMaxConnections = 50, connectMaxIdleTime = 30s, connectTimeout = Nothing, connectTLSParams = Nothing})