Deno and Redis
With over 80,000 stars and 670+ contributors, Deno is a popular modern runtime for JavaScript and TypeScript. It is built on V8, an open-source JavaScript engine developed by the Chromium Project for Google Chrome and Chromium web browsers.
#
Features of Deno- Deno is secure by default. It executes code in a sandbox environment, disallowing runtime access to the underlying filesystem, environment variables and scripts.
- Deno supports both JavaScript and TypeScript out of the box.
- Deno ships as a single executable with no dependencies.
- Comes with built-in utilities such as a dependency inspector (deno info) and a code formatter (deno fmt).
#
Getting Starteddeno.land/x is a hosting service for Deno scripts. It caches releases of open source modules stored on GitHub and serves them at one easy-to-remember domain. These modules contain small scripts that demonstrate use of Deno and its standard module.
The basic format of code URLs is
#
Example:In order to use Redis with Deno you will need a Deno Redis client. In the following sections, we will demonstrate the use of an experimental implementation of a Redis client for Deno.
#
Step 1. Set up a free Redis Enterprise Cloud accountVisit developer.redis.com/create/rediscloud/ and create a free Redis Enterprise Cloud account. Once you complete this tutorial, you will be provided with the database endpoint URL and password. Save it for future reference.
TIP
For a limited time, use TIGER200 to get $200 credits on Redis Enterprise Cloud and try all the advanced capabilities!
#
Step 2. Get Deno#
Step 3. Verify if Deno is properly installed#
Step 4. Create an empty file with the following contentThe following code creates a connection to Redis using Deno:
Replace the values of hostname and port to match those of your Redis database, and add an extra password field if needed.
#
Step 5. Executing the scriptDeno can grab scripts from multiple sources. For example, you can provide a filename, a URL, or'-' to read the file from stdin.
You can run a JavaScript or TypeScript program by executing deno run
.
When you run the script, the value of foo
should be output. You can verify this by running the monitor command: