module HLRDB.Structures.Set where
import Data.Hashable
import Data.HashSet as S
import Database.Redis as Redis
import HLRDB.Primitives.Redis
import HLRDB.Internal
smembers :: (MonadRedis m , Eq b , Hashable b) => RedisSet a b -> a -> m (HashSet b)
smembers p@(RSet (E _ _ d)) =
fmap (S.fromList . fmap (d . pure))
. unwrap
. Redis.smembers
. primKey p
sismember :: MonadRedis m => RedisSet a b -> a -> b -> m Bool
sismember p@(RSet (E _ e _)) k =
unwrap
. Redis.sismember (primKey p k)
. runIdentity
. e
sadd :: (MonadRedis m , Traversable t) => RedisSet a b -> a -> t b -> m ()
sadd p@(RSet (E _ e _)) k =
fixEmpty (ignore . unwrap . Redis.sadd (primKey p k)) (runIdentity . e)
srem :: (MonadRedis m , Traversable t) => RedisSet a b -> a -> t b -> m ()
srem p@(RSet (E _ e _)) k =
fixEmpty (ignore . unwrap . Redis.srem (primKey p k)) (runIdentity . e)
scard :: MonadRedis m => RedisSet a b -> a -> m Integer
scard p =
unwrap
. Redis.scard
. primKey p
srandmember :: MonadRedis m => RedisSet a b -> a -> m (Maybe b)
srandmember p@(RSet (E _ _ d)) =
(fmap . fmap) (d . pure)
. unwrap
. Redis.srandmember
. primKey p
srandmemberN :: MonadRedis m => RedisSet a b -> Integer -> a -> m [ b ]
srandmemberN p@(RSet (E _ _ d)) n =
(fmap . fmap) (d . pure)
. unwrap
. flip Redis.srandmemberN n
. primKey p
sscan :: MonadRedis m => RedisSet a b -> a -> Cursor -> m (Maybe Cursor , [ b ])
sscan p@(RSet (E _ _ d)) k =
unwrapCursor (fmap (d . pure))
. Redis.sscan (primKey p k)