Development

Redis: more than just caching

Most developers use Redis as a fast key-value cache. But this is only the tip of the iceberg. Redis is a versatile in-memory tool that is great for building high-load systems. In this article, we will look at practical Redis usage scenarios with code examples.

IK

Igor Krivoshey

Development and DevOps specialist

March 23, 2026·~8–10 minutes
Redis: more than just caching

1. Queues

Redis is ideal for implementing simple task queues.

Usage: background jobs, event processing

Main commands:

  • LPUSH— add to the queue

  • RPOP/BLPOP— get from the queue

Example (Node.js + ioredis)

JavaScript
import Redis from 'ioredis';

const redis = new Redis();

// Producer (додає задачу)
async function addJob(data) {
  await redis.lpush('queue:emails', JSON.stringify(data));
}

// Worker (обробляє задачі)
async function worker() {
  while (true) {
    const res = await redis.brpop('queue:emails', 0);
    const job = JSON.parse(res[1]);

    console.log('Processing:', job);
  }
}

worker();

Pros:

  • Simplicity

  • Instant processing

Minus:

  • No retry / ack (for more complex cases BullMQ is better)

2. Pub/Sub (Publish / Subscribe)

Redis allows you to implement a real-time messaging system.

Usage: chats, notifications, WebSocket

Example

JavaScript
// subscriber.js
const sub = new Redis();

sub.subscribe('chat');

sub.on('message', (channel, message) => {
  console.log(`New message: ${message}`);
});
JavaScript
// publisher.js
const pub = new Redis();

Feature:

  • Messages are not stored (this is not a queue!)

3. Rate Limiting (request limitation)

One of the most popular cases is API protection.

Using:

  • DDoS protection

  • limiting user requests

Example (Fixed Window)

JavaScript
async function rateLimit(ip) {
  const key = `rate:${ip}`;
  
  const current = await redis.incr(key);

  if (current === 1) {
    await redis.expire(key, 60); // 60 сек
  }

  if (current > 100) {
    throw new Error('Too many requests');
  }
}

Alternative:

  • Sliding window (more accurate control)

  • Token bucket (for API)

4. User sessions

Redis is often used as session storage.

Using:

  • authorization

  • shopping cart

  • temporary data

Example

JavaScript
// збереження сесії
await redis.set(
  `session:${sessionId}`,
  JSON.stringify({ userId: 123 }),
  'EX',
  3600
);

// отримання
const session = JSON.parse(
  await redis.get(`session:${sessionId}`)
);

Pros:

  • quickly

  • TTL "out of the box"

5. Geospatial data (Geo)

Redis has built-in support for geodata.

Using:

  • search "near me"

  • delivery

  • cards

Teams:

  • GEOADD

  • GEORADIUS

  • GEODIST

Example

JavaScript
// додаємо координати
await redis.geoadd('drivers', 30.5234, 50.4501, 'driver_1');

// шукаємо поруч (5 км)
const nearby = await redis.georadius(
  'drivers',
  30.5234,
  50.4501,
  5,
  'km'
);

console.log(nearby);

6. Counters and analytics

Redis is great for real-time metrics.

Using:

  • page views

  • cursing

  • analytics

Example

JavaScript
await redis.incr('page:home:views');

Or with TTL:

JavaScript
await redis.incr('stats:today');
await redis.expire('stats:today', 86400);

7. Distributed Locks

For synchronization between services.

Using:

  • avoiding race conditions

  • cron jobs

Example

JavaScript
const lock = await redis.set('lock:job', '1', 'NX', 'EX', 10);

if (lock) {
  console.log('Lock acquired');
  // виконуємо задачу
}

Conclusion

Redis is not just a cache, but a powerful tool for building:

  • highly loaded APIs

  • asynchronous systems

  • real-time applications

  • geoservices

If you use Redis only for cache, you use ~20% of its capabilities.

When should you use Redis?

Yes:

  • required speed (milliseconds)

  • temporary or frequently changing data

  • real-time logic

No:

  • complex transactions

  • long-term storage of critical data

Теги
RedisBackendArchitectureQueuesPerformance

Shipstack

Готовы внедрить это на практике?

Обсудим архитектуру, сроки и стек — без шаблонных презентаций, по делу.