Menu

Post image 1
Post image 2
1 / 2
0

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

DEV Community·Sebastian Cabarcas·21 days ago
#tZBrMsFX
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. The whole bench repo is public if you want to reproduce: laravel-permissions-redis-benchmark . Rest of the post is the why and the when not to use it .…

Continue reading — create a free account

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

Read More