On this page:
redis-list-append!
redis-list-get
redis-list-insert!
redis-list-length
redis-list-pop-left!
redis-list-pop-right!
redis-list-prepend!
redis-list-ref
redis-list-remove!
redis-list-set!
redis-list-trim!
redis-sublist

11 List Commands🔗ℹ

procedure

(redis-list-append! client key value)

  (or/c #f exact-nonnegative-integer?)
  client : redis?
  key : redis-key/c
  value : redis-string/c
Appends value to the list at key, returning the new length of the list.
Commands used by this function: RPUSH

procedure

(redis-list-get client key)  redis-value/c

  client : redis?
  key : redis-key/c
An alias for redis-sublist that retrieves the whole list at key.
Commands used by this function: LRANGE

procedure

(redis-list-insert! client 
  key 
  value 
  #:after pivot/after 
  #:before pivot/before) 
  (or/c #f exact-nonnegative-integer?)
  client : redis?
  key : redis-key/c
  value : redis-string/c
  pivot/after : redis-string/c
  pivot/before : redis-string/c
Inserts value into the list at key #:before or #:after the first occurrence of pivot/before or pivot/after, respectively, returning the new size of the list.

If key is not a list, then #f is returned.

If both #:after and #:before are provided, an exn:fail:contract error is raised.
Commands used by this function: LINSERT

procedure

(redis-list-length client key)  exact-nonnegative-integer?

  client : redis?
  key : redis-key/c
Returns the length of the list at key.
Commands used by this function: LLEN

procedure

(redis-list-pop-left! client    
  key ...+    
  [#:block? block?    
  #:timeout timeout])  redis-value/c
  client : redis?
  key : redis-key/c
  block? : boolean? = #f
  timeout : exact-nonnegative-integer? = 0
Removes and then returns the first value from the list at key.

; LPOP a
(redis-list-pop-left! client "a")

When block? is #t, you can supply multiple keys to retrieve a value from. The function will wait up to timeout seconds for a value and the result will contain a list containing the popped key and its value.

; BLPOP a b 0
(redis-list-pop-left! client "a" "b" #:block? #t)
 
; BLPOP a b 1
(redis-list-pop-left! client "a" "b" #:block? #t #:timeout 1)
Commands used by this function: LPOP, BLPOP

procedure

(redis-list-pop-right! client    
  key ...+    
  [#:dest dest    
  #:block? block?    
  #:timeout timeout])  redis-value/c
  client : redis?
  key : redis-key/c
  dest : redis-key/c = #f
  block? : boolean? = #f
  timeout : exact-nonnegative-integer? = 0
Removes and then returns the last value from the list at key.

; RPOP a
(redis-list-pop-right! client "a")

When a dest is provided, the popped value is prepended to the list at dest. If multiple keys are provided along with a dest, then a contract error is raised.

; RPOPLPUSH a b
(redis-list-pop-right! client "a" #:dest "b")
 
; BRPOPLPUSH a b 0
(redis-list-pop-right! client "a" #:dest "b" #:block? #t)
 
; BRPOPLPUSH a b 1
(redis-list-pop-right! client "a" #:dest "b" #:block? #t #:timeout 1)

When block? is #t, you can supply multiple keys to retrieve a value from or you can specify a dest into which the popped value should be prepended. The former operation maps to an BRPOP and the latter to a BRPOPLPUSH command.

; BRPOP a b 0
(redis-list-pop-right! client "a" "b" #:block? #t)
 
; BRPOP a b 1
(redis-list-pop-right! client "a" "b" #:block? #t #:timeout 1)

In blocking mode, the function will wait up to timeout seconds for a value and the result will contain a list containing the popped key and its value.
Commands used by this function: RPOP, RPOPLPUSH, BRPOP, BRPOPLPUSH

procedure

(redis-list-prepend! client key value)

  (or/c #f exact-nonnegative-integer?)
  client : redis?
  key : redis-key/c
  value : redis-string/c
Prepends value to the list at key, returning the new length of the list.
Commands used by this function: LPUSH

procedure

(redis-list-ref client key index)  redis-value/c

  client : redis?
  key : redis-key/c
  index : exact-integer?
Returns the item at index in key or #f.
Commands used by this function: LINDEX

procedure

(redis-list-remove! client key count value)

  exact-nonnegative-integer?
  client : redis?
  key : redis-key/c
  count : exact-integer?
  value : redis-string/c
Removes up to count values from the list at key and returns the total number of items that were removed.
Commands used by this function: LREM

procedure

(redis-list-set! client key index value)  boolean?

  client : redis?
  key : redis-key/c
  index : exact-integer?
  value : redis-string/c
Sets the value at index in the list at key to value.
Commands used by this function: LSET

procedure

(redis-list-trim! client    
  key    
  [#:start start    
  #:stop stop])  boolean?
  client : redis?
  key : redis-key/c
  start : exact-integer? = 0
  stop : exact-integer? = -1
Removes any elements from the list not included in the inclusive range between start and end.
Commands used by this function: LTRIM

procedure

(redis-sublist client    
  key    
  [#:start start    
  #:stop stop])  redis-value/c
  client : redis?
  key : redis-key/c
  start : exact-integer? = 0
  stop : exact-integer? = -1
Returns the sublist between the inclusive indices start and end of the list at key.
Commands used by this function: LRANGE