I'd like to store a product's quantity along with its ID using Redis. Here's what I have right now:
def add
$redis.sadd current_user_cart, params[:product_id]
redirect_to carts_show_path(current_user_cart)
render json: current_user.cart_count, status: 200
end
How can I store more than one value in a single key? Do I need to use a hash?
Yes. Redis is a key/value store. Meaning that it only has 2 columns... One is the key and the second one is the value, which I would in your case define as a JSON over a hash.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.