Page
Library
Module
Module type
Parameter
Class
Class type
Source
Redis_lwt.Client
Sourcetype reply = [
| `Status of string
| `Error of string
| `Int of int
| `Int64 of Int64.t
| `Bulk of string option
| `Multibulk of reply list
| `Ask of redirection
| `Moved of redirection
]
Server connection info
Print the spec
Print the spec
Create a connection spec with the given host.
Create a connection spec to use the given Unix socket.
type cluster_connections = private {
mutable connections_spec : connection_spec SlotMap.t;
mutable connections : connection ConnectionSpecMap.t;
}
and connection = private {
fd : IO.fd;
in_ch : IO.in_channel;
out_ch : IO.out_channel;
stream : reply list IO.stream;
cluster : cluster_connections;
}
Error responses from server
Possible BITOP operations
Authenticate to server.
Sends a custom request to the Redis server. Example: send_request connection ["set"; "foo"; "bar"]
Send a list of custom requests in a pipelined fashion (all are written, then all replies are read)
Authenticate to server with username and password.
Echo given string.
Ping connection; returns true
if ping was successfull.
Close connection.
Switch to a different db; raises Error
if index is invalid.
SENTINEL commands
Delete a key; returns the number of keys removed.
Determine if a key exists.
Set a key's time to live in seconds; returns true
if timeout was set, false otherwise.
Set a key's time to live in milliseconds; returns true
if timeout was set, false otherwise.
Set the expiration for a key as a UNIX timestamp, the time is truncated to the nearest second; returns true
if timeout was set, false
otherwise.
Set the expiration for a key as a UNIX timestamp in milliseconds; returns true
if timeout was set, false
otherwise.
Find all keys matching the given pattern.
Incrementally iterate the keys space; see tests for usage example.
Move key to a different db; returns true
if key was moved, false
otherwise.
Remove timeout on key; returns true
if timeout was removed, false
otherwise.
Return a random key from the keyspace; returns None
if db is empty.
Rename a key; raises Error
if key doesn't exist.
Rename a key, only if the new key does not exist; returns true
if key was renamed, false
if newkey already exists.
val sort :
connection ->
?by:string ->
?limit:(int * int) ->
?get:'a list ->
?order:[< `Asc | `Desc ] ->
?alpha:bool ->
string ->
string list IO.t
Sort elements in a list, set or sorted set; return sorted list of items.
val sort_and_store :
connection ->
?by:string ->
?limit:(int * int) ->
?get:'a list ->
?order:[< `Asc | `Desc ] ->
?alpha:bool ->
string ->
string ->
int IO.t
Sort and store elements in a list, set or sorted set; returns length of sorted items list which was stored.
Time to live for a key in seconds; returns None
if key doesn't exist or doesn't have a timeout.
Time to live for a key in milliseconds; returns None
if key doesn't exist or doesn't have a timeout.
Determine the type stored as key.
Return a serialized version of the value stored at the specified key; returns None
if key doesn't exist.
Create a key with serialized value (obtained via DUMP).
val migrate :
connection ->
?copy:bool ->
?replace:bool ->
string ->
int ->
string ->
int ->
int ->
unit IO.t
Atomically transfer a key from a source Redis instance to a destination Redis instance.
Inspect the internals of Redis objects; returns the number of references of the value associated with the specified key.
Inspect the internals of Redis objects; returns the kind of internal representation used in order to store the value associated with a key.
Inspect the internals of Redis objects; returns the number of seconds since the object stored at the specified key is idle.
Append a value to a key; returns length of string after append.
Sets or clears the bit at offset in the string value stored at key.
Returns the bit value at offset in the string value stored at key.
Perform a bitwise operation between multiple keys (containing string values) and store the result in the destination key. See bit_operation
type for available operations.
Count the number of set bits (population counting) in a string.
Return the position of the first bit set to 1 or 0 in a string.
Decrements the number stored at key by one. If the key does not exist, it is set to 0 before performing the operation.
Decrements the number stored at key by decrement. If the key does not exist, it is set to 0 before performing the operation.
Get the value of key.
Returns the substring of the string value stored at key, determined by the offsets start and end (both are inclusive).
Atomically sets key to value and returns the old value stored at key. Returns None
when key exists but does not hold a string value.
Increments the number stored at key by one. If the key does not exist, it is set to 0 before performing the operation.
Increments the number stored at key by increment. If the key does not exist, it is set to 0 before performing the operation.
Increment the string representing a floating point number stored at key by the specified increment. If the key does not exist, it is set to 0 before performing the operation.
Returns the values of all specified keys.
Sets the given keys to their respective values.
Sets the given keys to their respective values. MSETNX will not perform any operation at all even if just a single key already exists.
val set :
connection ->
?ex:int ->
?px:int ->
?nx:bool ->
?xx:bool ->
string ->
string ->
bool IO.t
Set key to hold the string value.
Set key to hold the string value and set key to timeout after a given number of seconds.
PSETEX works exactly like SETEX with the sole difference that the expire time is specified in milliseconds instead of seconds.
Set key to hold string value if key does not exist.
Overwrites part of the string stored at key, starting at the specified offset, for the entire length of value.
Returns the length of the string value stored at key. An error is returned when key holds a non-string value.
Removes the specified fields from the hash stored at key. Specified fields that do not exist within this hash are ignored.
Returns if field is an existing field in the hash stored at key.
Returns the value associated with field in the hash stored at key.
Returns all fields and values of the hash stored at key.
Increments the number stored at field in the hash stored at key by increment.
Increments the number stored at field in the hash stored at key by increment.
Returns all field names in the hash stored at key.
Returns the number of fields contained in the hash stored at key.
Returns the values associated with the specified fields in the hash stored at key.
Sets the specified fields to their respective values in the hash stored at key.
Sets field in the hash stored at key to value.
Sets field in the hash stored at key to value, only if field does not yet exist.
Get the length of the value of a hash field
val hscan :
?pattern:string ->
?count:int ->
connection ->
string ->
int ->
(int * (string * string) list) IO.t
Incrementally iterate hash fields and associated values
Returns all values in the hash stored at key.
Remove and get the first element in a list, or block until one is available
Remove and get the last element in a list, or block until one is available
Pop a value from a list, push it to another list and return it; or block until one is available
Get an element from a list by its index
val linsert :
connection ->
string ->
[< `After | `Before ] ->
string ->
string ->
int option IO.t
Insert an element before or after another element in a list
Get the length of a list
Remove and get the first element in a list
Prepend one or multiple values to a list
Prepend a value to a list, only if the list exists
Get a range of elements from a list
Remove elements from a list
Set the value of an element in a list by its index
Trim a list to the specified range
Remove and get the last element in a list
Remove the last element in a list, prepend it to another list and return it
Append one or multiple values to a list
Append a value to a list, only if the list exists
val lmove :
connection ->
string ->
string ->
[ `Left | `Right ] ->
[ `Left | `Right ] ->
string option IO.t
lmove from into sidefrom sideinto
moves an element from from
into into
, picking which side to pop/push based on the last arguments, and returns the element.
since redis 6.2
val blmove :
connection ->
string ->
string ->
[ `Left | `Right ] ->
[ `Left | `Right ] ->
timeout:int ->
string option IO.t
same as lmove
but blocks for up to timeout
seconds.
Adds values to the HyperLogLog data structure.
Returns the approximated cardinality of the union of the HyperLogLogs passed.
Merge multiple HyperLogLog values into an unique value that will approximate the cardinality of the union of the observed Sets of the source HyperLogLog structures.
Returns true if member was added, false otherwise.
Difference between first and all successive sets.
like sdiff, but store result in destination. returns size of result.
Like SINTER, but store result in destination. Returns size of result.
Returns true if an element was moved, false otherwise.
Remove random element from set.
Like SPOP, but doesn't remove chosen element.
Returns true if element was removed.
Like SUNION, but store result in destination. Returns size of result.
Post a message to a channel. Returns number of clients that received the message.
Lists the currently active channels. If no pattern is specified, all channels are listed.
Returns the number of subscribers (not counting clients subscribed to patterns) for the specified channels.
Subscribes the client to the specified channels.
From now on only pubsub related commands are accepted on the connection. Use stream
to read the stream the notifications (possibly-concurrently). Each notification in the form of ["message"; "<channel name>"; "<message>"]
for subscribed messages, or ["subscribe"; <list of channel>]
or ["unsubscribe"; <list of channels]
. Use reset
to exit the subscription state and issue other types of commands. See https://redis.io/docs/latest/develop/interact/pubsub/ for more details.
Unsubscribes the client from the given channels, or from all of them if an empty list is given
Subscribes the client to the given patterns. See subscribe
for more details.
Unsubscribes the client from the given patterns.
val zadd :
connection ->
?x:[< `NX | `XX ] ->
?ch:bool ->
string ->
(float * string) list ->
int IO.t
Add one or more members to a sorted set, or update its score if it already exists.
Return a range of members in a sorted set, by index.
Return a reversed range of members in a sorted set, by index.
val zrangebyscore :
connection ->
?withscores:bool ->
?limit:(int * int) ->
string ->
FloatBound.t ->
FloatBound.t ->
reply list IO.t
Return a range of members in a sorted set, by score.
val zrangebylex :
connection ->
?limit:(int * int) ->
string ->
StringBound.t ->
StringBound.t ->
reply list IO.t
Return a range of members in a sorted set, by lexicographical range.
val zrevrangebyscore :
connection ->
?withscores:bool ->
?limit:(int * int) ->
string ->
FloatBound.t ->
FloatBound.t ->
reply list IO.t
Return a range of members in a sorted set, by score.
val zrevrangebylex :
connection ->
?limit:(int * int) ->
string ->
StringBound.t ->
StringBound.t ->
reply list IO.t
Return a range of members in a sorted set, by lexicographical range.
Remove one or more members from a sorted set.
Remove all members in a sorted set between the given lexicographical range.
Remove all members in a sorted set between the given score range.
Remove all members in a sorted set between the given rank range.
Returns the sorted set cardinality (number of elements) of the sorted set stored at key.
Increment the score of a member in the sorted set
Returns the score of a member in the sorted set.
Returns the number of elements in the sorted set at key with a score between min and max.
Returns the number of members in a sorted set between a given lexicographical range.
Returns the rank of member in the sorted set stored at key.
Returns the reversed rank of member in the sorted set stored at key.
Removes and returns one or more members with the lowest scores in a sorted set.
Remove and return one or more members with the highest scores in a sorted set.
Remove and return the member with the lowest score in a sorted set, or block until one is available.
Remove and return the member with the highest score in a sorted set, or block until one is available.
For redis >= 5. We only support a subset of the commands for now.
val xadd :
connection ->
string ->
?maxlen:[ `Exact of int | `Approximate of int ] ->
?id:string ->
(string * string) list ->
string IO.t
Add a stream event, as a list of key-value pairs, to the given stream.
@see the official doc
Delete specific stream events. Should be rarely useful.
@see the official doc
Length of a stream. @see https://redis.io/commands/xlen .
val xtrim :
connection ->
string ->
maxlen:[ `Exact of int | `Approximate of int ] ->
unit ->
int IO.t
Trim stream to the given maximum length.
@see the official doc
A stream event as returned by Redis. It is composed of a stream ID (timestamp + counter), and a list of key/value pairs.
val xrange :
connection ->
string ->
start:StringBound.t ->
end_:StringBound.t ->
?count:int ->
unit ->
stream_event list IO.t
xrange connection stream ~start ~end_ ()
returns a range of events in the stream.
StringBound.NegInfinity
("-" in the doc) to indicate the earliest possible timeStringBound.Inclusive "timestamp"
or StringBound.Inclusive "timestamp-number"
for a left-inclusive boundStringBound.Exclusive "timestamp"
or StringBound.Exclusive "timestamp-number"
for a left-exclusive bound ("(" in the doc) only since Redis 6.2@see the official doc
val xrevrange :
connection ->
string ->
start:StringBound.t ->
end_:StringBound.t ->
?count:int ->
unit ->
stream_event list IO.t
Like xrange
but in reverse order. @see the official doc
val xread :
connection ->
?count:int ->
?block_ms:int ->
(string * [ `Last | `After of string ]) list ->
(string * stream_event list) list IO.t
xread connection pairs
reads data from the multiple streams specified in pairs
.
Each item of pairs
is a pair ("stream-name", <after>)
where <after>
is either:
`Last
("$" in the doc) to get events coming after the last current event (so, new events);`After i
to get events coming after the given ID i
, excluding i
itself.@see the official doc
Marks the start of a transaction block. Subsequent commands will be queued for atomic execution using EXEC.
Executes all previously queued commands in a transaction and restores the connection state to normal.
Flushes all previously queued commands in a transaction and restores the connection state to normal.
Marks the given keys to be watched for conditional execution of a transaction.
Flushes all the previously watched keys for a transaction.
Load the specified Lua script into the script cache. Returns the SHA1 digest of the script for use with EVALSHA.
Evaluates a script using the built-in Lua interpreter.
Evaluates a script cached on the server side by its SHA1 digest.
clear all databases
clear current database
last successful save as Unix timestamp
role in context of replication
synchronous save
save and shutdown server
Batch commands for mass insertion