Skip to content

Commit

Permalink
No commit message
Browse files Browse the repository at this point in the history
  • Loading branch information
2 parents 4426e61 + 541406f commit 5b63ac0
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 3 deletions.
36 changes: 36 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 @@ -86,6 +86,8 @@ import {
PutWebhook,
RotateWebhookSecret,
GetWebhookSecret,
GetBatch,
SetBatch,
} from '@gomomento/sdk';
import {delay} from '../utils/time';

Expand Down Expand Up @@ -281,6 +283,38 @@ async function example_API_SetIfNotExists(cacheClient: CacheClient) {
}
}

async function example_API_SetBatch(cacheClient: CacheClient) {
const values = new Map<string, string>([
['abc', '123'],
['xyz', '321'],
['123', 'xyz'],
['321', 'abc'],
]);
const result = await cacheClient.setBatch('test-cache', values);
if (result instanceof SetBatch.Success) {
console.log('Keys and values stored successfully');
} else if (result instanceof SetBatch.Error) {
throw new Error(
`An error occurred while attempting to batch set in cache 'test-cache': ${result.errorCode()}: ${result.toString()}`
);
}
}

async function example_API_GetBatch(cacheClient: CacheClient) {
const keys = ['abc', 'xyz', '123', '321'];
const result = await cacheClient.getBatch('test-cache', keys);
if (result instanceof GetBatch.Success) {
const values = result.values();
for (const key of keys) {
console.log(`Retrieved value for key '${key}': ${values[key]}`);
}
} else if (result instanceof GetBatch.Error) {
throw new Error(
`An error occurred while attempting to batch get in cache 'test-cache': ${result.errorCode()}: ${result.toString()}`
);
}
}

async function example_API_ListFetch(cacheClient: CacheClient) {
await cacheClient.listConcatenateBack('test-cache', 'test-list', ['a', 'b', 'c']);
const result = await cacheClient.listFetch('test-cache', 'test-list');
Expand Down Expand Up @@ -1383,6 +1417,8 @@ async function main() {
await example_API_Increment(cacheClient);
await example_API_ItemGetType(cacheClient);
await example_API_SetIfNotExists(cacheClient);
await example_API_SetBatch(cacheClient);
await example_API_GetBatch(cacheClient);

await example_API_ListFetch(cacheClient);
await example_API_ListConcatenateBack(cacheClient);
Expand Down
7 changes: 5 additions & 2 deletions packages/client-sdk-nodejs/src/internal/cache-data-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -229,8 +229,11 @@ export class CacheDataClient implements IDataClient {
.watchConnectivityState(currentState, deadline, (error?: Error) => {
if (error) {
this.logger.error(
`Unable to connect to Momento: ${error.name}. currentState: ${currentState} :
Please contact Momento if this persists. `
`Unable to eagerly connect to Momento. Please contact Momento if this persists. currentState: ${currentState}, errorName: ${
error.name
} : errorMessage: ${error.message}, errorStack: ${
error.stack ? error.stack : 'Stack trace undefined'
}`
);
resolve();
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {CacheGet, CacheSet} from '@gomomento/sdk-core';
const {cacheClient, integrationTestCacheName} = SetupIntegrationTest();

describe('CacheClient', () => {
it('should send and receive 5mb messages', async () => {
it.skip('should send and receive 5mb messages', async () => {
const value = 'a'.repeat(5_000_000);
const key = '5mb';

Expand Down

0 comments on commit 5b63ac0

Please sign in to comment.