根据 Second Index和 mapred查询数据

application 查询方法

get_last_item() ->

    {ok, Pid} = riakc_pb_socket:start_link("127.0.0.1", 8087),

    Bucket = <<"rends/ejabberd/pubsub_item">> ,

    Inputs = {index, Bucket, <<"idx_int">>, 1}, 

    Query = [{map, {modfun, trend_riak, get_map_bucket_values}, none, false},%%需要借助测方法由<B,K>转换成到value

                   {reduce,  {modfun, trend_riak, get_reduce_bucket_values}, get_last_entry, true}],  %%得到最后一条记录

    riakc_pb_socket:mapred(Pid, Inputs, Query).

 

打包在riak中的代码 :返回结果必须是list

 64 get_reduce_bucket_values(Records, get_last_entry)->

 65     io:format("get_last_entry Records = ~p~n", [Records]),

 66     F = fun(#pubsub_item{published=Published, level=Level},

 67             #pubsub_item{published=Published2, level=Level2}) ->

 68             if Level < Level2 -> true;     

 69                Level == Level2 ->             

 70                     if  Published < Published2 -> true;

 71                         true -> false                  

 72                     end;  

 73                true -> false

 74             end

 75         end,

 76     case lists:sort(F, Records) of 

 77         [] -> [];

 78         [PublishItem] -> [PublishItem];

 79         List when is_list(List)->  [hd(List)]                                                                                                                                                 

 80     end;

 81 get_reduce_bucket_values(Records, {Start, Max})->


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值