Thank you for taking your time to contribute to our Momento @redis/client wrapper!
This guide will provide you information to start your own development and testing.
Happy coding 💃
- Node version 14 or higher is required
- A Momento Auth Token is required, you can generate one using the Momento CLI
# Install dependencies
npm install
npm run build
npm run lint
TEST_AUTH_TOKEN=<YOUR_AUTH_TOKEN> npm run test-momento
First run Redis either natively, run Redis in a Docker container, or do your development in a devcontainer. Here is an example of running Redis in a Docker container:
docker run -it -p 6379:6379 redis
Then run the tests:
npm run test-redis
This assumes the Redis server is running on localhost:6379
. If using a different host and port, modify the above command as follows:
TEST_REDIS_HOST=<HOST> TEST_REDIS_PORT=<PORT> npm run test-redis
By running Redis on the local host, you can use the redis-cli
to inspect the state of the Redis server as well as interactively debug the tests. We have also included a devcontainer config which will mount the entire coding environment into a Docker container, including the Redis server. See .devcontainer
for more details.
This will run both the integration tests against Momento and Redis. As above, we assume the Redis server is running on localhost:6379
.
TEST_AUTH_TOKEN=<YOUR_AUTH_TOKEN> npm run test
Each method optionally supports taking CommandOptions
as the first argument.
This means that the types for the set
method are:
function set<T extends ClientCommandOptions>(
...args:
| [
key: RedisCommandArgument,
value: RedisCommandArgument | number,
options?: SetOptions
]
| [
commandOptions: CommandOptions<T>,
key: RedisCommandArgument,
value: RedisCommandArgument | number,
options?: SetOptions
]
);
// client/lib/client/index.ts
export interface ClientCommandOptions extends QueueCommandOptions {
isolated?: boolean;
}
// client/lib/client/command-queue.ts
export interface QueueCommandOptions {
asap?: boolean;
chainId?: symbol;
signal?: AbortSignal;
returnBuffers?: boolean;
}
When a user invokes a command using node-redis, a command object is placed on a queue for execution. The commands are sent over the network FIFO.
isolated
: instead of queuing the commands with the main client, send the command through a dedicated client, from a pool of dedicated (isolated) clientsasap
: the command is not placed on a queue but instead immediately sent.chainId
: logical ID the command belongs to, for grouping commandssignal
: allows for aborting a commandreturnBuffers
: boolean to return strings as buffers
The only property relevant to us is returnBuffers
. This decides whether the RESP decoder decodes simple string
or bulk string
replies as Buffer
s. Replies of other data types (error, integer, array) are left as-is.