On this page

DragonflyDB Store

The DragonflyDB store enables high-throughput distributed rate limiting using DragonflyDB — a modern, multi-threaded, Redis-compatible in-memory store. It's a drop-in replacement for the Redis store, using the same ioredis client and atomic Lua scripts.

What is DragonflyDB?

DragonflyDB is a C++ rewrite of Redis claiming 25x throughput improvement. It uses a multi-threaded, shared-nothing architecture that scales vertically across all available CPU cores. Licensed under BSL 1.1 (converts to Apache 2.0 in 2029). It maintains full wire compatibility with Redis — same protocol, same commands, same Lua scripting.

Installation

The DragonflyDB store requires ioredis as a peer dependency (same as Redis store):

npm install ioredis
# or: pnpm add ioredis
# or: yarn add ioredis
bun add ioredis

Usage

import { hitlimit } from '@joint-ops/hitlimit'
import { dragonflyStore } from '@joint-ops/hitlimit/stores/dragonfly'

app.use(hitlimit({
  limit: 100,
  window: '1m',
  store: dragonflyStore({
    url: 'redis://localhost:6379'
  })
}))
import { hitlimit } from '@joint-ops/hitlimit-bun'
import { dragonflyStore } from '@joint-ops/hitlimit-bun/stores/dragonfly'

const limiter = hitlimit({
  limit: 100,
  window: '1m',
  store: dragonflyStore({
    url: 'redis://localhost:6379'
  })
})

Options

OptionTypeDefaultDescription
urlstring-DragonflyDB connection URL (uses redis:// scheme)
clientRedis-Existing ioredis client instance
prefixstring'hitlimit:'Key prefix for rate limit entries

Parallel Lua Execution

DragonflyDB executes Lua scripts on different keys in parallel across threads — unlike Redis where Lua blocks the entire server. Since hitlimit's scripts properly declare all keys via KEYS[], they benefit from this parallelism automatically. This means rate limit checks for different users execute concurrently, improving throughput under high load.

Migration from Redis

Migrating from redisStore to dragonflyStore requires changing two lines:

// Before (Redis)
import { redisStore } from '@joint-ops/hitlimit/stores/redis'
const store = redisStore({ url: 'redis://localhost:6379' })

// After (DragonflyDB) — same URL scheme, same port, same options
import { dragonflyStore } from '@joint-ops/hitlimit/stores/dragonfly'
const store = dragonflyStore({ url: 'redis://localhost:6379' })

The connection URL uses the same redis:// scheme. ioredis connects identically to both Redis and DragonflyDB servers.

Characteristics

  • Architecture: Multi-threaded, shared-nothing design scaling across all CPU cores
  • Speed: Same as Redis store for rate limiting (network-bound)
  • License: BSL 1.1 (converts to Apache 2.0 in 2029)
  • Persistence: Configurable via DragonflyDB persistence settings
  • Scalability: Shared across all server instances
  • Atomic: Lua scripts ensure race-condition-free increments with parallel execution across keys

When to Use

  • High-throughput scenarios where Redis becomes a bottleneck
  • When you need multi-threaded Lua execution for concurrent rate limiting
  • When BSL 1.1 license is acceptable for your use case
  • Migrating from Redis — zero code changes beyond import path