2017-08-11 31 views
0

我想使用Redis存儲產品的數量及其ID。以下是我現在所擁有的:使用Redis導軌購物車:存儲項目數量

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 

如何在單個密鑰中存儲多個值?我需要使用散列嗎?

回答

1

是的。 Redis是一個關鍵/價值商店。這意味着它只有2列... 一個是關鍵,第二個是值,我會在你的情況下定義爲一個JSON在散列。