On this page:
parse-redis-url
make-redis
redis?
redis-connected?
redis-connect!
redis-disconnect!
redis-key/  c
redis-key-type/  c
redis-string/  c
redis-value/  c

1 Clients🔗ℹ

Each client represents a single TCP connection to the Redis server.

procedure

(parse-redis-url s)  
(or/c #f string?)
(or/c #f string?)
string?
(integer-in 0 65535)
(integer-in 0 16)
  s : string?
Parses a Redis connection URL into 5 values:

Examples:
> (require redis)
> (parse-redis-url "redis://127.0.0.1")

#f

#f

"127.0.0.1"

6379

0

> (parse-redis-url "redis://127.0.0.1/1")

#f

#f

"127.0.0.1"

6379

1

> (parse-redis-url "redis://bogdan@127.0.0.1/1")

"bogdan"

#f

"127.0.0.1"

6379

1

> (parse-redis-url "redis://bogdan:pass@127.0.0.1/1")

"bogdan"

"pass"

"127.0.0.1"

6379

1

procedure

(make-redis [#:client-name client-name    
  #:unix-socket socket-path    
  #:host host    
  #:port port    
  #:timeout timeout    
  #:db db    
  #:username username    
  #:password password])  redis?
  client-name : string? = "racket-redis"
  socket-path : (or/c #f path-string?) = #f
  host : string? = "127.0.0.1"
  port : (integer-in 0 65536) = 6379
  timeout : exact-nonnegative-integer? = 5
  db : (integer-in 0 16) = 0
  username : (or/c #f non-empty-string?) = #f
  password : (or/c #f non-empty-string?) = #f
Creates a Redis client and immediately attempts to connect to the database at #:host and #:port. The #:timeout parameter controls the maximum amount of time (in milliseconds) the client will wait for any individual response from the database. If the #:unix-socket argument is provided, the connection is made to the socket at that path and #:host and #:port are ignored.

If the #:username argument is provided, then Redis 6.0 is assumed and an AUTH username password command will be sent to the server after a connection is established.

If the #:password argument is provided without a #:username, then an AUTH password command is emitted. This is compatible with all versions of Redis since 1.0.

Each client maps to an individual connection, therefore clients are not thread safe! See Connection Pooling.

Changed in version 1.0 of package redis-lib: Added support for #:unix-socket connections.

procedure

(redis? v)  boolean?

  v : any/c
Returns #t when v is a Redis client.

procedure

(redis-connected? client)  boolean?

  client : redis?
Returns #t when client appears to be connected to the database. Does not detect broken pipes.

procedure

(redis-connect! client)  void?

  client : redis?
Initiates a connection to the database. If one is already open, then the client is first disconnected before the new connection is made.

procedure

(redis-disconnect! client)  void?

  client : redis?
Disconnects from the server immediately and without sending a QUIT command. Does nothing if the client is already disconnected.

The contract for valid Redis keys.

value

redis-key-type/c : (or/c 'string 'list 'set 'zset 'hash 'stream)

The contract for valid Redis key types.

The contract for valid Redis byte strings. Anywhere you see this contract, keep in mind that any string value you provide will be converted to bytes? via string->bytes/utf-8.

The contract for Redis response values.