On this page:
redis:   bindings for Redis

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()))



$ python test.py


and the equivalent benchmark in Racket CS:

$ cat <<EOF >test.rkt

#lang racket/base


(require redis)


(define c (make-redis))



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

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



$ racket test.rkt

cpu time: 367 real time: 565 gc time: 21

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.