Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Document new redis options #1416

Merged
merged 5 commits into from
Nov 30, 2023
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,8 @@ Decrements the number stored at `key` by one. If the key does not exist, it is s
```javascript
import redis from 'k6/experimental/redis';

// Get the redis instance(s) address and password from the environment
const redis_addrs = __ENV.REDIS_ADDRS || '';
const redis_password = __ENV.REDIS_PASSWORD || '';

// Instantiate a new redis client
const redisClient = new redis.Client({
addrs: redis_addrs.split(',') || new Array('localhost:6379'), // in the form of 'host:port', separated by commas
password: redis_password,
});
const redisClient = new redis.Client('redis://localhost:6379');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This not only updates to the new API, but also removes using a password in the example.

Is this intentional? Do we still have examples with password?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's a fair point! We do illustrate using the password in the Client documentation, though 👍🏻


export default async function () {
await redisClient.set('mykey', 10, 0);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,8 @@ Decrements the number stored at `key` by `decrement`. If the key does not exist,
```javascript
import redis from 'k6/experimental/redis';

// Get the redis instance(s) address and password from the environment
const redis_addrs = __ENV.REDIS_ADDRS || '';
const redis_password = __ENV.REDIS_PASSWORD || '';

// Instantiate a new redis client
const redisClient = new redis.Client({
addrs: redis_addrs.split(',') || new Array('localhost:6379'), // in the form of 'host:port', separated by commas
password: redis_password,
});
const redisClient = new redis.Client('redis://localhost:6379');

export default async function () {
await redisClient.set('mykey', 10, 0);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,8 @@ Removes the specified keys. A key is ignored if it does not exist.
```javascript
import redis from 'k6/experimental/redis';

// Get the redis instance(s) address and password from the environment
const redis_addrs = __ENV.REDIS_ADDRS || '';
const redis_password = __ENV.REDIS_PASSWORD || '';

// Instantiate a new redis client
const redisClient = new redis.Client({
addrs: redis_addrs.split(',') || new Array('localhost:6379'), // in the form of 'host:port', separated by commas
password: redis_password,
});
const redisClient = new redis.Client('redis://localhost:6379');

export default async function () {
await redisClient.set('mykey', 'myvalue', 0);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,8 @@ Returns the number of `key` arguments that exist. Note that if the same existing
```javascript
import redis from 'k6/experimental/redis';

// Get the redis instance(s) address and password from the environment
const redis_addrs = __ENV.REDIS_ADDRS || '';
const redis_password = __ENV.REDIS_PASSWORD || '';

// Instantiate a new redis client
const redisClient = new redis.Client({
addrs: redis_addrs.split(',') || new Array('localhost:6379'), // in the form of 'host:port', separated by commas
password: redis_password,
});
const redisClient = new redis.Client('redis://localhost:6379');

export default async function () {
let exists = await redisClient.exists('mykey');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,8 @@ Sets a timeout on key, after which the key will automatically be deleted. Note t
```javascript
import redis from 'k6/experimental/redis';

// Get the redis instance(s) address and password from the environment
const redis_addrs = __ENV.REDIS_ADDRS || '';
const redis_password = __ENV.REDIS_PASSWORD || '';

// Instantiate a new redis client
const redisClient = new redis.Client({
addrs: redis_addrs.split(',') || new Array('localhost:6379'), // in the form of 'host:port', separated by commas
password: redis_password,
});
const redisClient = new redis.Client('redis://localhost:6379');

export default async function () {
await redisClient.set('mykey', 'myvalue', 10);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,8 @@ Get the key's value.
```javascript
import redis from 'k6/experimental/redis';

// Get the redis instance(s) address and password from the environment
const redis_addrs = __ENV.REDIS_ADDRS || '';
const redis_password = __ENV.REDIS_PASSWORD || '';

// Instantiate a new redis client
const redisClient = new redis.Client({
addrs: redis_addrs.split(',') || new Array('localhost:6379'), // in the form of 'host:port', separated by commas
password: redis_password,
});
const redisClient = new redis.Client('redis://localhost:6379');

export default async function () {
await redisClient.set('mykey', 'myvalue', 0);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,8 @@ Get the value of `key` and delete the key. This functionality is similar to `get
```javascript
import redis from 'k6/experimental/redis';

// Get the redis instance(s) address and password from the environment
const redis_addrs = __ENV.REDIS_ADDRS || '';
const redis_password = __ENV.REDIS_PASSWORD || '';

// Instantiate a new redis client
const redisClient = new redis.Client({
addrs: redis_addrs.split(',') || new Array('localhost:6379'), // in the form of 'host:port', separated by commas
password: redis_password,
});
const redisClient = new redis.Client('redis://localhost:6379');

export default async function () {
await redisClient.set('mykey', 'oldvalue', 0);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,8 @@ Atomically sets `key` to `value` and returns the value previously stored at `key
```javascript
import redis from 'k6/experimental/redis';

// Get the redis instance(s) address and password from the environment
const redis_addrs = __ENV.REDIS_ADDRS || '';
const redis_password = __ENV.REDIS_PASSWORD || '';

// Instantiate a new redis client
const redisClient = new redis.Client({
addrs: redis_addrs.split(',') || new Array('localhost:6379'), // in the form of 'host:port', separated by commas
password: redis_password,
});
const redisClient = new redis.Client('redis://localhost:6379');

export default async function () {
await redisClient.set('mykey', 'oldvalue', 0);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,8 @@ Deletes the specified fields from the hash stored at `key`. The number of fields
```javascript
import redis from 'k6/experimental/redis';

// Get the redis instance(s) address and password from the environment
const redis_addrs = __ENV.REDIS_ADDRS || '';
const redis_password = __ENV.REDIS_PASSWORD || '';

// Instantiate a new redis client
const redisClient = new redis.Client({
addrs: redis_addrs.split(',') || new Array('localhost:6379'), // in the form of 'host:port', separated by commas
password: redis_password,
});
const redisClient = new redis.Client('redis://localhost:6379');

export default async function () {
await redisClient.hset('myhash', 'myfield', 'myvalue');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,8 @@ Returns the value associated with `field` in the hash stored at `key`.
```javascript
import redis from 'k6/experimental/redis';

// Get the redis instance(s) address and password from the environment
const redis_addrs = __ENV.REDIS_ADDRS || '';
const redis_password = __ENV.REDIS_PASSWORD || '';

// Instantiate a new redis client
const redisClient = new redis.Client({
addrs: redis_addrs.split(',') || new Array('localhost:6379'), // in the form of 'host:port', separated by commas
password: redis_password,
});
const redisClient = new redis.Client('redis://localhost:6379');

export default async function () {
await redisClient.hset('myhash', 'myfield', 'myvalue');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,8 @@ Returns all fields and values of the hash stored at `key`.
```javascript
import redis from 'k6/experimental/redis';

// Get the redis instance(s) address and password from the environment
const redis_addrs = __ENV.REDIS_ADDRS || '';
const redis_password = __ENV.REDIS_PASSWORD || '';

// Instantiate a new redis client
const redisClient = new redis.Client({
addrs: redis_addrs.split(',') || new Array('localhost:6379'), // in the form of 'host:port', separated by commas
password: redis_password,
});
const redisClient = new redis.Client('redis://localhost:6379');

export default async function () {
await redisClient.hset('myhash', 'myfield', 'myvalue');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,8 @@ Increments the integer value of `field` in the hash stored at `key` by `incremen
```javascript
import redis from 'k6/experimental/redis';

// Get the redis instance(s) address and password from the environment
const redis_addrs = __ENV.REDIS_ADDRS || '';
const redis_password = __ENV.REDIS_PASSWORD || '';

// Instantiate a new redis client
const redisClient = new redis.Client({
addrs: redis_addrs.split(',') || new Array('localhost:6379'), // in the form of 'host:port', separated by commas
password: redis_password,
});
const redisClient = new redis.Client('redis://localhost:6379');

export default async function () {
await redisClient.hset('myhash', 'myfield', 10);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,8 @@ Returns all fields of the hash stored at `key`.
```javascript
import redis from 'k6/experimental/redis';

// Get the redis instance(s) address and password from the environment
const redis_addrs = __ENV.REDIS_ADDRS || '';
const redis_password = __ENV.REDIS_PASSWORD || '';

// Instantiate a new redis client
const redisClient = new redis.Client({
addrs: redis_addrs.split(',') || new Array('localhost:6379'), // in the form of 'host:port', separated by commas
password: redis_password,
});
const redisClient = new redis.Client('redis://localhost:6379');

export default async function () {
await redisClient.hset('myhash', 'myfield', 'myvalue');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,8 @@ Returns the number of fields in the hash stored at `key`.
```javascript
import redis from 'k6/experimental/redis';

// Get the redis instance(s) address and password from the environment
const redis_addrs = __ENV.REDIS_ADDRS || '';
const redis_password = __ENV.REDIS_PASSWORD || '';

// Instantiate a new redis client
const redisClient = new redis.Client({
addrs: redis_addrs.split(',') || new Array('localhost:6379'), // in the form of 'host:port', separated by commas
password: redis_password,
});
const redisClient = new redis.Client('redis://localhost:6379');

export default async function () {
await redisClient.hset('myhash', 'myfield', 10);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,8 @@ Sets the specified field in the hash stored at `key` to `value`. If the `key` do
```javascript
import redis from 'k6/experimental/redis';

// Get the redis instance(s) address and password from the environment
const redis_addrs = __ENV.REDIS_ADDRS || '';
const redis_password = __ENV.REDIS_PASSWORD || '';

// Instantiate a new redis client
const redisClient = new redis.Client({
addrs: redis_addrs.split(',') || new Array('localhost:6379'), // in the form of 'host:port', separated by commas
password: redis_password,
});
const redisClient = new redis.Client('redis://localhost:6379');

export default async function () {
await redisClient.hset('myhash', 'myfield', 'myvalue');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,8 @@ Sets the specified field in the hash stored at `key` to `value`, only if `field`
```javascript
import redis from 'k6/experimental/redis';

// Get the redis instance(s) address and password from the environment
const redis_addrs = __ENV.REDIS_ADDRS || '';
const redis_password = __ENV.REDIS_PASSWORD || '';

// Instantiate a new redis client
const redisClient = new redis.Client({
addrs: redis_addrs.split(',') || new Array('localhost:6379'), // in the form of 'host:port', separated by commas
password: redis_password,
});
const redisClient = new redis.Client('redis://localhost:6379');

export default async function () {
await redisClient.hsetnx('myhash', 'myfield', 'myvalue');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,8 @@ Returns all values of the hash stored at `key`.
```javascript
import redis from 'k6/experimental/redis';

// Get the redis instance(s) address and password from the environment
const redis_addrs = __ENV.REDIS_ADDRS || '';
const redis_password = __ENV.REDIS_PASSWORD || '';

// Instantiate a new redis client
const redisClient = new redis.Client({
addrs: redis_addrs.split(',') || new Array('localhost:6379'), // in the form of 'host:port', separated by commas
password: redis_password,
});
const redisClient = new redis.Client('redis://localhost:6379');

export default async function () {
await redisClient.hset('myhash', 'myfield', 'myvalue');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,8 @@ Increments the number stored at `key` by one. If the key does not exist, it is s
```javascript
import redis from 'k6/experimental/redis';

// Get the redis instance(s) address and password from the environment
const redis_addrs = __ENV.REDIS_ADDRS || '';
const redis_password = __ENV.REDIS_PASSWORD || '';

// Instantiate a new redis client
const redisClient = new redis.Client({
addrs: redis_addrs.split(',') || new Array('localhost:6379'), // in the form of 'host:port', separated by commas
password: redis_password,
});
const redisClient = new redis.Client('redis://localhost:6379');

export default async function () {
await redisClient.set('mykey', 10, 0);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,8 @@ Increments the number stored at `key` by `increment`. If the key does not exist,
```javascript
import redis from 'k6/experimental/redis';

// Get the redis instance(s) address and password from the environment
const redis_addrs = __ENV.REDIS_ADDRS || '';
const redis_password = __ENV.REDIS_PASSWORD || '';

// Instantiate a new redis client
const redisClient = new redis.Client({
addrs: redis_addrs.split(',') || new Array('localhost:6379'), // in the form of 'host:port', separated by commas
password: redis_password,
});
const redisClient = new redis.Client('redis://localhost:6379');

export default async function () {
await redisClient.set('mykey', 10, 0);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,8 @@ Returns the specified element of the list stored at `key`. The index is zero-bas
```javascript
import redis from 'k6/experimental/redis';

// Get the redis instance(s) address and password from the environment
const redis_addrs = __ENV.REDIS_ADDRS || '';
const redis_password = __ENV.REDIS_PASSWORD || '';

// Instantiate a new redis client
const redisClient = new redis.Client({
addrs: redis_addrs.split(',') || new Array('localhost:6379'), // in the form of 'host:port', separated by commas
password: redis_password,
});
const redisClient = new redis.Client('redis://localhost:6379');

export default async function () {
await redisClient.rpush('mylist', 'first');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,8 @@ Returns the length of the list stored at `key`. If `key` does not exist, it is i
```javascript
import redis from 'k6/experimental/redis';

// Get the redis instance(s) address and password from the environment
const redis_addrs = __ENV.REDIS_ADDRS || '';
const redis_password = __ENV.REDIS_PASSWORD || '';

// Instantiate a new redis client
const redisClient = new redis.Client({
addrs: redis_addrs.split(',') || new Array('localhost:6379'), // in the form of 'host:port', separated by commas
password: redis_password,
});
const redisClient = new redis.Client('redis://localhost:6379');

export default function () {
redisClient
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,8 @@ Removes and returns the first element of the list stored at `key`.
```javascript
import redis from 'k6/experimental/redis';

// Get the redis instance(s) address and password from the environment
const redis_addrs = __ENV.REDIS_ADDRS || '';
const redis_password = __ENV.REDIS_PASSWORD || '';

// Instantiate a new redis client
const redisClient = new redis.Client({
addrs: redis_addrs.split(',') || new Array('localhost:6379'), // in the form of 'host:port', separated by commas
password: redis_password,
});
const redisClient = new redis.Client('redis://localhost:6379');

export default async function () {
await redisClient.lpush('mylist', 'first');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,8 @@ Inserts all the specified values at the head of the list stored at `key`. If `ke
```javascript
import redis from 'k6/experimental/redis';

// Get the redis instance(s) address and password from the environment
const redis_addrs = __ENV.REDIS_ADDRS || '';
const redis_password = __ENV.REDIS_PASSWORD || '';

// Instantiate a new redis client
const redisClient = new redis.Client({
addrs: redis_addrs.split(',') || new Array('localhost:6379'), // in the form of 'host:port', separated by commas
password: redis_password,
});
const redisClient = new redis.Client('redis://localhost:6379');

export default async function () {
await redisClient.lpush('mylist', 'first');
Expand Down