package redis

  1. Overview
  2. Docs
module IO = IO
module StringBound : sig ... end
module FloatBound : sig ... end
Types and exceptions
type reply = [
  1. | `Status of string
  2. | `Error of string
  3. | `Int of int
  4. | `Int64 of Int64.t
  5. | `Bulk of string option
  6. | `Multibulk of reply list
]
type connection = private {
  1. fd : IO.fd;
  2. in_ch : IO.in_channel;
  3. out_ch : IO.out_channel;
  4. stream : reply list IO.stream;
}
exception Error of string

Error responses from server

exception Unexpected of reply

Protocol errors

exception Unrecognized of string * string
type connection_spec = {
  1. host : string;
  2. port : int;
}

Server connection info

type bit_operation =
  1. | AND
  2. | OR
  3. | XOR
  4. | NOT

Possible BITOP operations

Connection handling
val disconnect : connection -> unit IO.t
val with_connection : connection_spec -> (connection -> 'a IO.t) -> 'a IO.t
val stream : connection -> reply list IO.stream
Connection commands
val auth : connection -> string -> unit IO.t

Authenticate to server.

val echo : connection -> string -> string option IO.t

Echo given string.

val ping : connection -> bool IO.t

Ping connection; returns true if ping was successfull.

val quit : connection -> unit IO.t

Close connection.

val select : connection -> int -> unit IO.t

Switch to a different db; raises Error if index is invalid.

Keys commands
val del : connection -> string list -> int IO.t

Delete a key; returns the number of keys removed.

val exists : connection -> string -> bool IO.t

Determine if a key exists.

val expire : connection -> string -> int -> bool IO.t

Set a key's time to live in seconds; returns true if timeout was set, false otherwise.

val pexpire : connection -> string -> int -> bool IO.t

Set a key's time to live in milliseconds; returns true if timeout was set, false otherwise.

val expireat : connection -> string -> float -> bool IO.t

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.

val pexpireat : connection -> string -> int -> bool IO.t

Set 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.t

Find all keys matching the given pattern.

val scan : ?pattern:string -> ?count:int -> connection -> int -> (int * string list) IO.t

Incrementally iterate the keys space; see tests for usage example.

val move : connection -> string -> int -> bool IO.t

Move key to a different db; returns true if key was moved, false otherwise.

val persist : connection -> string -> bool IO.t

Remove timeout on key; returns true if timeout was removed, false otherwise.

val randomkey : connection -> string option IO.t

Return a random key from the keyspace; returns None if db is empty.

val rename : connection -> string -> string -> unit IO.t

Rename a key; raises Error if key doesn't exist.

val renamenx : connection -> string -> string -> bool IO.t

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.

val ttl : connection -> string -> int option IO.t

Time 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.t

Time 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.t

Determine the type stored as key.

val dump : connection -> string -> string option IO.t

Return 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.t

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.

val object_refcount : connection -> string -> int option IO.t

Inspect 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.t

Inspect 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.t

Inspect the internals of Redis objects; returns the number of seconds since the object stored at the specified key is idle.

String commands
val append : connection -> string -> string -> int IO.t

Append a value to a key; returns length of string after append.

val setbit : connection -> string -> int -> int -> int IO.t

Sets or clears the bit at offset in the string value stored at key.

val getbit : connection -> string -> int -> int IO.t

Returns the bit value at offset in the string value stored at key.

val bitop : connection -> bit_operation -> string -> string list -> int IO.t

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.

val bitcount : ?first:int -> ?last:int -> connection -> string -> int IO.t

Count the number of set bits (population counting) in a string.

val bitpos : ?first:int -> ?last:int -> connection -> string -> int -> int IO.t

Return the position of the first bit set to 1 or 0 in a string.

val decr : connection -> string -> int IO.t

Decrements 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.t

Decrements 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.t

Get the value of key.

val getrange : connection -> string -> int -> int -> string option IO.t

Returns 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.t

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.

val incr : connection -> string -> int IO.t

Increments 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.t

Increments 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.t

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.

val mget : connection -> string list -> string option list IO.t

Returns the values of all specified keys.

val mset : connection -> (string * string) list -> unit IO.t

Sets the given keys to their respective values.

val msetnx : connection -> (string * string) list -> bool IO.t

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.

val setex : connection -> string -> int -> string -> unit IO.t

Set 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.t

PSETEX 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.t

Set key to hold string value if key does not exist.

val setrange : connection -> string -> int -> string -> int IO.t

Overwrites part of the string stored at key, starting at the specified offset, for the entire length of value.

val strlen : connection -> string -> int IO.t

Returns the length of the string value stored at key. An error is returned when key holds a non-string value.

Hash commands
val hdel : connection -> string -> string -> bool IO.t

Removes 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.t

Returns if field is an existing field in the hash stored at key.

val hget : connection -> string -> string -> string option IO.t

Returns the value associated with field in the hash stored at key.

val hgetall : connection -> string -> (string * string) list IO.t

Returns all fields and values of the hash stored at key.

val hincrby : connection -> string -> string -> int -> int IO.t

Increments the number stored at field in the hash stored at key by increment.

val hincrbyfloat : connection -> string -> string -> float -> float IO.t

Increments the number stored at field in the hash stored at key by increment.

val hkeys : connection -> string -> string list IO.t

Returns all field names in the hash stored at key.

val hlen : connection -> string -> int IO.t

Returns the number of fields contained in the hash stored at key.

val hmget : connection -> string -> string list -> string option list IO.t

Returns the values associated with the specified fields in the hash stored at key.

val hmset : connection -> string -> (string * string) list -> unit IO.t

Sets the specified fields to their respective values in the hash stored at key.

val hset : connection -> string -> string -> string -> bool IO.t

Sets field in the hash stored at key to value.

val hsetnx : connection -> string -> string -> string -> bool IO.t

Sets field in the hash stored at key to value, only if field does not yet exist.

val hstrlen : connection -> string -> string -> int IO.t

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

val hvals : connection -> string -> string list IO.t

Returns all values in the hash stored at key.

List commands
val blpop : connection -> string list -> int -> (string * string) option IO.t

Remove and get the first element in a list, or block until one is available

val brpop : connection -> string list -> int -> (string * string) option IO.t

Remove and get the last element in a list, or block until one is available

val brpoplpush : connection -> string -> string -> int -> string option IO.t

Pop 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.t

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

val llen : connection -> string -> int IO.t

Get the length of a list

val lpop : connection -> string -> string option IO.t

Remove and get the first element in a list

val lpush : connection -> string -> string -> int IO.t

Prepend one or multiple values to a list

val lpushx : connection -> string -> string -> int IO.t

Prepend a value to a list, only if the list exists

val lrange : connection -> string -> int -> int -> string list IO.t

Get a range of elements from a list

val lrem : connection -> string -> int -> string -> int IO.t

Remove elements from a list

val lset : connection -> string -> int -> string -> unit IO.t

Set the value of an element in a list by its index

val ltrim : connection -> string -> int -> int -> unit IO.t

Trim a list to the specified range

val rpop : connection -> string -> string option IO.t

Remove and get the last element in a list

val rpoplpush : connection -> string -> string -> string option IO.t

Remove the last element in a list, prepend it to another list and return it

val rpush : connection -> string -> string -> int IO.t

Append one or multiple values to a list

val rpushx : connection -> string -> string -> int IO.t

Append a value to a list, only if the list exists

HyperLogLog commands
val pfadd : connection -> string -> string list -> bool IO.t

Adds values to the HyperLogLog data structure.

val pfcount : connection -> string list -> int IO.t

Returns the approximated cardinality of the union of the HyperLogLogs passed.

val pfmerge : connection -> string list -> unit IO.t

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.

Set commands
val sadd : connection -> string -> string -> bool IO.t
val scard : connection -> string -> int IO.t
val sdiff : connection -> string list -> string list IO.t
val sdiffstore : connection -> string -> string list -> int IO.t
val sinter : connection -> string list -> string list IO.t
val sinterstore : connection -> string -> string list -> int IO.t
val sismember : connection -> string -> string -> bool IO.t
val smembers : connection -> string -> string list IO.t
val smove : connection -> string -> string -> string -> bool IO.t
val spop : connection -> string -> string option IO.t
val srandmember : connection -> string -> string option IO.t
val srem : connection -> string -> string -> bool IO.t
val sunion : connection -> string list -> string list IO.t
val sunionstore : connection -> string -> string list -> int IO.t
Pub/sub commands
val publish : connection -> string -> string -> int IO.t
val pubsub_channels : connection -> string option -> reply list IO.t
val pubsub_numsub : connection -> string list -> reply list IO.t
val subscribe : connection -> string list -> unit IO.t
val unsubscribe : connection -> string list -> unit IO.t
val psubscribe : connection -> string list -> unit IO.t
val punsubscribe : connection -> string list -> unit IO.t
Sorted set commands
val zadd : connection -> ?x:[< `NX | `XX ] -> ?ch:bool -> string -> (float * string) list -> int IO.t
val zrange : connection -> ?withscores:bool -> string -> int -> int -> reply list IO.t
val zrevrange : connection -> ?withscores:bool -> string -> int -> int -> reply list IO.t
val zrangebyscore : connection -> ?withscores:bool -> ?limit:(int * int) -> string -> FloatBound.t -> FloatBound.t -> reply list IO.t
val zrangebylex : connection -> ?limit:(int * int) -> string -> StringBound.t -> StringBound.t -> reply list IO.t
val zrevrangebyscore : connection -> ?withscores:bool -> ?limit:(int * int) -> string -> FloatBound.t -> FloatBound.t -> reply list IO.t
val zrevrangebylex : connection -> ?limit:(int * int) -> string -> StringBound.t -> StringBound.t -> reply list IO.t
val zrem : connection -> string -> string list -> int IO.t
val zremrangebylex : connection -> string -> StringBound.t -> StringBound.t -> int IO.t
val zremrangebyscore : connection -> string -> FloatBound.t -> FloatBound.t -> int IO.t
val zremrangebyrank : connection -> string -> int -> int -> int IO.t
val zcard : connection -> string -> int IO.t
val zincrby : connection -> string -> float -> string -> float IO.t
val zscore : connection -> string -> string -> float option IO.t
val zcount : connection -> string -> FloatBound.t -> FloatBound.t -> int IO.t
val zlexcount : connection -> string -> StringBound.t -> StringBound.t -> int IO.t
val zrank : connection -> string -> string -> int option IO.t
val zrevrank : connection -> string -> string -> int option IO.t
Transaction commands
val multi : connection -> unit IO.t
val exec : connection -> reply list IO.t
val discard : connection -> unit IO.t
val watch : connection -> string list -> unit IO.t
val unwatch : connection -> unit IO.t
val queue : (unit -> 'a IO.t) -> unit IO.t
Scripting commands
val script_load : connection -> string -> string IO.t
val eval : connection -> string -> string list -> string list -> reply IO.t
val evalsha : connection -> string -> string list -> string list -> reply IO.t
Server
val bgrewriteaof : connection -> unit IO.t
val bgsave : connection -> unit IO.t
val config_resetstat : connection -> unit IO.t
val dbsize : connection -> int IO.t
val flushall : connection -> unit IO.t
val flushdb : connection -> unit IO.t
val info : connection -> (string * string) list IO.t
val lastsave : connection -> float IO.t
val role : connection -> reply list IO.t
val save : connection -> unit IO.t
val shutdown : connection -> unit IO.t
OCaml

Innovation. Community. Security.