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').
71:- op(440, xfx, ~>), op(550, fx, ~).
82~>(Request, Reply) :- setting(server, Redis), redis(Redis, Request, Reply).
90~(PipeLine) :- setting(server, Redis), redis(Redis, PipeLine)
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
serversetting. By default, it is set todefault, 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:
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.