Ruby on rails 使用Redis的Rails购物车:存储商品数量
我想使用Redis存储产品的数量及其ID。以下是我现在拥有的:Ruby on rails 使用Redis的Rails购物车:存储商品数量,ruby-on-rails,redis,shopping-cart,Ruby On Rails,Redis,Shopping Cart,我想使用Redis存储产品的数量及其ID。以下是我现在拥有的: 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 如何在一个键中存储多个值?我需要使用散列吗?是。 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
如何在一个键中存储多个值?我需要使用散列吗?是。
Redis是一个键/值存储。这意味着它只有两列。。。
一个是键,第二个是值,在您的例子中,我将其定义为哈希上的JSON