static int parse_sort_options(SortOptions& options, const StringArray& args) { for (uint32 i = 0; i < args.size(); i++) { if (!strcasecmp(args[i].c_str(), "asc")) { options.is_desc = false; } else if (!strcasecmp(args[i].c_str(), "desc")) { options.is_desc = true; } else if (!strcasecmp(args[i].c_str(), "alpha")) { options.with_alpha = true; } else if (!strcasecmp(args[i].c_str(), "limit") && i < args.size() - 2) { options.with_limit = true; if (!string_toint32(args[i + 1], options.limit_offset) || !string_toint32(args[i + 2], options.limit_count)) { return -1; } i += 2; } else if (!strcasecmp(args[i].c_str(), "store") && i < args.size() - 1) { options.store_dst = args[i + 1].c_str(); i++; } else if (!strcasecmp(args[i].c_str(), "by") && i < args.size() - 1) { options.by = args[i + 1].c_str(); if (!strcasecmp(options.by, "nosort")) { options.by = NULL; options.nosort = true; } i++; } else if (!strcasecmp(args[i].c_str(), "get") && i < args.size() - 1) { options.get_patterns.push_back(args[i + 1].c_str()); i++; } else { DEBUG_LOG("Invalid sort option:%s", args[i].c_str()); return -1; } } return 0; }
int ArdbServer::GetRange(ArdbConnContext& ctx, RedisCommandFrame& cmd) { int32 start, end; if (!string_toint32(cmd.GetArguments()[1], start) || !string_toint32(cmd.GetArguments()[2], end)) { fill_error_reply(ctx.reply, "value is not an integer or out of range"); return 0; } std::string v; m_db->GetRange(ctx.currentDB, cmd.GetArguments()[0], start, end, v); fill_str_reply(ctx.reply, v); return 0; }
int ArdbServer::SetRange(ArdbConnContext& ctx, RedisCommandFrame& cmd) { int32 offset; if (!string_toint32(cmd.GetArguments()[1], offset)) { fill_error_reply(ctx.reply, "value is not an integer or out of range"); return 0; } int ret = m_db->SetRange(ctx.currentDB, cmd.GetArguments()[0], offset, cmd.GetArguments()[2]); fill_int_reply(ctx.reply, ret); return 0; }
int Comms::Sort(Context& ctx, RedisCommandFrame& cmd) { bool is_desc = false, with_alpha = false, with_limit = false; const ArgumentArray& args = cmd.GetArguments(); const std::string& key = args[0]; std::string by, store_dst; mmkv::StringArray get_patterns; int limit_offset = 0, limit_count = -1; for (uint32 i = 1; i < args.size(); i++) { if (!strcasecmp(args[i].c_str(), "asc")) { is_desc = false; } else if (!strcasecmp(args[i].c_str(), "desc")) { is_desc = true; } else if (!strcasecmp(args[i].c_str(), "alpha")) { with_alpha = true; } else if (!strcasecmp(args[i].c_str(), "limit") && (i + 2) < args.size()) { with_limit = true; if (!string_toint32(args[i + 1], limit_offset) || !string_toint32(args[i + 2], limit_count)) { return false; } i += 2; } else if (!strcasecmp(args[i].c_str(), "store") && i < args.size() - 1) { store_dst = args[i + 1]; i++; } else if (!strcasecmp(args[i].c_str(), "by") && i < args.size() - 1) { by = args[i + 1]; i++; } else if (!strcasecmp(args[i].c_str(), "get") && i < args.size() - 1) { get_patterns.push_back(args[i + 1].c_str()); i++; } else { DEBUG_LOG("Invalid sort option:%s", args[i].c_str()); return false; } } int err = 0; if (store_dst.empty()) { ctx.reply.type = REDIS_REPLY_ARRAY; mmkv::StringArrayResult results(ReplyResultStringAlloc, &ctx.reply); err = m_kv_store->Sort(ctx.currentDB, key, by, limit_offset, limit_count, get_patterns, is_desc, with_alpha, store_dst, results); } else { ctx.reply.type = REDIS_REPLY_INTEGER; mmkv::StringArrayResult results; err = m_kv_store->Sort(ctx.currentDB, key, by, limit_offset, limit_count, get_patterns, is_desc, with_alpha, store_dst, results); ctx.reply.integer = err >= 0 ? err : 0; if(err > 0) { FireKeyChangedEvent(ctx, store_dst); } } if (err < 0) { FillErrorReply(ctx, err); } return 0; }