1/*  File:    redis/tilde.pl
    2    Author:  Roy Ratcliffe
    3    Created: Jun 26 2026
    4    Purpose: Redis tilde operations
    5
    6Copyright (c) 2026, Roy Ratcliffe, Northumberland, United Kingdom
    7
    8Permission is hereby granted, free of charge,  to any person obtaining a
    9copy  of  this  software  and    associated   documentation  files  (the
   10"Software"), to deal in  the   Software  without  restriction, including
   11without limitation the rights to  use,   copy,  modify,  merge, publish,
   12distribute, sublicense, and/or sell  copies  of   the  Software,  and to
   13permit persons to whom the Software is   furnished  to do so, subject to
   14the following conditions:
   15
   16    The above copyright notice and this permission notice shall be
   17    included in all copies or substantial portions of the Software.
   18
   19THE SOFTWARE IS PROVIDED "AS IS", WITHOUT  WARRANTY OF ANY KIND, EXPRESS
   20OR  IMPLIED,  INCLUDING  BUT  NOT   LIMITED    TO   THE   WARRANTIES  OF
   21MERCHANTABILITY, FITNESS FOR A PARTICULAR   PURPOSE AND NONINFRINGEMENT.
   22IN NO EVENT SHALL THE AUTHORS  OR   COPYRIGHT  HOLDERS BE LIABLE FOR ANY
   23CLAIM, DAMAGES OR OTHER LIABILITY,  WHETHER   IN  AN ACTION OF CONTRACT,
   24TORT OR OTHERWISE, ARISING FROM,  OUT  OF   OR  IN  CONNECTION  WITH THE
   25SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
   26
   27*/
   28
   29:- module(redis_tilde,
   30          [ op(440, xfx, ~>),
   31            op(550, fx, ~),
   32            (~>)/2,             % +Request, -Reply
   33            (~)/1               % +PipeLine
   34          ]).   35:- autoload(library(redis), [redis/3, redis/2]).   36:- use_module(library(settings), [setting/4, setting/2]).   37
   38:- setting(server, atom, default, 'Server to use for Redis tilde operations').

Redis Tilde Operations

This module provides operators for interacting with a Redis server using the tilde syntax. The ~> operator is used to send a request to the Redis server and retrieve a reply, while the ~ operator is used to send a pipeline of requests.

The Redis server to use for these operations can be configured using the server setting. By default, it is set to default, but it can be changed to any valid Redis server identifier.

Example Usage

Read the current time from the Redis server and convert it to seconds:

?- [library(redis/tilde)].
?- time ~> [S, US], Time is S + (US / 1e6).

The Redis TIME command returns the current server time as a two-element list, where the first element is the number of seconds since the epoch and the second element is the number of microseconds. The above example retrieves this information and calculates the total time in seconds.

author
- Roy Ratcliffe
version
- 1.0
license
- MIT
   71:- op(440, xfx, ~>), op(550, fx, ~).
 ~>(+Request, -Reply) is semidet
Sends a request to the Redis server and retrieves the reply. Uses the Redis server specified in the settings.
Arguments:
Request- The request to send to the Redis server.
Reply- The reply received from the Redis server.
   82~>(Request, Reply) :- setting(server, Redis), redis(Redis, Request, Reply).
 ~ +PipeLine is det
Sends a pipeline of requests to the Redis server.
Arguments:
PipeLine- The pipeline of requests to send to the Redis server.
   90~(PipeLine) :- setting(server, Redis), redis(Redis, PipeLine)