Skip to content

Commit

Permalink
Implement mapKeys
Browse files Browse the repository at this point in the history
  • Loading branch information
omnibs committed May 22, 2024
1 parent 95dc076 commit cc6a51e
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion nri-redis/src/Redis/Script.hs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

module Redis.Script (Script (..), script, evalString, mapKeys, keysTouchedByScript, paramNames, paramValues, parser, Tokens (..), ScriptParam (..), printScript) where

import qualified Control.Monad
import Data.Either (Either (..))
import Data.Void (Void)
import qualified GHC.TypeLits
Expand Down Expand Up @@ -166,7 +167,18 @@ evalString = Debug.todo "evalString"

-- | Map the keys in the script to the keys in the Redis API
mapKeys :: (Text -> Task err Text) -> Script a -> Task err (Script a)
mapKeys _fn _script = Debug.todo "mapKeys"
mapKeys fn script' = do
newParams <-
script'
|> params
|> Log.unSecret
|> Control.Monad.mapM
( \param ->
case kind param of
RedisKey -> fn (value param) |> Task.map (\newValue -> param {value = newValue})
ArbitraryValue -> pure param
)
pure <| script' {params = Log.mkSecret newParams}

-- | Get the keys touched by the script
keysTouchedByScript :: Script a -> Set.Set Text
Expand Down

0 comments on commit cc6a51e

Please sign in to comment.