Page
Library
Module
Module type
Parameter
Class
Class type
Source
Make.Clientmodule IO = IOmodule StringBound : sig ... endmodule FloatBound : sig ... endtype 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 ]val string_of_reply : reply -> stringFor debugging purpose.
val connection_spec : ?port:int -> string -> connection_specCreate a connection spec with the given host.
module ConnectionSpecMap : Map.S with type key = connection_spectype 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;}exception Unexpected of replyProtocol errors
val connect : connection_spec -> connection IO.tval disconnect : connection -> unit IO.tval with_connection : connection_spec -> (connection -> 'a IO.t) -> 'a IO.tval stream : connection -> reply list IO.streamval auth : connection -> string -> unit IO.tAuthenticate to server.
val send_custom_request : connection -> string list -> reply IO.tSends a custom request to the Redis server. Example: send_request connection ["set"; "foo"; "bar"]
val auth_acl : connection -> string -> string -> unit IO.tAuthenticate to server with username and password.
val echo : connection -> string -> string option IO.tEcho given string.
val ping : connection -> bool IO.tPing connection; returns true if ping was successfull.
val quit : connection -> unit IO.tClose connection.
val select : connection -> int -> unit IO.tSwitch to a different db; raises Error if index is invalid.
val sentinel_masters : connection -> (string * string) list list IO.tSENTINEL commands
val sentinel_get_master_addr_by_name :
connection ->
string ->
(string * string) option IO.tval del : connection -> string list -> int IO.tDelete a key; returns the number of keys removed.
val exists : connection -> string -> bool IO.tDetermine if a key exists.
val expire : connection -> string -> int -> bool IO.tSet a key's time to live in seconds; returns true if timeout was set, false otherwise.
val pexpire : connection -> string -> int -> bool IO.tSet a key's time to live in milliseconds; returns true if timeout was set, false otherwise.
val expireat : connection -> string -> float -> bool IO.tSet 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.
val pexpireat : connection -> string -> int -> bool IO.tSet the expiration for a key as a UNIX timestamp in milliseconds; returns true if timeout was set, false otherwise.
val keys : connection -> string -> string list IO.tFind all keys matching the given pattern.
val scan :
?pattern:string ->
?count:int ->
connection ->
int ->
(int * string list) IO.tIncrementally iterate the keys space; see tests for usage example.
val move : connection -> string -> int -> bool IO.tMove key to a different db; returns true if key was moved, false otherwise.
val persist : connection -> string -> bool IO.tRemove timeout on key; returns true if timeout was removed, false otherwise.
val randomkey : connection -> string option IO.tReturn a random key from the keyspace; returns None if db is empty.
val rename : connection -> string -> string -> unit IO.tRename a key; raises Error if key doesn't exist.
val renamenx : connection -> string -> string -> bool IO.tRename 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.tSort 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.tSort and store elements in a list, set or sorted set; returns length of sorted items list which was stored.
val ttl : connection -> string -> int option IO.tTime to live for a key in seconds; returns None if key doesn't exist or doesn't have a timeout.
val pttl : connection -> string -> int option IO.tTime to live for a key in milliseconds; returns None if key doesn't exist or doesn't have a timeout.
val type_of :
connection ->
string ->
[> `Hash | `List | `None | `String | `Zset ] IO.tDetermine the type stored as key.
val dump : connection -> string -> string option IO.tReturn a serialized version of the value stored at the specified key; returns None if key doesn't exist.
val restore : connection -> string -> int -> string -> unit IO.tCreate a key with serialized value (obtained via DUMP).
val migrate :
connection ->
?copy:bool ->
?replace:bool ->
string ->
int ->
string ->
int ->
int ->
unit IO.tAtomically transfer a key from a source Redis instance to a destination Redis instance.
val object_refcount : connection -> string -> int option IO.tInspect the internals of Redis objects; returns the number of references of the value associated with the specified key.
val object_encoding : connection -> string -> string option IO.tInspect the internals of Redis objects; returns the kind of internal representation used in order to store the value associated with a key.
val object_idletime : connection -> string -> int option IO.tInspect the internals of Redis objects; returns the number of seconds since the object stored at the specified key is idle.
val append : connection -> string -> string -> int IO.tAppend a value to a key; returns length of string after append.
val setbit : connection -> string -> int -> int -> int IO.tSets or clears the bit at offset in the string value stored at key.
val getbit : connection -> string -> int -> int IO.tReturns the bit value at offset in the string value stored at key.
val bitop : connection -> bit_operation -> string -> string list -> int IO.tPerform a bitwise operation between multiple keys (containing string values) and store the result in the destination key. See bit_operation type for available operations.
val bitcount : ?first:int -> ?last:int -> connection -> string -> int IO.tCount the number of set bits (population counting) in a string.
val bitpos : ?first:int -> ?last:int -> connection -> string -> int -> int IO.tReturn the position of the first bit set to 1 or 0 in a string.
val decr : connection -> string -> int IO.tDecrements the number stored at key by one. If the key does not exist, it is set to 0 before performing the operation.
val decrby : connection -> string -> int -> int IO.tDecrements the number stored at key by decrement. If the key does not exist, it is set to 0 before performing the operation.
val get : connection -> string -> string option IO.tGet the value of key.
val getrange : connection -> string -> int -> int -> string option IO.tReturns the substring of the string value stored at key, determined by the offsets start and end (both are inclusive).
val getset : connection -> string -> string -> string option IO.tAtomically sets key to value and returns the old value stored at key. Returns None when key exists but does not hold a string value.
val incr : connection -> string -> int IO.tIncrements the number stored at key by one. If the key does not exist, it is set to 0 before performing the operation.
val incrby : connection -> string -> int -> int IO.tIncrements the number stored at key by increment. If the key does not exist, it is set to 0 before performing the operation.
val incrbyfloat : connection -> string -> float -> float IO.tIncrement 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.
val mget : connection -> string list -> string option list IO.tReturns the values of all specified keys.
val mset : connection -> (string * string) list -> unit IO.tSets the given keys to their respective values.
val msetnx : connection -> (string * string) list -> bool IO.tSets 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.tSet key to hold the string value.
val setex : connection -> string -> int -> string -> unit IO.tSet key to hold the string value and set key to timeout after a given number of seconds.
val psetex : connection -> string -> int -> string -> unit IO.tPSETEX works exactly like SETEX with the sole difference that the expire time is specified in milliseconds instead of seconds.
val setnx : connection -> string -> string -> bool IO.tSet key to hold string value if key does not exist.
val setrange : connection -> string -> int -> string -> int IO.tOverwrites part of the string stored at key, starting at the specified offset, for the entire length of value.
val strlen : connection -> string -> int IO.tReturns the length of the string value stored at key. An error is returned when key holds a non-string value.
val hdel : connection -> string -> string -> bool IO.tRemoves the specified fields from the hash stored at key. Specified fields that do not exist within this hash are ignored.
val hexists : connection -> string -> string -> bool IO.tReturns if field is an existing field in the hash stored at key.
val hget : connection -> string -> string -> string option IO.tReturns the value associated with field in the hash stored at key.
val hgetall : connection -> string -> (string * string) list IO.tReturns all fields and values of the hash stored at key.
val hincrby : connection -> string -> string -> int -> int IO.tIncrements the number stored at field in the hash stored at key by increment.
val hincrbyfloat : connection -> string -> string -> float -> float IO.tIncrements the number stored at field in the hash stored at key by increment.
val hkeys : connection -> string -> string list IO.tReturns all field names in the hash stored at key.
val hlen : connection -> string -> int IO.tReturns the number of fields contained in the hash stored at key.
val hmget : connection -> string -> string list -> string option list IO.tReturns the values associated with the specified fields in the hash stored at key.
val hmset : connection -> string -> (string * string) list -> unit IO.tSets the specified fields to their respective values in the hash stored at key.
val hset : connection -> string -> string -> string -> bool IO.tSets field in the hash stored at key to value.
val hsetnx : connection -> string -> string -> string -> bool IO.tSets field in the hash stored at key to value, only if field does not yet exist.
val hstrlen : connection -> string -> string -> int IO.tGet the length of the value of a hash field
val hscan :
?pattern:string ->
?count:int ->
connection ->
string ->
int ->
(int * (string * string) list) IO.tIncrementally iterate hash fields and associated values
val hvals : connection -> string -> string list IO.tReturns all values in the hash stored at key.
val blpop : connection -> string list -> int -> (string * string) option IO.tRemove and get the first element in a list, or block until one is available
val brpop : connection -> string list -> int -> (string * string) option IO.tRemove and get the last element in a list, or block until one is available
val brpoplpush : connection -> string -> string -> int -> string option IO.tPop a value from a list, push it to another list and return it; or block until one is available
val lindex : connection -> string -> int -> string option IO.tGet an element from a list by its index
val linsert :
connection ->
string ->
[< `After | `Before ] ->
string ->
string ->
int option IO.tInsert an element before or after another element in a list
val llen : connection -> string -> int IO.tGet the length of a list
val lpop : connection -> string -> string option IO.tRemove and get the first element in a list
val lpush : connection -> string -> string list -> int IO.tPrepend one or multiple values to a list
val lpushx : connection -> string -> string list -> int IO.tPrepend a value to a list, only if the list exists
val lrange : connection -> string -> int -> int -> string list IO.tGet a range of elements from a list
val lrem : connection -> string -> int -> string -> int IO.tRemove elements from a list
val lset : connection -> string -> int -> string -> unit IO.tSet the value of an element in a list by its index
val ltrim : connection -> string -> int -> int -> unit IO.tTrim a list to the specified range
val rpop : connection -> string -> string option IO.tRemove and get the last element in a list
val rpoplpush : connection -> string -> string -> string option IO.tRemove the last element in a list, prepend it to another list and return it
val rpush : connection -> string -> string list -> int IO.tAppend one or multiple values to a list
val rpushx : connection -> string -> string list -> int IO.tAppend a value to a list, only if the list exists
val lmove :
connection ->
string ->
string ->
[ `Left | `Right ] ->
[ `Left | `Right ] ->
string option IO.tlmove 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.tsame as lmove but blocks for up to timeout seconds.
val pfadd : connection -> string -> string list -> bool IO.tAdds values to the HyperLogLog data structure.
val pfcount : connection -> string list -> int IO.tReturns the approximated cardinality of the union of the HyperLogLogs passed.
val pfmerge : connection -> string list -> unit IO.tMerge multiple HyperLogLog values into an unique value that will approximate the cardinality of the union of the observed Sets of the source HyperLogLog structures.
val sadd : connection -> string -> string -> bool IO.tReturns true if member was added, false otherwise.
val scard : connection -> string -> int IO.tval sdiff : connection -> string list -> string list IO.tDifference between first and all successive sets.
val sdiffstore : connection -> string -> string list -> int IO.tlike sdiff, but store result in destination. returns size of result.
val sinter : connection -> string list -> string list IO.tval sinterstore : connection -> string -> string list -> int IO.tLike SINTER, but store result in destination. Returns size of result.
val sismember : connection -> string -> string -> bool IO.tval smembers : connection -> string -> string list IO.tval smove : connection -> string -> string -> string -> bool IO.tReturns true if an element was moved, false otherwise.
val spop : connection -> string -> string option IO.tRemove random element from set.
val srandmember : connection -> string -> string option IO.tLike SPOP, but doesn't remove chosen element.
val srem : connection -> string -> string -> bool IO.tReturns true if element was removed.
val sunion : connection -> string list -> string list IO.tval sunionstore : connection -> string -> string list -> int IO.tLike SUNION, but store result in destination. Returns size of result.
val publish : connection -> string -> string -> int IO.tPost a message to a channel. Returns number of clients that received the message.
val pubsub_channels : connection -> string option -> reply list IO.tLists the currently active channels. If no pattern is specified, all channels are listed.
val pubsub_numsub : connection -> string list -> reply list IO.tReturns the number of subscribers (not counting clients subscribed to patterns) for the specified channels.
val subscribe : connection -> string list -> unit IO.tSubscribes the client to the specified channels.
val unsubscribe : connection -> string list -> unit IO.tUnsubscribes the client from the given channels, or from all of them if an empty list is given
val psubscribe : connection -> string list -> unit IO.tSubscribes the client to the given patterns.
val punsubscribe : connection -> string list -> unit IO.tUnsubscribes the client from the given patterns.
val zadd :
connection ->
?x:[< `NX | `XX ] ->
?ch:bool ->
string ->
(float * string) list ->
int IO.tAdd one or more members to a sorted set, or update its score if it already exists.
val zrange :
connection ->
?withscores:bool ->
string ->
int ->
int ->
reply list IO.tReturn a range of members in a sorted set, by index.
val zrevrange :
connection ->
?withscores:bool ->
string ->
int ->
int ->
reply list IO.tReturn 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.tReturn a range of members in a sorted set, by score.
val zrangebylex :
connection ->
?limit:(int * int) ->
string ->
StringBound.t ->
StringBound.t ->
reply list IO.tReturn 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.tReturn a range of members in a sorted set, by score.
val zrevrangebylex :
connection ->
?limit:(int * int) ->
string ->
StringBound.t ->
StringBound.t ->
reply list IO.tReturn a range of members in a sorted set, by lexicographical range.
val zrem : connection -> string -> string list -> int IO.tRemove one or more members from a sorted set.
val zremrangebylex :
connection ->
string ->
StringBound.t ->
StringBound.t ->
int IO.tRemove all members in a sorted set between the given lexicographical range.
val zremrangebyscore :
connection ->
string ->
FloatBound.t ->
FloatBound.t ->
int IO.tRemove all members in a sorted set between the given score range.
val zremrangebyrank : connection -> string -> int -> int -> int IO.tRemove all members in a sorted set between the given rank range.
val zcard : connection -> string -> int IO.tReturns the sorted set cardinality (number of elements) of the sorted set stored at key.
val zincrby : connection -> string -> float -> string -> float IO.tIncrement the score of a member in the sorted set
val zscore : connection -> string -> string -> float option IO.tReturns the score of a member in the sorted set.
val zcount : connection -> string -> FloatBound.t -> FloatBound.t -> int IO.tReturns the number of elements in the sorted set at key with a score between min and max.
val zlexcount :
connection ->
string ->
StringBound.t ->
StringBound.t ->
int IO.tReturns the number of members in a sorted set between a given lexicographical range.
val zrank : connection -> string -> string -> int option IO.tReturns the rank of member in the sorted set stored at key.
val zrevrank : connection -> string -> string -> int option IO.tReturns the reversed rank of member in the sorted set stored at key.
val zpopmin : connection -> string -> int -> (string * float) list IO.tRemoves and returns one or more members with the lowest scores in a sorted set.
val zpopmax : connection -> string -> int -> (string * float) list IO.tRemove and return one or more members with the highest scores in a sorted set.
val bzpopmin :
connection ->
string list ->
float ->
(string * string * float) option IO.tRemove and return the member with the lowest score in a sorted set, or block until one is available.
val bzpopmax :
connection ->
string list ->
float ->
(string * string * float) option IO.tRemove 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.tAdd a stream event, as a list of key-value pairs, to the given stream.
@see the official doc
val xdel : connection -> string -> string list -> int IO.tDelete specific stream events. Should be rarely useful.
@see the official doc
val xlen : connection -> string -> int IO.tLength of a stream. @see https://redis.io/commands/xlen .
val xtrim :
connection ->
string ->
maxlen:[ `Exact of int | `Approximate of int ] ->
unit ->
int IO.tTrim 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.txrange 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.tLike 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.txread 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
val multi : connection -> unit IO.tMarks the start of a transaction block. Subsequent commands will be queued for atomic execution using EXEC.
val exec : connection -> reply list IO.tExecutes all previously queued commands in a transaction and restores the connection state to normal.
val discard : connection -> unit IO.tFlushes all previously queued commands in a transaction and restores the connection state to normal.
val watch : connection -> string list -> unit IO.tMarks the given keys to be watched for conditional execution of a transaction.
val unwatch : connection -> unit IO.tFlushes all the previously watched keys for a transaction.
val script_load : connection -> string -> string IO.tLoad the specified Lua script into the script cache. Returns the SHA1 digest of the script for use with EVALSHA.
val eval : connection -> string -> string list -> string list -> reply IO.tEvaluates a script using the built-in Lua interpreter.
val evalsha : connection -> string -> string list -> string list -> reply IO.tEvaluates a script cached on the server side by its SHA1 digest.
val bgrewriteaof : connection -> unit IO.tval bgsave : connection -> unit IO.tval config_resetstat : connection -> unit IO.tval dbsize : connection -> int IO.tval flushall : connection -> unit IO.tclear all databases
val flushdb : connection -> unit IO.tclear current database
val info : connection -> (string * string) list IO.tval lastsave : connection -> float IO.tlast successful save as Unix timestamp
val role : connection -> reply list IO.trole in context of replication
val save : connection -> unit IO.tsynchronous save
val shutdown : connection -> unit IO.tsave and shutdown server
module MassInsert : sig ... endBatch commands for mass insertion