推荐商品

2020-06-23  本文已影响0人  神仙苏醒

此案例是一个推荐商品的小demo,用redis的sortset 结构,

  /**
     * 继续购买商品(多个商品需要循环处理,相互加分)
     * @param productId 当前购买的商品
     * @param otherProdeuctId 当前和productId 一起购买的其他商品
     */
    public void continuePurchase(long productId, long otherProdeuctId){
        jedis.zincrby("continue_purchase_products::" + productId,1 ,
                String.valueOf(otherProdeuctId));
    }
 /**
     * 推荐其他人购买过的其他商品
     * @param productId
     * @return
     */
    public Set<Tuple> getRecommendProducts(long productId){
        return jedis.zrevrangeWithScores("continue_purchase_products::" + productId,0,2);
    }

非常巧妙的一个小方式 解决了小型系统的推荐问题

上一篇 下一篇

猜你喜欢

热点阅读