Skip to main content

Set API reference for Momento Cache

A set is a collection of elements, but each element can appear only once and order is not guaranteed.

Example: if your set contains [1, 2, 3] and you add 2, the set remains [1, 2, 3].

See Sets for more information on their usage.

Set methods

SetAddElement

Adds an element to a set. If the set item does not already exist, this method will create one.

NameTypeDescription
cacheNameStringName of the cache.
setNameStringName of the set item to be altered.
elementString | bytesElement to be added by this operation.
ttlCollectionTTL objectTTL for the set item in cache. This TTL takes precedence over the TTL used when initializing a cache connection client.
Method response object
  • Success
  • Error

See response objects for specific information.

SetAddElements

Adds multiple elements to a set item.

NameTypeDescription
cacheNameStringName of the cache.
setNameStringName of the set item to be altered.
elementsString[] | bytes[]Elements to be added by this operation.
ttlCollectionTTL objectTTL for the set item in cache. This TTL takes precedence over the TTL used when initializing a cache connection client.
Method response object
  • Success
  • Error

See response objects for specific information.

SetFetch

Gets a set item from a cache.

NameTypeDescription
cacheNameStringName of the cache.
setNameStringThe name of the set item to be retreived.
Method response object

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

  • Hit
    • valueSetBytes(): bytes[]
    • valueSetString(): string[]
    • toString(): string
  • Miss
  • Error

See response objects for specific information.

SetRemoveElement

Removes a single element from an existing set item.

NameTypeDescription
cacheNameStringName of the cache.
setNameStringName of the set item to be altered.
elementString | bytesElement to be removed by this operation.
Method response object
  • Success
  • Error

See response objects for specific information.

SetRemoveElements

Removes multiple elements from an existing set item.

NameTypeDescription
cacheNameStringName of the cache.
setNameStringName of the set item to be altered.
elementString | bytesElement to be removed by this operation.
Method response object
  • Success
  • Error

See response objects for specific information.

SetContainsElement

Checks if a provided element is in the given set.

NameTypeDescription
cacheNameStringName of the cache.
setNameStringName of the set item.
elementString | bytesName of the element to check existence of.
Method response object

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

  • Hit
    • containsElement(): bool
  • Miss
  • Error

See response objects for specific information.

SetContainsElements

Checks if provided elements are in the given set.

NameTypeDescription
cacheNameStringName of the cache.
setNameStringName of the set item.
elementsString[] \ bytes
Method response object

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

  • Hit
    • containsElements(): bool[]
  • Miss
  • Error

See response objects for specific information.