Crell,
@Crell@phpc.social avatar

Someone please explain to me how TF to use in (6, specifically, for now) without just praying that I put the right method name on a facade? How can I inject it instead like a grown up?

Seriously, I can find nothing for how to use basics like incr()/decr() other than "it will simply pass the arguments."

hunter,
@hunter@social.skrasek.us avatar

@Crell believe you’re looking for Illuminate\Redis\Connections\Connection

lhengstmengel,
@lhengstmengel@mastodon.nl avatar

@Crell I assume you want to use caching with redis configured as cache driver? Then you can inject the \Illuminate\Contracts\Cache\Repository interface and just do $cache->increment('foo', 2) etc.

Crell,
@Crell@phpc.social avatar

@lhengstmengel This particular use isn't a cache call.

lhengstmengel,
@lhengstmengel@mastodon.nl avatar

@Crell I never had to interact directly with redis myself from laravel but indeed it seems harder than it should be. I guess you can inject \Illuminate\Contracts\Redis\Connection and then there is a "command" instance method to send raw redis commands to the server but I can't test it right now.

joepferguson,
@joepferguson@phpc.social avatar

@Crell All of the Redis methods should have a static method you could call.

$redis->incr('user_visits', 1);  

Should increment the user_visits key by 1 in the defined Redis connection.

Crell,
@Crell@phpc.social avatar

@joepferguson I cannot even find what the $redis variable would be. The docs are useless for anything but the facade. In 5.1 there was a Database class for it, but it's gone in 6 and there is no "incr"/"decr" method anywhere at all that I can find.

joepferguson,
@joepferguson@phpc.social avatar

@Crell The facade should provide the methods as well.

I would expect this to work:

Redis::incr('user_visits', 1);  

If you'd prefer to skip those methods you can do Redis::command() and run a raw Redis command.

https://laravel.com/docs/6.x/redis#interacting-with-redis

Crell,
@Crell@phpc.social avatar

@joepferguson OK, but what if I DON'T want the facade? I want something injected, as the 5.1 code already was. I haven't figured out what class to even type against.

joepferguson,
@joepferguson@phpc.social avatar

@Crell I'm rusty on this as I've given in and used the static methods for the sake of upgrading ease.

I think you'd inject Illuminate\Support\Facades\Redis but you might find something already registered in the app container?

Crell,
@Crell@phpc.social avatar

@joepferguson Eh? The facades aren't instantiable, are they?

How does one mock out Redis then, if using the facades?

joepferguson,
@joepferguson@phpc.social avatar

@Crell I'm browsing through vendor/laravel/framework/src/Illuminate/Redis (granted a recent framework version) but I don't see much here. I always forget where Laravel starts and Predis/phpRedis begin.

joepferguson,
@joepferguson@phpc.social avatar

@Crell

The docs suggest this would work but do not work on my newer version

use Illuminate\Support\Facades\Redis;

$redis = Redis::connection();

skobkin,
@skobkin@lor.sh avatar

@Crell
Use PSR cache interface?

Crell,
@Crell@phpc.social avatar

@skobkin Not actually relevant in this situation. (Also, this is Laravel; they don't care about PSRs.)

skobkin,
@skobkin@lor.sh avatar

@Crell
My bad, maybe it's just my project.
I'm more of Symfony guy myself, so I'm not using those awful facades even working with Laravel 🙄

Crell,
@Crell@phpc.social avatar

@skobkin I wish I could avoid them...

  • All
  • Subscribed
  • Moderated
  • Favorites
  • Redis
  • DreamBathrooms
  • magazineikmin
  • tacticalgear
  • InstantRegret
  • ethstaker
  • rosin
  • love
  • Youngstown
  • slotface
  • ngwrru68w68
  • kavyap
  • GTA5RPClips
  • mdbf
  • everett
  • anitta
  • thenastyranch
  • Leos
  • cisconetworking
  • Durango
  • khanakhh
  • cubers
  • osvaldo12
  • normalnudes
  • provamag3
  • modclub
  • tester
  • megavids
  • JUstTest
  • All magazines