Main Content

isKey

Determine if the cache contains specified keys

Description

TF = isKey(c,keys) returns a logical 1 (true) if c contains the specified key, and returns a logical 0 (false) otherwise.

If keys is an array that specifies multiple keys, then TF is a logical array of the same size, and TF{i} is true if keys{i} exists in cache c.

example

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',magic(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 type mps.cache.RedisCache or mps.cache.MATFileCache.

Example: c

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

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

Output Arguments

collapse all

A logical array of the same size as keys indicating which specified keys were found in the data cache. TF has a logical 1 (true) if c contains a key specified by keys, and a logical 0 (false) otherwise.

Version History

Introduced in R2018b

See Also

| | |

Topics