File tree Expand file tree Collapse file tree 9 files changed +52
-66
lines changed
src/data/markdown/docs/02 javascript api/07 k6-experimental/02 redis/10 Client Expand file tree Collapse file tree 9 files changed +52
-66
lines changed Original file line number Diff line number Diff line change @@ -36,11 +36,10 @@ const redisClient = new redis.Client({
36
36
password: redis_password,
37
37
});
38
38
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' );
44
43
}
45
44
```
46
45
Original file line number Diff line number Diff line change @@ -36,11 +36,10 @@ const redisClient = new redis.Client({
36
36
password: redis_password,
37
37
});
38
38
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' );
44
43
}
45
44
```
46
45
Original file line number Diff line number Diff line change @@ -35,14 +35,11 @@ const redisClient = new redis.Client({
35
35
password: redis_password,
36
36
});
37
37
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)} ` );
46
43
}
47
44
```
48
45
Original file line number Diff line number Diff line change @@ -37,10 +37,9 @@ const redisClient = new redis.Client({
37
37
password: redis_password,
38
38
});
39
39
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 );
44
43
}
45
44
```
46
45
Original file line number Diff line number Diff line change @@ -35,18 +35,16 @@ const redisClient = new redis.Client({
35
35
password: redis_password,
36
36
});
37
37
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} ` );
50
48
}
51
49
```
52
50
Original file line number Diff line number Diff line change @@ -35,11 +35,10 @@ const redisClient = new redis.Client({
35
35
password: redis_password,
36
36
});
37
37
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' );
43
42
}
44
43
```
45
44
Original file line number Diff line number Diff line change @@ -37,11 +37,10 @@ const redisClient = new redis.Client({
37
37
password: redis_password,
38
38
});
39
39
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' );
45
44
}
46
45
```
47
46
Original file line number Diff line number Diff line change @@ -37,16 +37,14 @@ const redisClient = new redis.Client({
37
37
password: redis_password,
38
38
});
39
39
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
+ }
50
48
}
51
49
```
52
50
Original file line number Diff line number Diff line change @@ -35,18 +35,16 @@ const redisClient = new redis.Client({
35
35
password: redis_password,
36
36
});
37
37
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} ` );
50
48
}
51
49
```
52
50
You can’t perform that action at this time.
0 commit comments