Skip to content

Commit

Permalink
chore: add missing KeyExists and KeysExist docs snippets and correct …
Browse files Browse the repository at this point in the history
…docstrings (#1218)
  • Loading branch information
anitarua authored Apr 9, 2024
1 parent 3c1dc03 commit 0340d7a
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 2 deletions.
27 changes: 27 additions & 0 deletions examples/nodejs/cache/doc-example-files/doc-examples-js-apis.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,8 @@ import {
SetBatch,
ReadConcern,
CacheSetSample,
CacheKeyExists,
CacheKeysExist,
} from '@gomomento/sdk';
import * as crypto from 'crypto';

Expand Down Expand Up @@ -940,6 +942,28 @@ async function example_API_SortedSetRemoveElements(cacheClient: CacheClient, cac
}
}

async function example_API_KeyExists(cacheClient: CacheClient, cacheName: string) {
const result = await cacheClient.keyExists(cacheName, 'test-key');
if (result instanceof CacheKeyExists.Success) {
console.log("Does 'test-key' exists in the cache?", result.exists());
} else if (result instanceof CacheKeyExists.Error) {
throw new Error(
`An error occurred while attempting to call keyExists on key 'test-key' in cache '${cacheName}': ${result.errorCode()}: ${result.toString()}`
);
}
}

async function example_API_KeysExist(cacheClient: CacheClient, cacheName: string) {
const result = await cacheClient.keysExist(cacheName, ['test-key1', 'test-key2']);
if (result instanceof CacheKeysExist.Success) {
console.log("Do 'test-key1' and 'test-key2' exist in the cache?", result.exists());
} else if (result instanceof CacheKeysExist.Error) {
throw new Error(
`An error occurred while attempting to call keysExist on keys 'test-key1' and 'test-key2' in cache '${cacheName}': ${result.errorCode()}: ${result.toString()}`
);
}
}

function example_API_InstantiateAuthClient() {
new AuthClient({
credentialProvider: CredentialProvider.fromEnvironmentVariable({
Expand Down Expand Up @@ -1585,6 +1609,9 @@ async function main() {
await example_API_SortedSetRemoveElement(cacheClient, cacheName);
await example_API_SortedSetRemoveElements(cacheClient, cacheName);

await example_API_KeyExists(cacheClient, cacheName);
await example_API_KeysExist(cacheClient, cacheName);

example_API_InstantiateAuthClient();
const authClient = new AuthClient({
credentialProvider: CredentialProvider.fromEnvironmentVariable({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1531,7 +1531,7 @@ export abstract class AbstractCacheClient implements ICacheClient {
* @param {string} cacheName - The cache to look in.
* @param {string | Uint8Array} key - The key to look up.
* @returns {Promise<CacheKeyExists.Response>}
* {@link CacheKeyExists.Success} if key is found? or if key is checked?
* {@link CacheKeyExists.Success} returns boolean indicating whether the key was found.
* {@link CacheKeyExists.Error} on failure.
*/
public async keyExists(
Expand All @@ -1547,7 +1547,7 @@ export abstract class AbstractCacheClient implements ICacheClient {
* @param {string} cacheName - The cache to look in.
* @param {string[] | Uint8Array[]} keys - The keys to look up.
* @returns {Promise<CacheKeysExist.Response>}
* {@link CacheKeysExist.Success} if at least one key is found? if all keys checked?
* {@link CacheKeysExist.Success} returns list of booleans indicating whether each key was found.
* {@link CacheKeysExist.Error} on failure.
*/
public async keysExist(
Expand Down

0 comments on commit 0340d7a

Please sign in to comment.