Menu

1 / 2

A Redis-first alternative to spatie/laravel-permission, benchmarked

DEV Community·Sebastian Cabarcas·6 months ago
#tZBrMsFX
#laravel#redis#performance#permissions#spatie
Reading 0:00
15s threshold

TL;DR

I built a Redis-first roles & permissions package for Laravel called scabarcas/laravel-permissions-redis — Spatie-compatible API ( hasRole , hasPermissionTo , Blade directives, middleware), but the user→roles→permissions mapping lives in Redis SETs instead of being hydrated from the DB on every request.

Benchmark vs spatie/laravel-permission ^7.2 , with 5 warm-up + 30 measurement runs per scenario, GC reset between runs, predis client, SQLite + local Redis on Apple Silicon:

Workload Spatie p50 Redis p50 Speedup DB queries reduced

1 authorization-heavy request 13.76 ms 1.26 ms 10.94x 4 → 1 (75%)

10 iterations 138.87 ms 13.01 ms 10.68x 40 → 10 (75%)

50 iterations 696.73 ms 63.79 ms 10.92x 200 → 50 (75%)

The speedup is consistent — Redis lookups are near-constant time; Spatie's per-request relation hydration scales linearly.…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.