Remove and get the first element in a list (http://redis.io/commands/lpop).
The reply will consist of up to count elements, depending on the list's length.
Since Redis 1.0.0
O(1)
Adds all the elements arguments to the HyperLogLog data structure stored at the variable name specified as first argument (http://redis.io/commands/pfadd).
Since Redis 2.8.9
Set the value and expiration in milliseconds of a key (http://redis.io/commands/psetex).
Condidered deprecated since it can be replaced by SET with the PX argument when migrating or writing new code
Since Redis 2.6.0
Remove and get the last element in a list (http://redis.io/commands/rpop).
The reply will consist of up to count elements, depending on the list's length.
Result will have no more than N arguments.
Remove the last element in a list, prepend it to another list and return that
element f it existed (http://redis.io/commands/rpoplpush).
Since Redis 1.2.0
Set the value and expiration of a key (http://redis.io/commands/setex).
Regarded as deprected since 2.6 as it can be replaced by SET with the EX argument when
migrating or writing new code.
Since Redis 2.0.0
Make the server a slave of another instance, or promote it as master (http://redis.io/commands/slaveof).
Deprecated in Redis, can be replaced by replicaif since redis 5.0
Since Redis 1.0.0
Move an element after taking it from one list and pushing it to another, or blocks until one is available (https://redis.io/commands/blmove).
In clustered environments source and destination keys must be in the same hash slot, which can be ensured by using hash tags (e.g. {tag}source and {tag}destination).
Removes and returns member-score pairs from the first non-empty sorted set from a list of keys, or blocks until one is available (https://redis.io/commands/bzmpop).
O(K) + O(Mlog(N)) where K is the number of provided keys, N is the number of elements in the sorted set, and M is the number of elements popped.
In clustered environment, commands must operate on keys within the same hash slot.
Removes and returns member-score pairs from the first non-empty sorted set from a list of keys, or blocks until one is available (https://redis.io/commands/bzmpop).
O(K) + O(Mlog(N)) where K is the number of provided keys, N is the number of elements in the sorted set, and M is the number of elements popped.
In clustered environment, commands must operate on keys within the same hash slot.
The CLIENT NO-TOUCH command controls whether commands sent by the client will alter the LRULFU of the keys they access (<https:redis.iocommands/client-notouch>).
When turned on, the current client will not change LFU/LRU stats, unless it sends the TOUCH command.
When turned off, the client touches LFU/LRU stats just as a normal client.
The CLIENT SETINFO command assigns various info attributes to the current connection which are displayed in the output of CLIENT LIST and CLIENT INFO (https://redis.io/commands/client-setinfo).
Execute this subcommand on the destination master. It accepts multiple slot ranges and returns a task ID that can later be used to monitor the migration.
Redis default ScanOpts. Equivalent to omitting all optional parameters.
ScanOpts
{ scanMatch = Nothing -- don't match any pattern
, scanCount = Nothing -- don't set any requirements on number elements returned (works like value COUNT 10)
}
Redis default ZaddOpts. Equivalent to omitting all optional parameters.
ZaddOpts
{ zaddCondition = Nothing -- omit NX and XX options
, zaddChange = False -- don't modify the return value from the number of new elements added, to the total number of elements changed
, zaddIncrement = False -- don't add like ZINCRBY
, zaddSizeCondition = Nothing -- omit GT and LT options
}
The DELEX command supports a set of options that modify its behavior.
Only one option can be specified:
IFEQ removes the key if the value is equal to the specified value.
IFNE removes the key if the value is not equal to the specified value.
IFDEQ removes the key if its hash digest is equal to the specified hash digest.
IFDNE removes the key if its hash digest is not equal to the specified hash digest.
Works like eval, but sends the SHA1 hash of the script instead of the script itself.
Fails if the server does not recognise the hash, in which case, eval should be used instead.
O(N+log(M)) where N is the number of elements in the grid-aligned bounding box area around the shape provided as the filter and M is the number of items inside the shape
Queries a geospatial index for members inside an area of a box or a circle, optionally stores the result (https://redis.io/commands/geosearchstore). Since Redis 6.2.0
Set an expiration (TTL or time to live) on one or more fields of a given hash key. You must specify at least one field. Field(s) will automatically be deleted from the hash key when their TTLs expire.
Field expirations will only be cleared by commands that delete or overwrite the contents of the hash fields, including HDEL and HSET commands. This means that all the operations that conceptually alter the value stored at a hash key's field without replacing it with a new one will leave the TTL untouched.
You can clear the TTL using the hpersist command, which turns the hash field back into a persistent field.
Note that calling hexpirehpexpire with a zero TTL or hexpireathpexpireat with a time in the past will result in the hash field being deleted.
If the provided count argument is positive, return an array of distinct fields. The array's length is either count or the hash's number of fields (HLEN), whichever is lower.
If called with a negative count, the behavior changes and the command is allowed to return the same field multiple times. In this case, the number of returned fields is the absolute value of the specified count.
If the provided count argument is positive, return an array of distinct fields. The array's length is either count or the hash's number of fields (HLEN), whichever is lower.
If called with a negative count, the behavior changes and the command is allowed to return the same field multiple times. In this case, the number of returned fields is the absolute value of the specified count.
LBOUND and UBOUND constrain the result.
SATURATE clips out-of-bounds values instead of rejecting the increment.
EXPXEXATPXATPERSIST control the key expiration.
ENX only sets the expiration when the key currently has no TTL.
In clustered environments source and destination keys must be in the same hash slot, which can be ensured by using hash tags (e.g. {tag}source and {tag}destination).
O(1)
O(N) where N is the number of elements in the list, for the average case. When searching for elements near the head or the tail of the list, or when the MAXLEN option is provided, the command may run in constant time.
O(N) where N is the number of elements in the list, for the average case. When searching for elements near the head or the tail of the list, or when the MAXLEN option is provided, the command may run in constant time.
O(N) where N is the number of elements in the list, for the average case. When searching for elements near the head or the tail of the list, or when the MAXLEN option is provided, the command may run in constant time.
O(N) where N is the number of elements in the list, for the average case. When searching for elements near the head or the tail of the list, or when the MAXLEN option is provided, the command may run in constant time.
The MSETEX command supports a set of options that modify its behavior:
NX sets the keys and their expiration time only if none of the specified keys exist.
XX sets the keys and their expiration time only if all of the specified keys already exist.
EXPXEXAT/PXAT set the shared expiration for the specified keys.
KEEPTTL retains the time to live associated with the keys.
Remove and return one or multiple random members from a set (http://redis.io/commands/spop). The Redis command SPOP is split up into spop, spopN. Since Redis 1.0.0
Remove and return one or multiple random members from a set (http://redis.io/commands/spop). The Redis command SPOP is split up into spop, spopN. Since Redis 1.0.0
`REDUCE dim` reduces the dimensionality of the vector using random projection.
CAS performs the slow neighbor candidate collection in the background.
NOQUANT, Q8, and BIN control quantization and are mutually exclusive.
EF sets the build exploration factor.
SETATTR associates attributes with the entry.
M sets the maximum number of graph links per node.
O(log(K)+M) where K is the number of elements in the start prefix, and M is the number of elements returned. In practical terms, the command is just O(M).
O(log(K)+M) where K is the number of elements in the start prefix, and M is the number of elements returned. In practical terms, the command is just O(M).
COUNT limits the number of returned results.
EPSILON filters out elements that are too far from the query vector.
EF controls the exploration factor.
FILTER applies a filtering expression and `FILTER-EF` limits filtering effort.
TRUTH forces an exact linear scan.
NOTHREAD executes the search in the main thread.
O(1) Transfers ownership of pending stream entries that match
the specified criteria. The message should be pending for more than <min-idle-time>
milliseconds and ID should be greater than <start>.
XAUTOCLAIM <stream name> <consumer group name> <min idle time> <start>
This version of function claims no more than 100 mesages, use xautoclaimOpt to
override this behavior.
O(1) Transfers ownership of pending stream entries that match
the specified criteria. See xautoclaim for more details about criteria.
This variant returns only id of the messages without data. This method
claims no more than 100 messages, see xautoclaimJustIdsOpts for changing
this default.
O(1) if count is small Transfers ownership of pending stream entries that match
the specified criteria. See xautoclaim for more details about criteria.
This variant returns only id of the messages without data and allows to set the maximum
number of messages to be claimed.
Add one or more members to a sorted set, or update its score if it already exists (http://redis.io/commands/zadd). The Redis command ZADD is split up into zadd, zaddOpts. Since Redis 1.2.0
O(L + (N - K)log(N)) worst case where $L$ is the total number of elements in all the sorted sets, N is the size of the first sorted set, and K is the size of the result set.
In clustered environment, commands must operate on keys within the same hash slot.
O(L + (N - K)log(N)) worst case where $L$ is the total number of elements in all the sorted sets, N is the size of the first sorted set, and K is the size of the result set.
In clustered environment, commands must operate on keys within the same hash slot.
O(L + (N - K)log(N)) worst case where $L$ is the total number of elements in all the sorted sets, N is the size of the first sorted set, and K is the size of the result set.
In clustered environment, commands must operate on keys within the same hash slot.
Keys that do not exist are considered to be empty sets.
O(NK) + O(Mlog(M)) worst case with N being the smallest input sorted set, K being the number of input sorted sets and M being the number of elements in the resulting sorted set.
In clustered environment, commands must operate on keys within the same hash slot.
O(NK) + O(Mlog(M)) worst case with N being the smallest input sorted set, K being the number of input sorted sets and M being the number of elements in the resulting sorted set.
In clustered environment, commands must operate on keys within the same hash slot.
O(NK) + O(Mlog(M)) worst case with N being the smallest input sorted set, K being the number of input sorted sets and M being the number of elements in the resulting sorted set.
In clustered environment, commands must operate on keys within the same hash slot.
O(NK) + O(Mlog(M)) worst case with N being the smallest input sorted set, K being the number of input sorted sets and M being the number of elements in the resulting sorted set.
In clustered environment, commands must operate on keys within the same hash slot.
The reply shape depends on the path syntax, so this wrapper returns the raw Reply.
O(N) when path is evaluated to a single value where N is the size of the array, O(N) when path is evaluated to multiple values, where N is the size of the key
The reply shape depends on the path syntax, so this wrapper returns the raw Reply.
O(N) when path is evaluated to a single value where N is the size of the array, O(N) when path is evaluated to multiple values, where N is the size of the key
The reply shape depends on the path syntax, so this wrapper returns the raw Reply.
O(N) when path is evaluated to a single value where N is the size of the array, O(N) when path is evaluated to multiple values, where N is the size of the key
The reply shape depends on the path syntax, so this wrapper returns the raw Reply.
O(N) when path is evaluated to a single value where N is the size of the array, O(N) when path is evaluated to multiple values, where N is the size of the key
O(N) when path is evaluated to a single value where N is the size of the values, O(N) when path is evaluated to multiple values, where N is the size of the key
O(N) when path is evaluated to a single value where N is the size of the values, O(N) when path is evaluated to multiple values, where N is the size of the key
The reply shape depends on the path syntax, so this wrapper returns the raw Reply.
O(N) when path is evaluated to a single value, where N is the size of the value, O(N) when path is evaluated to multiple values, where N is the size of the key
The reply shape depends on the path syntax, so this wrapper returns the raw Reply.
O(N) when path is evaluated to a single value, where N is the size of the value, O(N) when path is evaluated to multiple values, where N is the size of the key
O(N) when path is evaluated to a single value where N is the size of the deleted value, O(N) when path is evaluated to multiple values, where N is the size of the key
O(N) when path is evaluated to a single value where N is the size of the deleted value, O(N) when path is evaluated to multiple values, where N is the size of the key
O(N) when path is evaluated to a single value where N is the size of the deleted value, O(N) when path is evaluated to multiple values, where N is the size of the key
O(N) when path is evaluated to a single value where N is the size of the deleted value, O(N) when path is evaluated to multiple values, where N is the size of the key
O(N) when path is evaluated to a single value where N is the size of the value, O(N) when path is evaluated to multiple values, where N is the size of the key
O(N) when path is evaluated to a single value where N is the size of the value, O(N) when path is evaluated to multiple values, where N is the size of the key
Consequently, JSON values at matching paths are updated, deleted, or expanded with new children.
O(M+N) when path is evaluated to a single value where M is the size of the original value and N is the size of the new value, O(M+N) when path is evaluated to multiple values where M is the size of the key and N is the size of the new value times the number of matches
O(M*N) when path is evaluated to a single value where M is the number of keys and N is the size of the value, O(N1+N2+dots+Nm) when path is evaluated to multiple values
The reply shape depends on the path syntax, so this wrapper returns the raw Reply.
O(N) when path is evaluated to a single value, where N is the number of keys in the object, O(N) when path is evaluated to multiple values, where N is the size of the key
The reply shape depends on the path syntax, so this wrapper returns the raw Reply.
O(N) when path is evaluated to a single value, where N is the number of keys in the object, O(N) when path is evaluated to multiple values, where N is the size of the key
The reply may be any RESP shape depending on the JSON value, so this wrapper returns the raw Reply.
O(N) when path is evaluated to a single value, where N is the size of the value, O(N) when path is evaluated to multiple values, where N is the size of the key
The reply may be any RESP shape depending on the JSON value, so this wrapper returns the raw Reply.
O(N) when path is evaluated to a single value, where N is the size of the value, O(N) when path is evaluated to multiple values, where N is the size of the key
O(M+N) when path is evaluated to a single value where M is the size of the original value and N is the size of the new value, O(M+N) when path is evaluated to multiple values where M is the size of the key and N is the size of the new value times the number of matches
Add channels into the PubSubController, and if there is an active pubSubForever, send the subscribe
and psubscribe commands to Redis. The addChannels function is thread-safe. This function
does not wait for Redis to acknowledge that the channels have actually been subscribed; use
addChannelsAndWait for that.
You can subscribe to the same channel or pattern channel multiple times; the PubSubController keeps
a list of callbacks and executes each callback in response to a message.
The return value is an action UnregisterCallbacksAction which will unregister the callbacks,
which should typically used with bracket.
Call addChannels and then wait for Redis to acknowledge that the channels are actually subscribed.
Note that this function waits for requested subscription change requests, so if you for example call
addChannelsAndWait from multiple threads simultaneously, they will all wait their pending
subscription changes to be acknowledged by Redis.
This also correctly waits if the network connection dies during the subscription change. Say that the
network connection dies right after we send a subscription change to Redis. pubSubForever will throw
ConnectionLost and addChannelsAndWait will continue to wait. Once you recall pubSubForever
with the same PubSubController, pubSubForever will open a new connection, send subscription commands
for all channels in the PubSubController (which include the ones we are waiting for),
and wait for the responses from Redis. Only once we receive the response from Redis that it has subscribed
to all channels in PubSubController will addChannelsAndWait unblock and return.
Get the list of current channels in the PubSubController. WARNING! This might not
exactly reflect the subscribed channels in the Redis server, because there is a delay
between adding or removing a channel in the PubSubController and when Redis receives
and processes the subscription change request.
Get the list of current pattern channels in the PubSubController. WARNING! This might not
exactly reflect the subscribed channels in the Redis server, because there is a delay
between adding or removing a channel in the PubSubController and when Redis receives
and processes the subscription change request.
Create a new PubSubController. Note that this does not subscribe to any channels, it just
creates the controller. The subscriptions will happen once pubSubForever is called.
Listens to published messages on subscribed channels and channels matching
the subscribed patterns. For documentation on the semantics of Redis
Pub/Sub see http://redis.io/topics/pubsub.
The given callback function is called for each received message.
Subscription changes are triggered by the returned PubSub. To keep
subscriptions unchanged, the callback can return mempty.
Example: Subscribe to the "news" channel indefinitely.
pubSub (subscribe ["news"]) $ \msg -> do
putStrLn $ "Message from " ++ show (msgChannel msg)
return mempty
Example: Receive a single message from the "chat" channel.
pubSub (subscribe ["chat"]) $ \msg -> do
putStrLn $ "Message from " ++ show (msgChannel msg)
return $ unsubscribe ["chat"]
It should be noted that Redis Pub/Sub by its nature is asynchronous
so returning unsubscribe does not mean that callback won't be able
to receive any further messages. And to guarantee that you won't
won't process messages after unsubscription and won't unsubscribe
from the same channel more than once you need to use IORef or
something similar
This action is executed once Redis acknowledges that all the subscriptions in
the controller are now subscribed. You can use this after an exception (such as
ConnectionLost) to signal that all subscriptions are now reactivated.
Open a connection to the Redis server, register to all channels in the PubSubController,
and process messages and subscription change requests forever. The only way this will ever
exit is if there is an exception from the network code or an unhandled exception
in a MessageCallback or PMessageCallback. For example, if the network connection to Redis
dies, pubSubForever will throw a ConnectionLost. When such an exception is
thrown, you can recall pubSubForever with the same PubSubController which will open a
new connection and resubscribe to all the channels which are tracked in the PubSubController.
The general pattern is therefore during program startup create a PubSubController and fork
a thread which calls pubSubForever in a loop (using an exponential backoff algorithm
such as the retry package to not hammer the Redis
server if it does die). For example,
myhandler :: ByteString -> IO ()
myhandler msg = putStrLn $ unpack $ decodeUtf8 msg
onInitialComplete :: IO ()
onInitialComplete = putStrLn "Redis acknowledged that mychannel is now subscribed"
main :: IO ()
main = do
conn <- connect defaultConnectInfo
pubSubCtrl <- newPubSubController [("mychannel", myhandler)] []
concurrently ( forever $
pubSubForever conn pubSubCtrl onInitialComplete
`catch` (\(e :: SomeException) -> do
putStrLn $ "Got error: " ++ show e
threadDelay $ 50*1000) -- TODO: use exponential backoff
) $ restOfYourProgram
{- elsewhere in your program, use pubSubCtrl to change subscriptions -}
At most one active pubSubForever can be running against a single PubSubController at any time. If
two active calls to pubSubForever share a single PubSubController there will be deadlocks. If
you do want to process messages using multiple connections to Redis, you can create more than one
PubSubController. For example, create one PubSubController for each getNumCapabilities
and then create a Haskell thread bound to each capability each calling pubSubForever in a loop.
This will create one network connection per controller/capability and allow you to
register separate channels and callbacks for each controller, spreading the load across the capabilities.
Remove channels from the PubSubController, and if there is an active pubSubForever, send the
unsubscribe commands to Redis. Note that as soon as this function returns, no more callbacks will be
executed even if more messages arrive during the period when we request to unsubscribe from the channel
and Redis actually processes the unsubscribe request. This function is thread-safe.
If you remove all channels, the connection in pubSubForever to redis will stay open and waiting for
any new channels from a call to addChannels. If you really want to close the connection,
use killThread or Control.Concurrent.Async.cancel to kill the thread running
pubSubForever.
Call removeChannels and then wait for all pending subscription change requests to be acknowledged
by Redis. This uses the same waiting logic as addChannelsAndWait. Since removeChannels immediately
notifies the PubSubController to start discarding messages, you likely don't need this function and
can just use removeChannels.
Creates a subscription and automatically unsubscribes when callback returns, this function keeps
flow control in the callback, so it is useful for short-lived subscriptions, when the callback knows
when to exit. The function is quite simple and does not make any attempts to handle connection loss.
Note that this function does not support changing subscriptions while it is running, so it is only useful for short-lived Pub/Sub connections.
An example of usage, that is hard to implement with pubSubForever is to subscribe to a channel:
withPubSub conn ["mychannel"] [] $ \waitMsg -> do
d <- registerDelay 1000000 -- 1 second (requires -threaded runtime)
atomically $ asum [ readTVar >>= guard >> return Nothing
, Just $ waitMsg
]
In case if connection is lost, user callback will receive BlockedIndefinitelyOnSTM exception.
Inside the transaction block, command functions return their result wrapped
in a Queued. The Queued result is a proxy object for the actual
command's result, which will only be available after EXECing the
transaction.
Example usage (note how Queued 's Applicative instance is used to
combine the two individual results):
runRedis conn $ do
set "hello" "hello"
set "world" "world"
helloworld <- multiExec $ do
hello <- get "hello"
world <- get "world"
return $ (,) <$> hello <*> world
liftIO (print helloworld)
It is recommended to not use the ConnInfo data constructor directly.
Instead use defaultConnectInfo and update it with record syntax. For
example to connect to a password protected Redis server running on localhost
and listening to the default port:
myConnectInfo :: ConnectInfo
myConnectInfo = defaultConnectInfo {connectAuth = Just "secret"}
Or better yet, use parseConnectInfo to parse a URL.
Amount of time for which an unused connection is kept open. The
smallest acceptable value is 0.5 seconds. If the timeout value in
your redis.conf file is non-zero, it should be larger than
connectMaxIdleTime.
Adds one or more members to a geospatial index (https://redis.io/commands/geoadd). The Redis command GEOADD is split up into geoadd and geoAddOpts. Since Redis 3.2.0
Approximate trimming. Is faster, but may leave slightly more
elements in the stream if they can't be immediately deleted.
Additional parameter Specifies the maximal count of entries that will be evicted. When LIMIT and count aren't specified, the default value of 100 * the number of entries in a macro node will be implicitly used as the count, Just 0 removes the limit entirely.
Enable consumer group lag tracking, specify an arbitrary ID.
An arbitrary ID is any ID that isn't the ID of the stream's first entry,
last entry, or zero ("0-0") ID. Use it to find out how many entries
are between the arbitrary ID (excluding it) and the stream's last entry.
Since Redis 7.0, fails if set on the ealier versions.
Instances2Eq, Show
EqXGroupCreateOptsDefined in hedis-0.16.4 · Database.Redis.ManualCommands
Enable consumer group lag tracking for an arbitrary ID. An arbitrary ID is any ID that isn't the ID of the stream's first entry, its last entry or the zero ("0-0") ID
@since Redis 7.0, fails if set to Just on ealier versions.
The number of entries in the PEL (pending elemeent list): pending messages for the consumer, which are messages that were delivered but are yet to be acknowledged
The number of milliseconds that have passed since the consumer's last successful interaction (Examples: xreadGroup that actually read some entries into the PEL, xclaim/xautoclaim that actually claimed some entries)
since Redis 7.0: always Nothing@ for previous versions.
the number of entries in the stream that are still waiting to be delivered to the group's consumers, or a Nothing when that number can't be determined.
Since Redis 7.0: always Nothing on the previous versions.
Deletes the specified entries from the stream and also removes all references to these entries from all consumer groups' pending entry lists, effectively cleaning up all traces of the messages. If an entry ID is not in the stream, but there are dangling references, XDELEX with DELREF would still remove all those references.
WEIGHTS option, it is possible to specify a multiplication factor for each input sorted set. Each element's score is multiplied by its corresponding weight before aggregation. When WEIGHTS is not given, the multiplication factors default to 1.
Add one or more members to a sorted set, or update its score if it already exists (http://redis.io/commands/zadd). The Redis command ZADD is split up into zadd, zaddOpts. Since Redis 1.2.0
A handler for a message from a subscribed channel.
The callback is passed the message content.
Messages are processed synchronously in the receiving thread, so if the callback
takes a long time it will block other callbacks and other messages from being
received. If you need to move long-running work to a different thread, we suggest
you use TBQueue with a reasonable bound, so that if messages are arriving faster
than you can process them, you do eventually block.
If the callback throws an exception, the exception will be thrown from pubSubForever
which will cause the entire Redis connection for all subscriptions to be closed.
As long as you call pubSubForever in a loop you will reconnect to your subscribed
channels, but you should probably add an exception handler to each callback to
prevent this.
A controller that stores a set of channels, pattern channels, and callbacks.
It allows you to manage Pub/Sub subscriptions and pattern subscriptions and alter them at
any time throughout the life of your program.
You should typically create the controller at the start of your program and then store it
through the life of your program, using addChannels and removeChannels to update the
current subscriptions.
An action that when executed will unregister the callbacks. It is returned from addChannels
or addChannelsAndWait and typically you would use it in bracket to guarantee that you
unsubscribe from channels. For example, if you are using websockets to distribute messages to
clients, you could use something such as:
websocketConn <- Network.WebSockets.acceptRequest pending
let mycallback msg = Network.WebSockets.sendTextData websocketConn msg
bracket (addChannelsAndWait ctrl [("hello", mycallback)] []) id $ const $ do
{- loop here calling Network.WebSockets.receiveData -}
A Queued value represents the result of a command inside a transaction. It
is a proxy object for the actual result, which will only be available
after returning from a multiExec transaction.
Command-context inside of MULTI/EXEC transactions. Use multiExec to run
actions of this type.
In the RedisTx context, all commands return a Queued value. It is a
proxy object for the actual result, which will only be available after
finishing the transaction.