redis

ruby
class CircuitBreaker
  class CircuitOpenError < StandardError; end

  INCREMENT = <<~LUA.freeze
    local n = redis.call('INCR', KEYS[1])
    if n == 1 then redis.call('EXPIRE', KEYS[1], ARGV[1]) end

Graceful Degradation: Feature-Based Rescue

rails resilience circuit-breaker
by codesnips 3 tabs
typescript
import Redis from "ioredis";

export const redis = new Redis(process.env.REDIS_URL ?? "redis://localhost:6379");

export interface Codec<T> {
  encode(value: T): string;

Redis cache-aside for expensive reads

redis performance caching
by codesnips 3 tabs
typescript
import { Queue } from "bullmq";
import IORedis from "ioredis";

export const connection = new IORedis(process.env.REDIS_URL ?? "redis://localhost:6379", {
  maxRetriesPerRequest: null,
});

BullMQ worker with retries + dead-letter

node redis background-jobs
by codesnips 3 tabs
ruby
class RateLimiter
  def initialize(key:, limit:, window:)
    @key = "rate_limit:#{key}"
    @limit = limit
    @window = window
  end

API throttling with custom Redis-based limiter

rails redis rate-limiting
by Alex Kumar 2 tabs
php
<?php

namespace App\Http\Controllers;

use App\Jobs\ProcessWebhook;
use App\Support\WebhookSignature;

Debounce Duplicate Webhooks in Laravel by Dispatching a Delayed Queued Job

laravel webhooks queues
by codesnips 3 tabs
php
<?php

namespace App\Services;

use App\Models\Order;
use Illuminate\Support\Facades\Cache;

Cache Expensive Dashboard Aggregates and Bust Them on Write in Laravel

laravel caching redis
by codesnips 4 tabs
ruby
class CacheNamespace
  attr_reader :name

  def initialize(name, store: Rails.cache)
    @name = name.to_s
    @store = store

Cache Key Versioning with a Single “namespace”

rails caching cache-invalidation
by codesnips 3 tabs
ruby
require "sidekiq/api"

class QueueDepthGuard
  class QueueSaturated < StandardError
    attr_reader :queue, :depth

Background Job Backpressure with Queue Depth Guard

rails reliability sidekiq
by codesnips 3 tabs
lua
-- KEYS[1] = current window key, KEYS[2] = previous window key
-- ARGV: limit, window_ms, elapsed_ms
local limit = tonumber(ARGV[1])
local window = tonumber(ARGV[2])
local elapsed = tonumber(ARGV[3])

Sliding-Window Rate Limiting for Express Routes Backed by Redis

express redis rate-limiting
by codesnips 4 tabs
python
import json
import secrets
import time
from typing import Optional

import redis.asyncio as redis

Sliding-Window Session Token Expiry With FastAPI Middleware and Redis

fastapi redis sessions
by codesnips 3 tabs
erb
{% load cache %}
<section class="dashboard">
  <h1>{{ team.name }} — Overview</h1>

  {% cache 3600 team_order_stats team.id stats_version %}
    <div class="stat-grid">

Cache an Expensive Dashboard Fragment with Django's Template Cache Tag and Signal-Based Invalidation

django caching template-cache
by codesnips 3 tabs
typescript
import {
  WebSocketGateway,
  WebSocketServer,
  SubscribeMessage,
  OnGatewayConnection,
  OnGatewayDisconnect,

Room-Based Live Notifications over a NestJS WebSocket Gateway

nestjs websockets socket-io
by codesnips 4 tabs