Skip to content

Admin Operations

The DBX TypeScript SDK provides admin operations for server management and monitoring.

Installation

npm install @0dbx/redis

Basic Usage

import { DbxRedisClient } from "@0dbx/redis";
 
// Create client
const client = new DbxRedisClient("http://localhost:3000");
 
// Admin operations
const health = await client.admin.health();
const ping = await client.admin.ping();

WebSocket Client

import { DbxWsClient } from "@0dbx/redis";
 
// Create WebSocket client
const wsClient = new DbxWsClient("ws://localhost:3000/redis_ws");
 
// Admin operations via WebSocket
const health = await wsClient.admin.health();
const ping = await wsClient.admin.ping();

Admin Operations

INFO - Get Server Info

const info = await adminClient.info("all");

PING - Test Connection

const pong = await adminClient.ping("Hello DBX");

FLUSHDB/FLUSHALL - Clear Database

await adminClient.flushdb();
await adminClient.flushall();

KEYS/SCAN - Find Keys

const keys = await adminClient.keys("user:*");
const scanResult = await adminClient.scan(0, { count: 10, match: "user:*" });

DEL - Delete Keys

const deleted = await adminClient.del(["key1", "key2"]);

EXISTS - Check Keys Exist

const exists = await adminClient.exists(["key1", "key2"]);

TYPE - Get Key Type

const type = await adminClient.type("user:123");

TTL/EXPIRE/PERSIST - Key Expiration

const ttl = await adminClient.ttl("session:123");
await adminClient.expire("session:123", 3600);
await adminClient.persist("session:123");

RENAME/RENAMENX - Rename Key

await adminClient.rename("old:key", "new:key");
await adminClient.renamenx("old:key", "new:key");

DBSIZE - Get Database Size

const size = await adminClient.dbsize();

SLOWLOG - Get Slow Query Log

const slowlog = await adminClient.slowlog(10);

CONFIG GET/SET - Configuration

const config = await adminClient.configGet("maxmemory");
await adminClient.configSet("maxmemory", "1gb");

Error Handling

All methods throw DBXError on failure. See String Client for error handling examples.

Best Practices

  • Use admin operations with proper authentication
  • Use SCAN instead of KEYS for large datasets
  • Backup data before destructive operations
  • Log all admin operations for audit