Did you know ... Search Documentation:
Pack canny_tudor -- prolog/redis/xgroup.pl
PublicShow source

Wraps Redis's `XGROUP CREATE` command with xgroup_create/3 and xgroup_create/4. Translates Prolog options into Redis command arguments, extracts stream id/1 (default $), handles make_stream(true) and entries_read/1, and captures optional reply. Behaves idempotently by catching BUSYGROUP errors.

 xgroup_create(+Redis:atom, +Key:atom, +Group:atom) is det
 xgroup_create(+Redis:atom, +Key:atom, +Group:atom, +Options:list) is det
Creates a consumer group for a Redis stream if it does not already exist. This predicate attempts to create a consumer group named Group for the stream identified by Key in the Redis instance specified by Redis. If the consumer group already exists, the predicate succeeds without error.

The predicate can be called with or without the Options argument. If Options is not provided, it defaults to an empty list. The Options argument allows for additional customisation of the command execution, such as specifying the ID for the consumer group, whether to create the stream if it does not exist, and how many entries to read when the group is created.

Example usage:

% Create a consumer group named "mygroup" for the stream "mystream" in
% the Redis instance "myredis".
?- xgroup_create(myredis, mystream, mygroup).

Delete a consumer group named "mygroup" for the stream "mystream" in the Redis instance "myredis" using:

?- redis(myredis, xgroup(destroy, mystream, mygroup), _).
Arguments:
Redis- The Redis instance identifier.
Key- The Redis stream key.
Group- The name of the consumer group to create.
Options- A list of options to customise the command execution.

Supported options include:

  • id(Id) specifies the ID for the consumer group. Defaults to '$' (the latest entry in the stream).
  • make_stream(true) specifies that the stream should be created if it does not already exist.
  • entries_read(EntriesRead) specifies the number of entries to read when the group is created.
  • reply(Reply) specifies a variable to unify with the command's reply. If not provided, the reply is ignored.

Undocumented predicates

The following predicates are exported, but not or incorrectly documented.

 xgroup_create(Arg1, Arg2, Arg3, Arg4)