{-# LANGUAGE OverloadedStrings #-}

module Server.Logic.Redis
( encodeRedisKey
, runRedis
) where

import Server.Core
import qualified Data.Text as T
import qualified Database.Redis as Redis

encodeRedisKey :: [(T.Text, T.Text)] -> T.Text
encodeRedisKey :: [(Text, Text)] -> Text
encodeRedisKey = [Text] -> Text
T.concat ([Text] -> Text)
-> ([(Text, Text)] -> [Text]) -> [(Text, Text)] -> Text
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ((Text, Text) -> Text) -> [(Text, Text)] -> [Text]
forall a b. (a -> b) -> [a] -> [b]
map (Text, Text) -> Text
encodeIdentifier where
    encodeIdentifier :: (T.Text, T.Text) -> T.Text
    encodeIdentifier :: (Text, Text) -> Text
encodeIdentifier (Text
key, Text
value) = [Text] -> Text
T.concat [ Text
"[", Text
key, Text
"=\"", HasCallStack => Text -> Text -> Text -> Text
Text -> Text -> Text -> Text
T.replace Text
"\"" Text
"\"\"" Text
value, Text
"\"]" ]

runRedis :: ServerConfiguration -> ServerResources -> Redis.Redis a -> IO a
runRedis :: forall a. ServerConfiguration -> ServerResources -> Redis a -> IO a
runRedis ServerConfiguration
serverConfiguration ServerResources
serverResources Redis a
redis = do
    let conn :: Connection
conn = ServerResources -> Connection
serverResourcesRedisConnection ServerResources
serverResources
    Connection -> Redis a -> IO a
forall a. Connection -> Redis a -> IO a
Redis.runRedis Connection
conn Redis a
redis