Main Content

isKey

Determine if the cache contains specified keys

Description

example

TF= isKey(c,keys)returns a logical1 (true)ifccontains the specified key, and returns a logical0 (false)otherwise.

Ifkeysis an array that specifies multiple keys, thenTFis a logical array of the same size, andTF{i}istrueifkeys{i}exists in cachec.

Examples

collapse all

Start a persistence service that uses Redis™ as the persistence provider. The service requires a connection name and an open port. Once the service is running, you can connect to the service using the connection name and create a cache.

ctrl = mps.cache.control('myRedisConnection','Redis','Port',4519); start(ctrl) c = mps.cache.connect('myCache','Connection','myRedisConnection');

Add keys and values to the cache.

put(c,'keyOne',10,'keyTwo',20,'keyThree',30,'keyFour',[400 500],'keyFive'魔法(5))

Determine if the cache contains specified keys.

TF = isKey(c,{'keyOne','keyTW00','keyTREE','key4','keyFive'})
TF = 1×5 logical array 1 0 0 0 1

Input Arguments

collapse all

A data cache represented by a persistence provider specific data cache object.

Currently, Redis and MATLAB®are the only supported persistence providers. Therefore, the cache objects will be of typemps.cache.RedisCacheormps.cache.MATFileCache.

Example:c

Keys to search for in the cache objectc, specified as a character vector, string, or cell array of character vectors or strings. To search for multiple keys, specifykeysas a cell array.

Example:{'keyOne','keyTW00','keyTREE','key4','keyFive'}

Output Arguments

collapse all

A logical array of the same size askeysindicating which specified keys were found in the data cache.TFhas a logical1 (true)ifccontains a key specified bykeys, and a logical0 (false)otherwise.

Version History

Introduced in R2018b