メインコンテンツまでスキップ

List API reference for Momento Cache

This page details the Momento API methods for the list collection data types.

List methods

ListFetch

Gets a list item from a cache, with optional slices.

NameTypeDescription
cacheNameStringName of the cache.
listNameStringThe name of the list item to be retrieved.
startIndexNumberThe starting inclusive element of the list to fetch. Default is 0. This argument is optional.
endIndexNumberThe ending exclusive element of the list to fetch. Default is end of list. This argument is optional.
Method response object

The response object for ListFetch returns three possible options, a cache hit, miss, or an error.

  • Hit
    • valueListBytes(): bytes[]
    • valueListString(): string[]
    • toString(): string - Display a truncated valueListString(). See truncation.
  • Miss
  • Error

See response objects for specific information.

ListConcatenateBack

Appends the supplied list to the end of an existing list item.

Example:

If you have [1, 2, 3] and listConcatenateBack [4, 5, 6] you will have [1, 2, 3, 4, 5, 6].

NameTypeDescription
cacheNameStringName of the cache.
listNameStringName of the list item to be set.
valuesString[] | bytes[]Values to be added as elements to the list item.
ttlCollectionTTL objectTTL for the list item in cache. This TTL takes precedence over the TTL used when initializing a cache client connection object.
truncateFrontToSizeNumberSee truncate to size.
Method response object
  • Success
    • listLength(): number - the new length of the list
    • toString(): string - add the listLength
  • Error

See response objects for specific information.

ListConcatenateFront

Appends the supplied list to the front of an existing list item.

Example:

If you have [1, 2, 3] and listConcatenateFront [4, 5, 6] you will have [4, 5, 6, 1, 2, 3].

NameTypeDescription
cacheNameStringName of the cache.
listNameStringName of the list item to be set.
valuesString[] | bytes[]Values to be added as elements to the list item.
ttlCollectionTTL objectTTL for the list item in cache. This TTL takes precedence over the TTL used when initializing a cache client.
truncateBackToSizeNumberSee truncate to size.
Method response object
  • Success
    • listLength(): number - the new length of the list item
    • toString(): string - add the listLength
  • Error

See response objects for specific information.

ListLength

Get the length of an existing list item

NameTypeDescription
cacheNameStringName of the cache.
listNameStringName of the list item to be checked.
Method response object
  • Hit
    • length(): number
    • toString(): include the length
  • Miss
  • Error

See response objects for specific information.

ListPopBack

Remove and return the last element from a list item.

NameTypeDescription
cacheNameStringName of the cache.
listNameStringName of the list item to be retreived.
Method response object
  • Hit
    • valueString(): string
    • valueBytes(): bytes
    • toString(): truncated valueString()
  • Miss
  • Error

See response objects for specific information.

ListPopFront

Remove and return the first element from a list item.

NameTypeDescription
cacheNameStringName of the cache.
listNameStringName of the list item to be retreived.
Method response object
  • Hit
    • valueString(): string
    • valueBytes(): bytes
    • toString(): truncated valueString()
  • Miss
  • Error

See response objects for specific information.

ListPushBack

Push a value to the end of a list item. This is exactly like passing just one value to ListConcatenateBack.

NameTypeDescription
cacheNameStringName of the cache.
listNameStringName of the list to be set.
valueString | bytesValue to be added.
ttlCollectionTTL objectTTL for the list item in cache. This TTL takes precedence over the TTL used when initializing a cache connection client.
truncateBackToSizeNumberSee truncate to size.
Method response object
  • Success
    • listLength(): number - the new length of the list item
    • toString(): string - add the listLength
  • Error

See response objects for specific information.

ListPushFront

Push a value to the beginning of a list item. Just like ListPushBack, but to the front.

NameTypeDescription
cacheNameStringName of the cache.
listNameStringName of the list to be set.
valueString | bytesValue to be added to the list item by the operation.
ttlCollectionTTL objectTTL for the list item in cache. This TTL takes precedence over the TTL used when initializing a cache connection client.
truncateBackToSizeNumberSee truncate to size.
Method response object
  • Success
    • listLength(): number - the new length of the list
    • toString(): string - add the listLength
  • Error

See response objects for specific information.

ListRemoveValue

Remove all elements in a list item equal to a particular value.

Examples

  • If you have the list ['up', 'up', 'down', 'down', 'left', 'right'] and remove ‘up’ the list will be ['down', 'down', 'left', 'right']
NameTypeDescription
cacheNameStringName of the cache.
listNameStringName of the list item to be set.
valueString | bytesValue to be added to the list item by the operation.
Method response object

Responses

  • Success - even if the value does not exist
  • Error

See response objects for specific information.

ListRetain

Retains only slice of the list where the start is inclusive and the end is exclusive. The items outside of this range will be dropped from the list.

Example: For the specified list, start at index 4 (the startIndex) and keep the next five elements, end at index 10 (the endIndex). Discard all other elements in the list. In this example, elements at position 0-3 and 9 or higher are dropped.

NameTypeDescription
cacheNameStringName of the cache.
listNameStringName of the list item to be set.
startIndexNumberThe starting inclusive element of the list to retain. Default is 0.
endIndexNumberThe ending exclusive element of the list to retain. Default is end of list.
ttlCollectionTTL objectTTL for the list item in cache. This TTL takes precedence over the TTL used when initializing a cache connection client.
Method response object

Responses

  • Success - even if the value does not exist
  • Error

See response objects for specific information.

Truncate to size

ListConcatenate and ListPush type API calls all have truncation options. If after adding their elements the list exceeds this size, this list will be truncated.

  • Example: If the list is [1, 2, 3] and you ListConcatenateBack [4, 5, 6] with truncateFrontToSize: 5 the list will be truncated to [2, 3, 4, 5, 6] and the response ListLength will be 5.

  • Example: If the list is [1, 2, 3] and you ListConcatenateBack [4, 5, 6] with truncateFrontToSize: 10 the list will not be truncated. It will be [1, 2, 3, 4, 5, 6]