Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

flap152's avatar
Level 11

Using redis in your code, in vapor

I have redis set up on my vapor app/environment for caching, but I need to use redis in my code for functionality.

It works locally but when deployed I get errors on my first call to redis and it seems to be in the connection itself.

I assumed the config/environment variables were already set up to use redis, but maybe not.

Has anybody here used redis programmatically on vapor?

Note: I am using phpredis extension and not predis.

0 likes
9 replies
crnkovic's avatar

Did you provision a Elasticache redis cluster?

flap152's avatar
Level 11

Yes it is provisioned in Vapor, my vapor.yml has the cache: cachename entry and I see some activity on AWS monitoring (page caching at this point I guess)

flap152's avatar
Level 11

I found redis is functional on my vapor instance BUT some commands that work locally don't work on vapor (Win vs Linux?). ALSO, predis and phpredis do not behave the same, THEN using the Facades that handle the connection automatically hide the auto-complete I'd have using the classes directly... sigh.

flap152's avatar
flap152
OP
Best Answer
Level 11

A hint on debugging environment issues on Vapor: in AWS Lambda is a page where you can see all the injected environment variables. There I saw that Vapor indeed uses phpredis, I saw the url/port/password to the redis instance, etc.

neilgilmour's avatar

Something that caught me out was needing to wrap the key in {} as it's in a cluster, eg Redis::smove('{myset.original}', '{myset.new}', $value);

flap152's avatar
Level 11

@ITProperty Please understand it's 2 years later... No actual "solution" but we realized Vapor-AWS-redis used clusters that behave differently and don't necessarily support same instruction set. Pooling of commands was part of what we tried at the time, IIRC.

Please or to participate in this conversation.