Skip to content

Connection Setup

  • ioredis offers multiple constructors for different connection configurations
  • Glide uses a single configuration object that comes pre-configured with best practices

Glide typically requires minimal configuration changes for:

  • Timeout settings
  • TLS configuration
  • Read from replica settings
  • User authentication (username & password)

For advanced configurations, refer to the Node.js Glide Guide.

ioredis

const Redis = require("ioredis");
// Simple connection
const redis = new Redis();
// With options
const redisWithOptions = new Redis({
port: 6379,
host: "localhost",
username: "user",
password: "password",
});

Glide

import { GlideClient } from '@valkey/valkey-glide';
// Simple connection
const addresses = [
{ host: "localhost", port: 6379 }
];
const client = await GlideClient.createClient({
addresses: addresses
});
// With options
const clientWithOptions = await GlideClient.createClient({
addresses: [{ host: "localhost", port: 6379 }],
credentials: {
username: "user",
password: "password",
},
useTLS: true,
requestTimeout: 5000,
readFrom: "AZAffinity",
advancedConfiguration: {
connectionTimeout: 500 // Example of advanced configuration
}
});

ioredis

const Redis = require("ioredis");
const cluster = new Redis.Cluster([
{ host: "127.0.0.1", port: 6379 },
{ host: "127.0.0.1", port: 6380 }
]);
// With options
const clusterWithOptions = new Redis.Cluster([
{ host: "127.0.0.1", port: 6379 },
{ host: "127.0.0.1", port: 6380 }
], {
redisOptions: {
password: "password"
}
});

Glide

import { GlideClusterClient } from '@valkey/valkey-glide';
const addresses = [
{ host: "127.0.0.1", port: 6379 },
{ host: "127.0.0.1", port: 6380 }
];
const client = await GlideClusterClient.createClient({
addresses: addresses
});
// With options
const clientWithOptions = await GlideClusterClient.createClient({
addresses: addresses,
credentials: {
password: "password"
},
useTLS: true,
advancedConfiguration: {
connectionTimeout: 500 // Example of advanced configuration
}
});

The table below compares ioredis constructors with Glide configuration parameters:

ioredis ParameterEquivalent Glide Configuration
host: stringaddresses: [{ host: string, port?: number }]
port: numberaddresses: [{ host: string, port: number }]
username: stringcredentials: { username: string, password: string }
password: stringcredentials: { password: string }
db: numberclient.select(number)
tls: {}useTLS?: true
Not implmentedprotocol?: ProtocolVersion;
commandTimeout: numberrequestTimeout: number
connectTimeout: numberadvancedConfiguration: { connectionTimeout: number }
retryStrategy: functionconnectionBackoff?: { numberOfRetries: number, factor: number, exponentBase: number, jitterPercent?: number }
readOnly: booleanreadFrom?: "REPLICA"/ "preferReplica"/ "AZAffinity"/ "AZAffinityReplicasAndPrimary" Read about AZ affinity
lazyConnect: booleanlazyConnect?: boolean;

Advanced configuration

Standalone Mode uses AdvancedGlideClientConfiguration and Cluster Mode uses AdvancedGlideClusterClientConfiguration, but the usage is similar:

// Standalone mode
const client = await GlideClient.createClient({
addresses: [{ host: "localhost", port: 6379 }],
advancedConfiguration: {
connectionTimeout: 500,
}
});
// Cluster mode
const clusterClient = await GlideClusterClient.createClient({
addresses: [{ host: "localhost", port: 6379 }],
advancedConfiguration: {
connectionTimeout: 500,
}
});