On this page:
redis:   bindings for Redis
7.4

redis: bindings for Redis

Bogdan Popa <bogdan@defn.io>

 (require redis) package: redis-lib

This package provides up-to-date bindings to the Redis database that are idiomatic and fast. Every exposed function has a contract (some are even quite complex!) and the library is about as fast as hiredis (written in C) + redis-py.

Here is a microbenchmark in Python:

$ cat <<EOF >test.py

import redis

import timeit

 

c = redis.Redis()

 

print(timeit.timeit("c.set('a', '1')", number=10000, globals=globals()))

EOF

 

$ python test.py

0.5616942420000001

and the equivalent benchmark in Racket:

$ cat <<EOF >test.rkt

#lang racket/base

 

(require redis)

 

(define c (make-redis))

 

(time

 (for ([_ (in-range 10000)])

   (redis-bytes-set! c "a" "1")))

EOF

 

$ racket test.rkt

cpu time: 506 real time: 590 gc time: 0

Obviously, real world use cases will have different characteristics, but the point is that the library won’t get in your way.

The functions in this package are named differently from their Redis counterparts to avoid confusion as much as possible. The rule is that when a function name is ambiguous with regards to the type of value it operates on, then it must contain the type in its name.

For example, rather than exposing a function called redis-get for looking up keys, we expose redis-bytes-get so that it is clear to the user that they’re about to receive one or more byte strings. On the other hand, redis-rename! doesn’t need to be prefixed, because the operation can only refer to renaming a key.

If you’re looking to run a particular command but are not sure what the associated function’s name is, simply search this documentation for that command. The documentation for each function names the commands said function relies on.