javascript-redis-server
Interact with a Redis server using this simple Node.js client. Learn how to connect, set, and get values. Free and easy to use.
Redis Server
This example demonstrates a basic Node.js client interacting with a Redis server. It shows how to connect, set a key-value pair, and retrieve the value.
Connecting to the Redis Server
The code first establishes a connection to the Redis server using the redis
library. The connection string specifies the URL of the Redis instance.
Setting and Getting Values
The client.set()
method sets a key ('foo') to a value ('bar'). The client.get()
method (not shown in this example, but implied) would retrieve the value associated with the key.
const redis = require('redis');
const client = redis.createClient({ url: 'redis://redis:6379' });
client.on('error', (err) => console.error('Redis Client Error', err));
client.connect();
client.set('foo', 'bar')
.then(() => console.log('Value set successfully'))
.catch(console.error);
client.quit();
Further Exploration
This is a very basic example. The Redis library offers many more commands for managing data in your Redis instance. Explore the Redis command documentation to learn more.