What steps should I do?

I’m using: SWI-Prolog version 7.6.4 for amd64

I want to write an gearman worker api or to adapt https://github.com/emacstheviking/gnuprolog-redisclient to swi-prolog.

What steps should I do?

Logtalk includes a Redis library supported in several Prolog systems including SWI-Prolog. This library is inspired by the Sean Charles GNU Prolog Redis client:

https://logtalk.org/library/redis_0.html

Also included in Logtalk is a redis example with unit tests for the library:

https://github.com/LogtalkDotOrg/logtalk3/tree/master/examples/redis

There are also two SWI-Prolog packs avaialble, resp and resp_parse, providing Redis protocol parsing and writing:

http://www.swi-prolog.org/pack/list?p=resp
http://www.swi-prolog.org/pack/list?p=resp_parse

1 Like

Hello Paulo,
I’ve decided to use Logtalk, configuration was a little heavy for me.
my program logtalk.lgt :
:-logtalk_load(library(redis_loader)).
:- object(suveica).
:-public([salvare/2]).
salvare(A,B):-
redis::connect(Connection),
redis::send(Connection, set(A,B), status(‘OK’)),
redis::disconnect(Connection).
:-end_object.

swilgt -g {logtalk}.
is working with some warnnings

  • Reference to unknown object: redis
    
  •   while compiling object suveica
    
  •   in file /home/alin/logtalk.lgt between lines 4-7
    

% [ /home/alin/logtalk/library/termp.lgt loaded ]
% [ /home/alin/logtalk/library/term.lgt loaded ]
% [ /home/alin/logtalk/library/atomic.lgt loaded ]
% [ /home/alin/logtalk/library/atom.lgt loaded ]
% [ /home/alin/logtalk/library/number.lgt loaded ]
% [ /home/alin/logtalk/library/float.lgt loaded ]
% [ /home/alin/logtalk/library/integer.lgt loaded ]
% [ /home/alin/logtalk/library/compound.lgt loaded ]
% [ /home/alin/logtalk/library/listp.lgt loaded ]
% [ /home/alin/logtalk/library/list.lgt loaded ]
% [ /home/alin/logtalk/library/type.lgt loaded ]
% [ /home/alin/logtalk/library/basic_types_loader.lgt loaded ]
% [ /home/alin/logtalk/library/redis.lgt loaded ]
% [ /home/alin/logtalk/library/redis_loader.lgt loaded ]
% [ /home/alin/logtalk.lgt loaded ]
% 1 compilation warning
?- suveica::salvare(‘A’,‘B’).
true.

?- ^D
% halt
alin@conta:~$ redis-cli
127.0.0.1:6379> get A
“B”

For now everything is ok, thanks, in the next step I will try to adapt some code from php.

PS: the link https://github.com/LogtalkDotOrg/logtalk3/tree/master/examples/redis is not working for me.
At first somehow I’ve manage to run tester.lgt, my redis content has gone, I blame the line send(Connection, flushall, status(OK1)) from test(flushall_flushdb_and_dbsize), I was crying like a baby because of that, nothing irreparable :slight_smile: after all it was my fault so in the learning process I will avoid tests .
Best regards :slight_smile:

Common practice is to define a loader.lgt file that loads your code together with all required libraries. For example, assuming your object is in a suveica.lgt file:

:- initialization((
    logtalk_load(library(redis_loader)),
    logtalk_load(suveica, [optimize(on)])
))

The logtalk_load/1-2 predicates are not directives and should not be used as such as that practice is not portable. The warning that you got as caused simply by loading the redis library from the same source file that’s using the redis object as the actual loading of the library will only occur after the whole file is compiled and loaded. With the loader.lgt file above, the warning would no longer occur.

The link to the example is gone that to that example, which contained only tests, being moved for the forthcoming 3.27.0 release to https://github.com/LogtalkDotOrg/logtalk3/tree/master/library/redis That release will also simplify loading of libraries (e.g. in the loader.lgt file above you will be able to use instead logtalk_load(redis(loader)).

1 Like