|
3 | 3 | * @difficulty intermediate
|
4 | 4 | * @tags cli, deploy
|
5 | 5 | * @run --allow-net --allow-env <url>
|
6 |
| - * @resource {https://deno.land/x/r2d2} r2d2 on deno.land/x |
| 6 | + * @resource {https://jsr.io/@iuioiua/redis} redis on jsr.io |
7 | 7 | * @resource {https://redis.io/docs/getting-started/} Getting started with Redis
|
8 | 8 | * @group Databases
|
9 | 9 | *
|
10 |
| - * Using the r2d2 module, you can connect to a Redis database running anywhere. |
| 10 | + * Using the jsr:@iuioiua/redis module, you can connect to a Redis database running anywhere. |
11 | 11 | */
|
12 | 12 |
|
13 |
| -// Import the `sendCommand()` function from r2d2 |
14 |
| -import { sendCommand } from "https://deno.land/x/r2d2/mod.ts"; |
| 13 | +// Import the `RedisClient` from jsr:@iuioiua/redis |
| 14 | +import { RedisClient } from "jsr:@iuioiua/redis"; |
15 | 15 |
|
16 | 16 | // Create a TCP connection with the Redis server
|
17 |
| -const redisConn = await Deno.connect({ port: 6379 }); |
| 17 | +using redisConn = await Deno.connect({ port: 6379 }); |
| 18 | + |
| 19 | +// Create an instance of 'RedisClient' |
| 20 | +const redisClient = new RedisClient(redisConn); |
18 | 21 |
|
19 | 22 | // Authenticate with the server by sending the command "AUTH <username> <password>"
|
20 |
| -await sendCommand(redisConn, [ |
| 23 | +await redisClient.sendCommand([ |
21 | 24 | "AUTH",
|
22 | 25 | Deno.env.get("REDIS_USERNAME")!,
|
23 | 26 | Deno.env.get("REDIS_PASSWORD")!,
|
24 | 27 | ]);
|
25 | 28 |
|
26 | 29 | // Set the "hello" key to have value "world" using the command "SET hello world"
|
27 |
| -await sendCommand(redisConn, ["SET", "hello", "world"]); // "OK" |
| 30 | +await redisClient.sendCommand(["SET", "hello", "world"]); // "OK" |
28 | 31 |
|
29 | 32 | // Get the "hello" key using the command "GET hello"
|
30 |
| -await sendCommand(redisConn, ["GET", "hello"]); // "world" |
31 |
| - |
32 |
| -// Close the connection to the database |
33 |
| -redisConn.close(); |
| 33 | +await redisClient.sendCommand(["GET", "hello"]); // "world" |
0 commit comments