Skip to content

Commit e298e40

Browse files
oleiademstoykov
andcommitted
Update src/data/markdown/docs/02 javascript api/07 k6-experimental/02 redis/10 Client.md
Co-authored-by: Mihail Stoykov <[email protected]>
1 parent 5f0926a commit e298e40

File tree

11 files changed

+23
-25
lines changed

11 files changed

+23
-25
lines changed

src/data/markdown/docs/02 javascript api/07 k6-experimental/02 redis.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,4 @@ which operate in a synchronous manner,
2727
the Redis `Client` operates in an asynchronous manner.
2828
In practice, this means that using the Redis `Client`'s methods won't block test execution,
2929
and that the test will continue to run even if the Redis `Client` isn't ready to respond to the request.
30-
However, achieving a seemingly synchronous behavior can be done using the `async/await` syntax. When preceding an asynchronous Redis `Client` operation with the `await` keyword in the context of an `async` function, the execution of the function will wait for the operation to complete before continuing its execution.
30+
The `async/await` syntax can be used to make the code look synchronous while still being asynchronous, and not blocking the test execution.

src/data/markdown/docs/02 javascript api/07 k6-experimental/02 redis/10 Client.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,8 @@ export async function measureRedisPerformance() {
6262

6363
await redisClient.set(key, 1);
6464
await redisClient.incrBy(key, 10);
65-
if (await redisClient.get(key) !== '11') {
65+
const value = await redisClient.get(key);
66+
if (value !== '11') {
6667
throw new Error('foo should have been incremented to 11');
6768
}
6869

@@ -81,7 +82,7 @@ export async function measureUsingRedisData() {
8182
// we have filled in setup().
8283
const randomID = await redisClient.srandmember('crocodile_ids');
8384
const url = `https://test-api.k6.io/public/crocodiles/${randomID}`;
84-
const res = http.get(url);
85+
const res = await http.asyncRequest("GET", url);
8586

8687
check(res, {'status is 200': (r) => r.status === 200});
8788

src/data/markdown/docs/02 javascript api/07 k6-experimental/02 redis/10 Client/Client-decrby.md

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -39,14 +39,9 @@ const redisClient = new redis.Client({
3939
export default async function () {
4040
await redisClient.set('mykey', 10, 0);
4141

42-
let value;
43-
value = await redisClient.incr('mykey');
44-
value = await redisClient.incrBy('mykey', value);
45-
value = await redisClient.decrBy('mykey', value);
46-
value = await redisClient.decr('mykey');
47-
48-
if (value !== -1) {
49-
throw new Error('mykey should have been -1');
42+
const value = await redisClient.decrBy('mykey', 2);
43+
if (value !== 8) {
44+
throw new Error('mykey should have been 8');
5045
}
5146
}
5247
```

src/data/markdown/docs/02 javascript api/07 k6-experimental/02 redis/10 Client/Client-expire.md

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,12 +41,10 @@ export default async function () {
4141
await redisClient.expire('mykey', 100);
4242

4343
const ttl = await redisClient.ttl('mykey');
44-
if (ttl <= 10) {
44+
if (ttl <= 10 || ttl >= 100) {
4545
throw new Error('mykey should have a ttl of 10 <= x < 100');
4646
}
47-
48-
await redisClient.persist('mykey', 100);
4947
}
5048
```
5149

52-
</CodeGroup>
50+
</CodeGroup>

src/data/markdown/docs/02 javascript api/07 k6-experimental/02 redis/10 Client/Client-get.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ export default async function () {
4040

4141
const exists = await redisClient.exists('mykey');
4242
if (exists === false) {
43-
throw new Error('mykey should exist');
43+
throw new Error('mykey should exist');
4444
}
4545

4646
const value = await redisClient.get('mykey');

src/data/markdown/docs/02 javascript api/07 k6-experimental/02 redis/10 Client/Client-getdel.md

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,12 @@ const redisClient = new redis.Client({
3737

3838
export default async function () {
3939
await redisClient.set('mykey', 'oldvalue', 0);
40-
await redisClient.getSet('mykey', 'newvalue');
41-
await redisClient.getDel('mykey');
40+
let value = await redisClient.getSet('mykey', 'newvalue');
41+
42+
value = await redisClient.getDel('mykey');
43+
if (value !== 'newvalue') {
44+
throw new Error('mykey should have been newvalue');
45+
}
4246
}
4347
```
4448

src/data/markdown/docs/02 javascript api/07 k6-experimental/02 redis/10 Client/Client-hkeys.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ export default async function () {
4141

4242
const keys = await redisClient.hkeys('myhash');
4343
if (keys.length !== 2) {
44-
throw new Error('myhash should have 2 keys');
44+
throw new Error('myhash should have 2 keys');
4545
}
4646

4747
console.log(`myhash has keys ${keys}`);

src/data/markdown/docs/02 javascript api/07 k6-experimental/02 redis/10 Client/Client-hset.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ const redisClient = new redis.Client({
3939

4040
export default async function () {
4141
await redisClient.hset('myhash', 'myfield', 'myvalue');
42-
await redisClient.then((_) => redisClient.hget('myhash', 'myfield'));
42+
await redisClient.hget('myhash', 'myfield');
4343
await redisClient.hdel('myhash', 'myfield');
4444
}
4545
```

src/data/markdown/docs/02 javascript api/07 k6-experimental/02 redis/10 Client/Client-hsetnx.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,9 @@ export default async function () {
4141
await redisClient.hsetnx('myhash', 'myfield', 'myvalue')
4242
await redisClient.hsetnx('myhash', 'myotherfield', 'myothervalue');
4343

44-
const s = await redisClient.hsetnx('myhash', 'myfield', 'mynewvalue');
45-
if (s === true) {
46-
throw new Error('hsetnx should have failed on existing field');
44+
const set = await redisClient.hsetnx('myhash', 'myfield', 'mynewvalue');
45+
if (set === true) {
46+
throw new Error('hsetnx should have failed on existing field');
4747
}
4848
}
4949
```

src/data/markdown/docs/02 javascript api/07 k6-experimental/02 redis/10 Client/Client-lrange.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ export default async function () {
4444

4545
const item = redisClient.lindex('mylist', 0);
4646
if (item !== 'first') {
47-
throw new Error('lindex operation should have returned first');
47+
throw new Error('lindex operation should have returned first');
4848
}
4949

5050
await redisClient.lrange('mylist', 1, 2);

0 commit comments

Comments
 (0)