Skip to content

Commit

Permalink
SharedKernal/feat: #72 Exposing Redis Eval Function
Browse files Browse the repository at this point in the history
  • Loading branch information
manvir singh authored and manvir singh committed Apr 11, 2023
1 parent 09e1119 commit 690b8ab
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion lib/mobility-core/src/Kernel/Storage/Hedis/Queries.hs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import qualified Data.ByteString as BS
import qualified Data.ByteString.Lazy as BSL
import Data.String.Conversions
import qualified Data.Text as Text
import Database.Redis (Queued, Redis, RedisTx, Reply, TxResult (..))
import Database.Redis (Queued, Redis, RedisTx, Reply, TxResult (..),RedisResult)
import qualified Database.Redis as Hedis
import GHC.Records.Extra
import Kernel.Prelude
Expand Down Expand Up @@ -202,6 +202,11 @@ delByPattern ptrn = do
runWithPrefix_ ptrn $ \prefKey ->
Hedis.eval @_ @_ @Reply "for i, name in ipairs(redis.call('KEYS', ARGV[1])) do redis.call('DEL', name); end" ["0"] [prefKey]

eval ::(RedisResult a, HedisFlow m env) => Text -> [Text] -> [Text] -> m a
eval script keys args = do
nKeys <- mapM buildKey keys
runHedis $ Hedis.eval (cs script) nKeys (map cs args)

tryLockRedis :: HedisFlow m env => Text -> ExpirationTime -> m Bool
tryLockRedis key timeout = setNxExpire (buildLockResourceName key) timeout ()

Expand Down

0 comments on commit 690b8ab

Please sign in to comment.