dimanche 1 septembre 2019

Laravel Redis key prefix not working as intended

I have a rather weird problem with Laravel lately that when I am storing something in Redis and then get the keys and try to retrieve the values using that key, I get null. However when I manually remove the prefix from the key via substring or something similar, I am able to retrieve the data. Example:

Redis::hmset('users:'.$db_user->id,$db_user->toArray());

Then I do the following to retrieve the stored keys:

foreach(Redis::redis->keys('users:*') as $key){
        Redis::redis->hgetall($key); //returns null
        Redis::hgetall(substr($key,18))); //returns the stored values
    }

A key would come out as:

redisser_database_users:78

Which is to be expected given the prefix settings in Laravel. Now I wonder if this behaviour is intended or not. If it is, it doesn't make a whole lot of sense to me.

Can this be fixed somehow so I can use the keys directly without manually cutting off the prefix?



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire