Skip to content

Commit b6061c6

Browse files
committed
Update redis hash commands examples with async/await syntax
1 parent d9666fc commit b6061c6

File tree

9 files changed

+52
-66
lines changed

9 files changed

+52
-66
lines changed

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

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,10 @@ const redisClient = new redis.Client({
3636
password: redis_password,
3737
});
3838

39-
export default function () {
40-
redisClient
41-
.hset('myhash', 'myfield', 'myvalue')
42-
.then((_) => redisClient.hget('myhash', 'myfield'))
43-
.then((_) => redisClient.hdel('myhash', 'myfield'));
39+
export default async function () {
40+
await redisClient.hset('myhash', 'myfield', 'myvalue');
41+
await redisClient.hget('myhash', 'myfield');
42+
await redisClient.hdel('myhash', 'myfield');
4443
}
4544
```
4645

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

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,10 @@ const redisClient = new redis.Client({
3636
password: redis_password,
3737
});
3838

39-
export default function () {
40-
redisClient
41-
.hset('myhash', 'myfield', 'myvalue')
42-
.then((_) => redisClient.hget('myhash', 'myfield'))
43-
.then((_) => redisClient.hdel('myhash', 'myfield'));
39+
export default async function () {
40+
await redisClient.hset('myhash', 'myfield', 'myvalue');
41+
await redisClient.hget('myhash', 'myfield');
42+
await redisClient.hdel('myhash', 'myfield');
4443
}
4544
```
4645

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

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -35,14 +35,11 @@ const redisClient = new redis.Client({
3535
password: redis_password,
3636
});
3737

38-
export default function () {
39-
redisClient
40-
.hset('myhash', 'myfield', 'myvalue')
41-
.then((_) => redisClient.hset('myhash', 'myotherfield', 'myothervalue'))
42-
.then((_) => redisClient.hgetall('myhash'))
43-
.then((object) => {
44-
console.log(`myhash has key:value pairs ${JSON.stringify(object)}`);
45-
});
38+
export default async function () {
39+
await redisClient.hset('myhash', 'myfield', 'myvalue');
40+
await redisClient.hset('myhash', 'myotherfield', 'myothervalue');
41+
const object = await redisClient.hgetall('myhash');
42+
console.log(`myhash has key:value pairs ${JSON.stringify(object)}`);
4643
}
4744
```
4845

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

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,9 @@ const redisClient = new redis.Client({
3737
password: redis_password,
3838
});
3939

40-
export default function () {
41-
redisClient
42-
.hset('myhash', 'myfield', 10)
43-
.then((_) => redisClient.hincrby('myhash', 'myfield', 20));
40+
export default async function () {
41+
await redisClient.hset('myhash', 'myfield', 10);
42+
await redisClient.hincrby('myhash', 'myfield', 20);
4443
}
4544
```
4645

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

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -35,18 +35,16 @@ const redisClient = new redis.Client({
3535
password: redis_password,
3636
});
3737

38-
export default function () {
39-
redisClient
40-
.hset('myhash', 'myfield', 'myvalue')
41-
.then((_) => redisClient.hset('myhash', 'myotherfield', 'myothervalue'))
42-
.then((_) => redisClient.hkeys('myhash'))
43-
.then((keys) => {
44-
if (keys.length !== 2) {
45-
throw new Error('myhash should have 2 keys');
46-
}
47-
48-
console.log(`myhash has keys ${keys}`);
49-
});
38+
export default async function () {
39+
await redisClient.hset('myhash', 'myfield', 'myvalue');
40+
await redisClient.hset('myhash', 'myotherfield', 'myothervalue');
41+
42+
const keys = await redisClient.hkeys('myhash');
43+
if (keys.length !== 2) {
44+
throw new Error('myhash should have 2 keys');
45+
}
46+
47+
console.log(`myhash has keys ${keys}`);
5048
}
5149
```
5250

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

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,10 @@ const redisClient = new redis.Client({
3535
password: redis_password,
3636
});
3737

38-
export default function () {
39-
redisClient
40-
.hset('myhash', 'myfield', 10)
41-
.then((_) => redisClient.hset('myhash', 'myotherfield', 20))
42-
.then((_) => redisClient.hlen('myhash'));
38+
export default async function () {
39+
await redisClient.hset('myhash', 'myfield', 10);
40+
await redisClient.hset('myhash', 'myotherfield', 20);
41+
await redisClient.hlen('myhash');
4342
}
4443
```
4544

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

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,10 @@ const redisClient = new redis.Client({
3737
password: redis_password,
3838
});
3939

40-
export default function () {
41-
redisClient
42-
.hset('myhash', 'myfield', 'myvalue')
43-
.then((_) => redisClient.hget('myhash', 'myfield'))
44-
.then((_) => redisClient.hdel('myhash', 'myfield'));
40+
export default async function () {
41+
await redisClient.hset('myhash', 'myfield', 'myvalue');
42+
await redisClient.then((_) => redisClient.hget('myhash', 'myfield'));
43+
await redisClient.hdel('myhash', 'myfield');
4544
}
4645
```
4746

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

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -37,16 +37,14 @@ const redisClient = new redis.Client({
3737
password: redis_password,
3838
});
3939

40-
export default function () {
41-
redisClient
42-
.hsetnx('myhash', 'myfield', 'myvalue')
43-
.then((_) => redisClient.hsetnx('myhash', 'myotherfield', 'myothervalue'))
44-
.then((_) => redisClient.hsetnx('myhash', 'myfield', 'mynewvalue'))
45-
.then((set) => {
46-
if (set === true) {
47-
throw new Error('hsetnx should have failed on existing field');
48-
}
49-
});
40+
export default async function () {
41+
await redisClient.hsetnx('myhash', 'myfield', 'myvalue')
42+
await redisClient.hsetnx('myhash', 'myotherfield', 'myothervalue');
43+
44+
const s = await redisClient.hsetnx('myhash', 'myfield', 'mynewvalue');
45+
if (s === true) {
46+
throw new Error('hsetnx should have failed on existing field');
47+
}
5048
}
5149
```
5250

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

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -35,18 +35,16 @@ const redisClient = new redis.Client({
3535
password: redis_password,
3636
});
3737

38-
export default function () {
39-
redisClient
40-
.hset('myhash', 'myfield', 'myvalue')
41-
.then((_) => redisClient.hset('myhash', 'myotherfield', 'myothervalue'))
42-
.then((_) => redisClient.hvals('myhash'))
43-
.then((values) => {
44-
if (values.length !== 2) {
45-
throw new Error('myhash should have 2 values');
46-
}
47-
48-
console.log(`myhash has values ${values}`);
49-
});
38+
export default async function () {
39+
await redisClient.hset('myhash', 'myfield', 'myvalue');
40+
await redisClient.hset('myhash', 'myotherfield', 'myothervalue');
41+
42+
const values = await redisClient.hvals('myhash');
43+
if (values.length !== 2) {
44+
throw new Error('myhash should have 2 values');
45+
}
46+
47+
console.log(`myhash has values ${values}`);
5048
}
5149
```
5250

0 commit comments

Comments
 (0)