Skip to content

[13.x] Ability to set session prefix for Redis#60700

Merged
taylorotwell merged 4 commits into
laravel:13.xfrom
jackbayliss:13.x-ability-set-set-session-prefix-on-redis
Jul 11, 2026
Merged

[13.x] Ability to set session prefix for Redis#60700
taylorotwell merged 4 commits into
laravel:13.xfrom
jackbayliss:13.x-ability-set-set-session-prefix-on-redis

Conversation

@jackbayliss

@jackbayliss jackbayliss commented Jul 8, 2026

Copy link
Copy Markdown
Contributor

On Redis providers like Upstash / clusters / ElastiCache and general managed redis services, you're limited to a single keystore (db0), so you can't isolate sessions from cache by using a separate store.

Sessions currently inherit the cache prefix by default with setups like:

SESSION_DRIVER=redis
CACHE_STORE=redis
SCHEDULE_CACHE_DRIVER=redis

This makes it extremely difficult to scan and figure out what's what, between cache and sessions. Meaning when you need to clear cache manually or clear space its complex.

This PR allows you to set a prefix, and is completely opt in, which mirrors the session.connection option.
it could be defaulted, but i'm not sure or in charge of those executive decisions. But, maybe this should be the default in 14.x to prevent confusion?

// config/session.php
'prefix' => env('SESSION_PREFIX', Str::slug((string) env('APP_NAME', 'laravel')).'-session-'),

I can move this to 14.x if you'd prefer too

Alternatively, we can do something like the below, but it was a lot less discoverable and confusing, which is why I thought of this PR.

// .env
// SESSION_STORE = sessions

// config/cache.php
  'sessions' => [
          'driver' => 'redis',
          'prefix' => '-session-',   
],

This PR will also assist #60705

@github-actions

github-actions Bot commented Jul 8, 2026

Copy link
Copy Markdown

Thanks for submitting a PR!

Note that draft PRs are not reviewed. If you would like a review, please mark your pull request as ready for review in the GitHub user interface.

Pull requests that are abandoned in draft may be closed due to inactivity.

@jackbayliss jackbayliss marked this pull request as ready for review July 9, 2026 12:18
@taylorotwell

Copy link
Copy Markdown
Member

Hmm, if we set the prefix here would it override or stomp on the cache prefix. Is that object shared between the two?

@jackbayliss

jackbayliss commented Jul 9, 2026

Copy link
Copy Markdown
Contributor Author

@taylorotwell I think its OK cause its cloned

clone $this->container->make('cache')->store($store),

So, they are both seperate at least that's how I read it :D (I did test it locally and it worked)

@taylorotwell taylorotwell merged commit 3093ff3 into laravel:13.x Jul 11, 2026
53 checks passed
@jackbayliss jackbayliss deleted the 13.x-ability-set-set-session-prefix-on-redis branch July 12, 2026 10:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants