Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/redis/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails 使用Redis的Rails购物车:存储商品数量_Ruby On Rails_Redis_Shopping Cart - Fatal编程技术网

Ruby on rails 使用Redis的Rails购物车:存储商品数量

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是一个键/值存储。这意

我想使用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是一个键/值存储。这意味着它只有两列。。。 一个是键,第二个是值,在您的例子中,我将其定义为哈希上的JSON