【问题标题】:Rails shopping cart with Redis: storing item quantity使用 Redis 的 Rails 购物车:存储商品数量
【发布时间】:2023-03-15 19:55:01
【问题描述】:

我想使用 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

如何在一个键中存储多个值?我需要使用哈希吗?

【问题讨论】:

    标签: ruby-on-rails redis shopping-cart


    【解决方案1】:

    是的。 Redis 是一个键/值存储。这意味着它只有 2 列... 一个是键,第二个是值,在您的情况下,我将其定义为散列上的 JSON。

    【讨论】:

      猜你喜欢
      • 2018-02-22
      • 2015-06-01
      • 1970-01-01
      • 1970-01-01
      • 2017-06-05
      • 2021-11-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多