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.
deno.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
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.
Visit redis.com/try-free and create a free Redis Cloud account. Once you complete this tutorial, you will be provided with the database endpoint URL and password. Save it for future reference.
The 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.
Deno 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:
https://deno.land/x/IDENTIFIER@VERSION/FILE_PATH
https://deno.land/[email protected]/examples
brew install deno
deno -V
deno 1.19.0
import { connect } from 'https://deno.land/x/redis/mod.ts';
const redis = await connect({
hostname: 'redis-18386.c110-qa.us-east-1-1.ec2.qa-cloud.redislabs.com',
port: 18386,
password: 'XXXX',
});
const ok = await redis.set('foo', 'bar');
const foo = await redis.get('foo');
deno run --allow-net redis.ts
redis-15692.c264.ap-south-1-1.ec2.cloud.redislabs.com:15692> monitor
OK
1646536310.435577 [0 122.171.165.94:50193] "AUTH" "(redacted)"
1646536310.475578 [0 122.171.165.94:50193] "SET" "foo" "bar"
1646536310.511578 [0 122.171.165.94:50193] "GET" "foo"
For a limited time, use TIGER200 to get $200 credits on Redis Cloud and try all the advanced capabilities!