Typing¶
coredis.typing
Input types¶
The API uses the following type aliases to describe the unions of acceptable types for parameters to redis command wrappers.
- ValueT¶
Represents the different python primitives that are accepted as input parameters for commands that can be used with loosely defined types. These are encoded using the configured encoding before being transmitted.
- StringT¶
The canonical type used for input parameters that represent “strings” that are transmitted to redis.
For methods that accept non optional variable number of keys or values, coredis does NOT
use positional or keyword varargs and expects a “container” to be passed in for the argument.
Common examples of such APIs are delete()
and exists()
.
Instead of accepting Iterable
, a union of select containers from the standard
library are accepted via Parameters
.
- Parameters¶
Restricted union of container types accepted as arguments to apis that accept a variable number values for an argument (such as keys, values). This is used instead of
typing.Iterable
as the latter allowsstr
to be passed in as valid values forIterable[str]
orbytes
to be passed in as a valid value forIterable[bytes]
which is never the actual expectation in the scope of coredis. For example:def length(values: Parameters[ValueT]) -> int: return len(list(values)) length(["1", 2, 3, 4]) # valid length({"1", 2, 3, 4}) # valid length(("1", 2, 3, 4)) # valid length({"1": 2}.keys()) # valid length({"1": 2}.values()) # valid length(map(str, range(10))) # valid length({"1": 2}) # invalid length("123") # invalid length(b"123") # invalid
alias of
list
[T_co
] |Set
[T_co
] |tuple
[T_co
, …] |ValuesView
[T_co
] |Iterator
[T_co
]
Redis Response (RESP) descriptions¶
The follow two types describe the total representation of parsed responses from the redis serialization protocol(s) (RESP & RESP3) (See Redis Response for more details).
In most cases these are not exposed through the client API and are only meant for internal pre-validation before the parsed response is transformed or narrowed to the returns documented in the client API at Clients.
- ResponsePrimitive¶
Mapping of primitives returned by redis
- ResponseType¶
alias of
str
|bytes
|int
|float
|bool
|None
|list
[Any
] |MutableSet
[str
|bytes
|int
|float
|bool
|None
|tuple
[str
|bytes
|int
|float
|bool
|None
, …] |frozenset
[str
|bytes
|int
|float
|bool
|None
]] |dict
[str
|bytes
|int
|float
|bool
|None
|tuple
[str
|bytes
|int
|float
|bool
|None
, …] |frozenset
[str
|bytes
|int
|float
|bool
|None
],Any
] |RedisError
Response Types¶
In most cases the API returns native python types mapped as closely as possible
to the response from redis. The responses are normalized across RESP versions 2
and 3
to maintain a consistent signature (Most notable example of this is dictionary
In certain cases these are “lightly” typed using NamedTuple
or TypedDict
for ease of documentation and in the case of “tuples”
returned by redis - to avoid errors in indexing.
- class ClientInfo¶
Bases:
TypedDict
Response from CLIENT INFO
id
: a unique 64-bit client IDaddr
: address/port of the clientladdr
: address/port of local address client connected to (bind address)fd
: file descriptor corresponding to the socketname
: the name set by the client with CLIENT SETNAMEage
: total duration of the connection in secondsidle
: idle time of the connection in secondsflags
: client flagsdb
: current database IDsub
: number of channel subscriptionspsub
: number of pattern matching subscriptionsmulti
: number of commands in a MULTI/EXEC contextqbuf
: query buffer length (0 means no query pending)qbuf-free
: free space of the query buffer (0 means the buffer is full)argv-mem
: incomplete arguments for the next command (already extracted from query buffer)multi-mem
: memory is used up by buffered multi commands. Added in Redis 7.0obl
: output buffer lengtholl
: output list length (replies are queued in this list when the buffer is full)omem
: output buffer memory usagetot-mem
: total memory consumed by this client in its various buffersevents
: file descriptor eventscmd
: last command playeduser
: the authenticated username of the clientredir
: client id of current client tracking redirectionresp
: client RESP protocol version. Added in Redis 7.0
- ScriptFlag¶
Script/Function flags See: https://redis.io/topics/lua-api#a-namescriptflagsa-script-flags
alias of
Literal
[‘no-writes’, ‘allow-oom’, ‘allow-stale’, ‘no-cluster’, b’no-writes’, b’allow-oom’, b’allow-stale’, b’no-cluster’]
- class FunctionDefinition[source]¶
Bases:
TypedDict
Function definition as returned by FUNCTION LIST
- flags: Set[ScriptFlag]¶
function flags
- class LibraryDefinition[source]¶
Bases:
TypedDict
Library definition as returned by FUNCTION LIST
- engine: Literal['LUA']¶
the engine used by the library
- functions: Dict[StringT, FunctionDefinition]¶
Mapping of function names to functions in the library
- class ScoredMember(member: StringT, score: float)[source]¶
Bases:
NamedTuple
Member of a sorted set
- class GeoCoordinates(longitude: float, latitude: float)[source]¶
Bases:
NamedTuple
A longitude/latitude pair identifying a location
- class GeoSearchResult(name: StringT, distance: float | None, geohash: int | None, coordinates: GeoCoordinates | None)[source]¶
Bases:
NamedTuple
Structure of a geo query
- coordinates: GeoCoordinates | None¶
Lat/Lon
- class Command¶
Bases:
TypedDict
Definition of a redis command See: https://redis.io/topics/key-specs
name
: This is the command’s name in lowercasearity
: Arity is the number of arguments a command expects.flags
: See https://redis.io/commands/command#flagsfirst-key
: This value identifies the position of the command’s first key name argumenlast-key
: This value identifies the position of the command’s last key name argumentstep
: This value is the step, or increment, between the first key and last key values where the keys are.acl-categories
: This is an array of simple strings that are the ACL categories to which the command belongstips
: Helpful information about the commandkey-specification
: This is an array consisting of the command’s key specificationssub-commands
: This is an array containing all of the command’s subcommands, if any
- class RoleInfo(role: str, offset: int | None = None, status: str | None = None, slaves: Tuple[Dict[str, str | int], ...] | None = None, masters: Tuple[str, ...] | None = None)[source]¶
Bases:
NamedTuple
Redis instance role information
- class StreamEntry(identifier: StringT, field_values: OrderedDict[StringT, StringT])[source]¶
Bases:
NamedTuple
Structure representing an entry in a redis stream
- class StreamInfo¶
Bases:
TypedDict
Details of a stream See: https://redis.io/commands/xinfo-stream
- class StreamPending(pending: int, minimum_identifier: StringT, maximum_identifier: StringT, consumers: OrderedDict[StringT, int])[source]¶
Bases:
NamedTuple
Summary response from XPENDING
- class StreamPendingExt(identifier: StringT, consumer: StringT, idle: int, delivered: int)[source]¶
Bases:
NamedTuple
Extended form response from XPENDING
- class SlowLogInfo(id, start_time, duration, command, client_addr, client_name)[source]¶
Bases:
NamedTuple
- class LCSMatch(first: Tuple[int, int], second: Tuple[int, int], length: int | None)[source]¶
Bases:
NamedTuple
An instance of an LCS match
- class LCSResult(matches: Tuple[LCSMatch, ...], length: int)[source]¶
Bases:
NamedTuple
Results from LCS
- class MonitorResult(time: datetime, db: int, client_addr: tuple[str, int] | str | None, client_type: Literal['tcp', 'unix', 'lua'], command: str, args: tuple[str, ...] | None)[source]¶
Bases:
object
Details of issued commands received by the client when listening with the MONITOR command
- class PubSubMessage[source]¶
Bases:
TypedDict
- type: str¶
One of the following:
- subscribe
Server response when a client subscribes to a channel(s)
- unsubscribe
Server response when a client unsubscribes from a channel(s)
- psubscribe
Server response when a client subscribes to a pattern(s)
- punsubscribe
Server response when a client unsubscribes from a pattern(s)
- ssubscribe
Server response when a client subscribes to a shard channel(s)
- sunsubscribe
Server response when a client unsubscribes from a shard channel(s)
- message
A message received from subscribing to a channel
- pmessage
A message received from subscribing to a pattern
- channel: StringT¶
The channel subscribed to or unsubscribed from or the channel a message was published to
- pattern: StringT | None¶
The pattern that was subscribed to or unsubscribed from or to which a received message was routed to
- data: int | StringT¶
If
type
is one of{message, pmessage}
this is the actual published messageIf
type
is one of{subscribe, psubscribe, ssubscribe, unsubscribe, punsubscribe, sunsubscribe}
this will be anint
corresponding to the number of channels and patterns that the connection is currently subscribed to.
coredis.modules.response.types
- class SearchDocument(id: StringT, score: float | None, score_explanation: list[AnyStr] | None, payload: StringT | None, sortkeys: StringT | None, properties: dict[AnyStr, ResponseType])[source]¶
Bases:
Generic
Search document as returned by FT.SEARCH
- score_explanation: List[AnyStr] | None¶
Explanation of the score if the
explainscore
option was used
- properties: Dict[AnyStr, ResponseType]¶
Mapping of properties returned for the document
- class SearchResult(total: int, documents: tuple[SearchDocument, ...])[source]¶
Bases:
Generic
Search results as returned by FT.SEARCH
- documents: tuple[SearchDocument, ...]¶
The documents returned by the query
- class SearchAggregationResult(results: list[dict[StringT, ResponseType]], cursor: int | None)[source]¶
Bases:
Generic
Search aggregations as returned by FT.AGGREGATE
- results: List[Dict[StringT, ResponseType]]¶
The aggregation results
- class AutocompleteSuggestion(string: AnyStr, score: float | None, payload: AnyStr | None)[source]¶
Bases:
Generic
Autocomplete suggestion as returned by FT.SUGGET
- string: AnyStr¶
the suggestion string
- JsonType¶
Type alias for valid python types that can be represented as json
alias of
str
|int
|float
|bool
|None
|dict
[str
,Any
] |list
[Any
]
- class GraphNode(id: int, labels: set[AnyStr], properties: dict[AnyStr, ResponseType])[source]¶
Bases:
Generic
Representation of a graph node
- labels: Set[AnyStr]¶
A set of labels associated with the node
- properties: Dict[AnyStr, ResponseType]¶
Mapping of property names to values
- class GraphRelation(id: int, type: AnyStr, src_node: int, destination_node: int, properties: dict[AnyStr, ResponseType])[source]¶
Bases:
Generic
Representation of a relation between two nodes
- type: AnyStr¶
Relation type
- properties: Dict[AnyStr, ResponseType]¶
Mapping of all properties the relation possesses
- class GraphPath(nodes: list[GraphNode], relations: list[GraphRelation])[source]¶
Bases:
Generic
Representation of a graph path
- relations: list[GraphRelation]¶
The relations in the path
- property path: tuple[GraphNode | GraphRelation, ...]¶
The path as a tuple of nodes and relations
- class GraphQueryResult(header: tuple[AnyStr, ...], result_set: tuple[ResponsePrimitive | list[ResponsePrimitive | GraphNode | GraphRelation | GraphPath], ...], stats: dict[str, ResponsePrimitive])[source]¶
Bases:
Generic
Response from GRAPH.QUERY
- header: Tuple[AnyStr, ...]¶
List of entries in the response header
- result_set: Tuple[ResponsePrimitive | List[ResponsePrimitive | GraphNode[AnyStr] | GraphRelation[AnyStr] | GraphPath[AnyStr]], ...]¶
The result set from the query
- stats: Dict[str, ResponsePrimitive]¶
Mapping of query statistics
- class GraphSlowLogInfo(start_time: int, command: StringT, query: StringT, duration: float)[source]¶
Bases:
NamedTuple
Response from GRAPH.SLOWLOG