Summer Sale! All accounts are 50% off this week.

tinfoilman's avatar

Redis sorted set commands

Redis really frustrates me. Most documentation on the web is for running it on the command line, which I can get to work fine, but trying to do the same thing in my Laravel Vapor app always takes me a lot of fooling around. Some things work and some things don't. This one is really killing me.

I have a sorted set with key name 'reviews' that has 500 members. I want to be able to pull out 20 at a time. The Redis command should be:

ZREVRANGEBYSCORE key max min [WITHSCORES] [LIMIT offset count]

I have no problem getting the complete list in my app using:

Redis::zrevrangebyscore('reviews', 'inf', 0)

But how do I insert the Limit offset count part of the command? The closest I've come to making it work is this:

Redis::zrevrangebyscore('reviews', 'inf', 0, array('limit' => array(0, 20)));

The exception I get in Telescope is:

255      * @param  mixed  $min

256      * @param  mixed  $max

257      * @param  array  $options

258      * @return array

259      */

260     public function zrevrangebyscore($key, $min, $max, $options = [])

261     {

262         if (isset($options['limit'])) {

263             $options['limit'] = [

264                 $options['limit']['offset'],

265                 $options['limit']['count'],

266             ];

267         }

268 

269         return $this->command('zRevRangeByScore', [$key, $min, $max, $options]);

270     }

271 

272     /**

273      * Find the intersection between sets and store in a new set.

274      *

Can anyone please help me figure out what that exception is expecting to receive?

0 likes
0 replies

Please or to participate in this conversation.