Lists are very powerful data type in Redis.

  • Insert of values: LPUSH, LPUSHX, RPUSH, RPUSHX
  • Change of existing value: LSET
  • get existing values: LRANGE
  • info about list: LLEN

 

LPUSH:

  • prepends values (adds them at the beginning) in list
  • if list does not exist it creates it
  • syntax:
    • LPUSH list-name value [value2 value3 …]
      • returns total number of values in list after operation: (integer) xx
      • if more values are added then last value will be at the beginning of the list

LPUSHX:

  • similar to LPUSH but prepends values only if list exists
  • if list does not exist returns 0 and list is NOT created

RPUSH:

  • appends values (adds them at the end) in list
  • if list does not exist it creates it
  • syntax:
    • RPUSH list-name value [value2 value3 …]
      • returns total number of values in list after operation: (integer) xx
      • if more values are added then last value will be at the end of the list

RPUSHX:

  • limilar to LPUSHX – list MUST exist

LSET:

  • sets value in list at specified index position – index MUST exist in list!
  • syntax:
    • LSET list-name index value

LRANGE:

  • shows values in list – in specified range of indexes
  • syntax:
    • LRANGE list-name start end

LLEN:

  • returns number of values in list: (integer) 4