CACHES = {
"default": {
"BACKEND": "django_redis.cache.RedisCache",
"LOCATION": "redis://127.0.0.1:6379/1",
"OPTIONS": {
"CLIENT_CLASS": "django_redis.client.DefaultClient",
package pool
import "context"
type Job func(ctx context.Context) error
class CreateAccountsAndLedger < ActiveRecord::Migration[7.1]
def change
create_table :accounts do |t|
t.string :name, null: false
t.string :currency, null: false, default: "USD"
t.bigint :balance_cents, null: false, default: 0
use std::sync::Arc;
use std::time::Duration;
use futures::stream::{FuturesUnordered, StreamExt};
use reqwest::Client;
use tokio::sync::Semaphore;
class TypingPresence
EXPIRE_AFTER = 6 # seconds
def initialize(room, redis: Redis.current)
@room = room
@redis = redis
package worker
import "context"
func (p *Pool) Submit(job Job) error {
// Reject fast if draining, otherwise enqueue with backpressure.
class CreateIdempotencyKeys < ActiveRecord::Migration[7.1]
def change
create_table :idempotency_keys do |t|
t.string :key, null: false
t.string :request_path, null: false
t.datetime :locked_at
module ConnectionHealth
extend ActiveSupport::Concern
def with_fresh_connection
conn = ActiveRecord::Base.connection
conn.verify! # pings and reconnects if the socket is dead
import type { Redis } from "ioredis";
export interface StoredResponse {
status: "pending" | "completed";
fingerprint: string;
httpStatus?: number;
public final class Debouncer implements AutoCloseable {
private final ScheduledExecutorService scheduler;
private final long delayMillis;
private final AtomicReference<ScheduledFuture<?>> pending = new AtomicReference<>();
package metrics
import "time"
type bucket struct {
start time.Time
use std::sync::{Arc, Mutex};
use std::thread;
fn main() {
let counter = Arc::new(Mutex::new(0));
let mut handles = vec![];