aconchillo / guile-redis

Redis module for Guile
GNU General Public License v3.0
29 stars 4 forks source link
guile redis scheme

guile-redis

GNU Guile 2.2 GNU Guile 3.0

guile-redis is a Guile module for the Redis key-value data store. It provides all commands up to Redis 7.0 and supports multiple commands, pipelining and Pub/Sub.

Installation

Download the latest tarball and untar it:

If you are cloning the repository make sure you run this first:

$ autoreconf -vif

Then, run the typical sequence:

$ ./configure --prefix=<guile-prefix>
$ make
$ sudo make install

Where <guile-prefix> should preferably be the same as your system Guile installation directory (e.g. /usr).

If everything installed successfully you should be up and running:

$ guile
scheme@(guile-user)> (use-modules (redis))
scheme@(guile-user)>

It might be that you installed guile-redis somewhere differently than your system's Guile. If so, you need to indicate Guile where to find guile-redis, for example:

$ GUILE_LOAD_PATH=/usr/local/share/guile/site guile

Usage

Procedures

The main interface to the Redis server is really simply. It consists on three procedures, the most important one being /redis-send/ which basically sends commands to the server.

Redis commands

All commands in guile-redis are defined with lower-case and hyphenated in the case of commands that have two or more words. For example, the command "CLIENT LIST" is defined as client-list.

The commands take exaclty the same arguments as defined in the Redis manual and all the arguments (if any) need to be passed as a single list. For example:

(bitfield '(mykey INCRBY i5 100 1 GET u4 0))

Note that, internally, guile-redis will automatically convert symbols and numbers to strings before sending the command to Redis.

Redis Pub/Sub

guile-redis >= 2.0.0 adds proper support for Redis Pub/Sub. The Pub/Sub commands don't follow the approach of the rest of commands (except the PUBSUB command), instead there's a procedure for each of them:

Examples

> (use-modules (redis))
> (define conn (redis-connect))
> (redis-send conn (ping))
"PONG"
> (redis-send conn (list (ping) (ping '("hello from guile-redis"))))
("PONG" "hello from guile-redis")
> (redis-send conn (mset '(hello "world" foo "bar")))
"OK"
> (redis-send conn (mget '(hello foo)))
("world" "bar")
> (redis-subscribe conn '("news"))
(("news" . 1))
> (redis-publish conn "news" "hello from guile-redis")
1
> (redis-subscribe-read conn)
"news"
"hello from guile-redis"
> (redis-unsubscribe conn)
(("news" . 0))
> (redis-close conn)

License

Copyright (C) 2013-2022 Aleix Conchillo Flaque aconchillo@gmail.com

This file is part of guile-redis.

guile-redis is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version.

guile-redis is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with guile-redis. If not, see https://www.gnu.org/licenses/.