summaryrefslogtreecommitdiff
path: root/fig-frontend/src/Fig/Frontend/DB.hs
blob: d0641de1cf0db33b6262966ac6e37d6af0514356 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
module Fig.Frontend.DB where

import Control.Error.Util (hush)

import qualified Database.Redis as Redis

import Fig.Prelude

connect :: MonadIO m => m Redis.Connection
connect = liftIO $ Redis.checkedConnect Redis.defaultConnectInfo
  { Redis.connectHost = "shiro"
  }

get :: MonadIO m => Redis.Connection -> ByteString -> m (Maybe ByteString)
get c key = liftIO $ Redis.runRedis c do
  v <- Redis.get key
  pure . join $ hush v

hget :: MonadIO m => Redis.Connection -> ByteString -> ByteString -> m (Maybe ByteString)
hget c key hkey = liftIO $ Redis.runRedis c do
  v <- Redis.hget key hkey
  pure . join $ hush v

hvals :: MonadIO m => Redis.Connection -> ByteString -> m (Maybe [ByteString])
hvals c key = liftIO $ Redis.runRedis c do
  hush <$> Redis.hvals key