Command: LIST.PUSH


Overview

The LIST.PUSH command inserts one or more elements at the beginning of a list associated with a specific key in the Fleare in-memory database. If the key does not exist, a new list is created. If the key exists but holds a non-list data type, an error is returned.

Command Name

LIST.PUSH

Description

This command prepends one or more elements to the beginning of a list stored at the given key.

  • If the key is not present, a new list is created and the elements are inserted.

  • If the key exists but does not represent a list, an error is thrown.

  • Elements can be of various types: strings, numbers, and valid JSON objects.

Use Cases

  • Prepend messages to a user notification list

  • Maintain a history of API call payloads

  • Store numeric logs with real-time data


Syntax

  LIST.PUSH <key> <element> [<element>...]
  
  • <key> : A valid string representing the name of the list.

  • <element> : One or more values to be inserted at the beginning of the list. These can be plain strings, numbers, or JSON strings.


Permissions

  • Read and write access to the specified key’s shard.

  • Permission to modify the Write-Ahead Log (WAL).


Examples

  localhost:9219> LIST.PUSH myKey "This is my first element"
Ok

localhost:9219> LIST.PUSH myKey '{"name":"John", "address": "kolkata"}' 10023.22
Ok
  
  localhost:9219> LIST.GET myKey
  
  Ok [
  "This is my first element",
  {
    "name": "John",
    "address": "kolkata"
  },
  10023.22
]
  
Inserting multiple string elements
  localhost:9219> LIST.PUSH fruits "apple" "banana" "cherry"
Ok
  
Inserting a mix of JSON, number, and string
  localhost:9219> LIST.PUSH data '{"user":"alice"}' 42 "note"
Ok
  
Inserting a JSON array as a single element
  localhost:9219> LIST.PUSH complexList '[1, 2, 3]'
Ok
  

Note: This inserts the whole array as a single element, not three separate values.

Example 4: Creating a list at a new key
  localhost:9219> LIST.PUSH newList "firstItem"
Ok
  
Unicode and special characters
  localhost:9219> LIST.PUSH greetings "こんにちは" "¡Hola!" "Cześć"
Ok
  
For LIST.GET fruits
  localhost:9219> LIST.GET fruits
Ok [
  "apple",
  "banana",
  "cherry"
]
  
For LIST.GET data
  localhost:9219> LIST.GET data
Ok [
  {
    "user": "alice"
  },
  42,
  "note"
]
  
For LIST.GET complexList
  localhost:9219> LIST.GET complexList
Ok [
  [
    1,
    2,
    3
  ]
]
  
For LIST.GET greetings
  localhost:9219> LIST.GET greetings
Ok [
  "こんにちは",
  "¡Hola!",
  "Cześć"
]
  

Behavior on Error

Scenario Error Message
No key provided ERR_INVALID_KEY: Key must be provided
Invalid characters in key ERR_INVALID_KEY: <detailed validation error>
Existing key is not a list ERR_INVALID_CHARACTER: <unmarshal error message>
Storage write failure Error returned from shard.M.Set()