Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Decrement score in Redis or remove if 0

Tags:

redis

How can I decrement score of one Redis element by 1 in sorted set or remove it if it's value is 0? Currently I am using $redis.zincrby user_cart, -1, params[:product_id] (Rails 4.1.4), but I get negative values.

Thanks in advance!

like image 904
Kerozu Avatar asked Nov 01 '14 21:11

Kerozu


1 Answers

ZINCRBY's reply is the new score so you can check it and issue a ZREM if it is < 1.

like image 100
Itamar Haber Avatar answered Sep 19 '22 11:09

Itamar Haber