Add skeleton for zset and hset commands

This commit is contained in:
Roman Gershman 2022-02-28 23:19:21 +02:00
parent f255d17a72
commit 8c95facb47
6 changed files with 195 additions and 21 deletions

View file

@ -1022,10 +1022,10 @@ unsigned char *zzlFind(unsigned char *lp, sds ele, double *score) {
sptr = lpNext(lp,eptr);
serverAssert(sptr != NULL);
/* Matching element, pull out score. */
if (score != NULL) *score = zzlGetScore(sptr);
return eptr;
}
/* Matching element, pull out score. */
if (score != NULL) *score = zzlGetScore(sptr);
return eptr;
}
return NULL;
}
@ -1378,10 +1378,10 @@ int zsetAdd(robj *zobj, double score, sds ele, int in_flags, int *out_flags, dou
{
zsetConvert(zobj,OBJ_ENCODING_SKIPLIST);
} else {
zobj->ptr = zzlInsert(zobj->ptr,ele,score);
if (newscore) *newscore = score;
*out_flags |= ZADD_OUT_ADDED;
return 1;
zobj->ptr = zzlInsert(zobj->ptr,ele,score);
if (newscore) *newscore = score;
*out_flags |= ZADD_OUT_ADDED;
return 1;
}
} else {
*out_flags |= ZADD_OUT_NOP;
@ -2552,7 +2552,7 @@ void zunionInterDiffGenericCommand(client *c, robj *dstkey, int numkeysIndex, in
if (setnum < 1) {
addReplyErrorFormat(c,
"at least 1 input key is needed for %s", c->cmd->name);
"at least 1 input key is needed for '%s' command", c->cmd->fullname);
return;
}
@ -3664,7 +3664,7 @@ void zrangeGenericCommand(zrange_result_handler *handler, int argc_start, int st
handler->beginResultEmission(handler);
handler->finalizeResultEmission(handler, 0);
} else {
addReply(c,shared.emptyarray);
addReply(c, shared.emptyarray);
}
goto cleanup;
}
@ -3824,7 +3824,7 @@ void genericZpopCommand(client *c, robj **keyv, int keyc, int where, int emitkey
if (reply_nil_when_empty) {
addReplyNullArray(c);
} else {
addReply(c,shared.emptyarray);
addReply(c,shared.emptyarray);
}
return;
}
@ -3917,13 +3917,13 @@ void genericZpopCommand(client *c, robj **keyv, int keyc, int where, int emitkey
++result_count;
} while(--rangelen);
/* Remove the key, if indeed needed. */
if (zsetLength(zobj) == 0) {
/* Remove the key, if indeed needed. */
if (zsetLength(zobj) == 0) {
if (deleted) *deleted = 1;
dbDelete(c->db,key);
notifyKeyspaceEvent(NOTIFY_GENERIC,"del",key,c->db->id);
}
dbDelete(c->db,key);
notifyKeyspaceEvent(NOTIFY_GENERIC,"del",key,c->db->id);
}
if (c->cmd->proc == zmpopCommand) {
/* Always replicate it as ZPOP[MIN|MAX] with COUNT option instead of ZMPOP. */
@ -3998,12 +3998,12 @@ void blockingGenericZpopCommand(client *c, robj **keys, int numkeys, int where,
/* Empty zset, move to next key. */
if (llen == 0) continue;
/* Non empty zset, this is like a normal ZPOP[MIN|MAX]. */
/* Non empty zset, this is like a normal ZPOP[MIN|MAX]. */
genericZpopCommand(c, &key, 1, where, 1, count, use_nested_array, reply_nil_when_empty, NULL);
if (count == -1) {
/* Replicate it as ZPOP[MIN|MAX] instead of BZPOP[MIN|MAX]. */
rewriteClientCommandVector(c,2,
rewriteClientCommandVector(c,2,
(where == ZSET_MAX) ? shared.zpopmax : shared.zpopmin,
key);
} else {
@ -4015,7 +4015,7 @@ void blockingGenericZpopCommand(client *c, robj **keys, int numkeys, int where,
decrRefCount(count_obj);
}
return;
return;
}
/* If we are not allowed to block the client and the zset is empty the only thing

View file

@ -3,11 +3,11 @@ cxx_link(dragonfly base dragonfly_lib)
add_library(dragonfly_lib command_registry.cc common.cc config_flags.cc
conn_context.cc db_slice.cc debugcmd.cc dragonfly_listener.cc
dragonfly_connection.cc engine_shard_set.cc generic_family.cc
dragonfly_connection.cc engine_shard_set.cc generic_family.cc hset_family.cc
list_family.cc main_service.cc memcache_parser.cc rdb_load.cc rdb_save.cc replica.cc
snapshot.cc redis_parser.cc reply_builder.cc script_mgr.cc server_family.cc
set_family.cc
string_family.cc transaction.cc)
string_family.cc transaction.cc zset_family.cc)
cxx_link(dragonfly_lib dfly_core redis_lib uring_fiber_lib
fibers_ext strings_lib http_server_lib tls_lib)

50
src/server/hset_family.cc Normal file
View file

@ -0,0 +1,50 @@
// Copyright 2022, Roman Gershman. All rights reserved.
// See LICENSE for licensing terms.
//
#include "server/hset_family.h"
#include "server/command_registry.h"
namespace dfly {
void HSetFamily::HDel(CmdArgList args, ConnectionContext* cntx) {
}
void HSetFamily::HLen(CmdArgList args, ConnectionContext* cntx) {
}
void HSetFamily::HExists(CmdArgList args, ConnectionContext* cntx) {
}
void HSetFamily::HGet(CmdArgList args, ConnectionContext* cntx) {
}
void HSetFamily::HIncrBy(CmdArgList args, ConnectionContext* cntx) {
}
void HSetFamily::HSet(CmdArgList args, ConnectionContext* cntx) {
}
void HSetFamily::HSetNx(CmdArgList args, ConnectionContext* cntx) {
}
void HSetFamily::HStrLen(CmdArgList args, ConnectionContext* cntx) {
}
using CI = CommandId;
#define HFUNC(x) SetHandler(&HSetFamily::x)
void HSetFamily::Register(CommandRegistry* registry) {
*registry << CI{"HDEL", CO::FAST | CO::WRITE, -3, 1, 1, 1}.HFUNC(HDel)
<< CI{"HLEN", CO::FAST | CO::READONLY, 2, 1, 1, 1}.HFUNC(HLen)
<< CI{"HEXISTS", CO::FAST | CO::READONLY, 3, 1, 1, 1}.HFUNC(HExists)
<< CI{"HGET", CO::FAST | CO::READONLY, 3, 1, 1, 1}.HFUNC(HGet)
<< CI{"HINCRBY", CO::WRITE | CO::DENYOOM | CO::FAST, 4, 1, 1, 1}.HFUNC(HIncrBy)
<< CI{"HSET", CO::WRITE | CO::FAST | CO::DENYOOM, -4, 1, 1, 1}.HFUNC(HSet)
<< CI{"HSETNX", CO::WRITE | CO::DENYOOM | CO::FAST, 4, 1, 1, 1}.HFUNC(HSetNx)
<< CI{"HSTRLEN", CO::READONLY | CO::FAST, 3, 1, 1, 1}.HFUNC(HStrLen);
}
} // namespace dfly

29
src/server/hset_family.h Normal file
View file

@ -0,0 +1,29 @@
// Copyright 2022, Roman Gershman. All rights reserved.
// See LICENSE for licensing terms.
//
#pragma once
#include "server/common_types.h"
namespace dfly {
class ConnectionContext;
class CommandRegistry;
class HSetFamily {
public:
static void Register(CommandRegistry* registry);
private:
static void HDel(CmdArgList args, ConnectionContext* cntx);
static void HLen(CmdArgList args, ConnectionContext* cntx);
static void HExists(CmdArgList args, ConnectionContext* cntx);
static void HGet(CmdArgList args, ConnectionContext* cntx);
static void HIncrBy(CmdArgList args, ConnectionContext* cntx);
static void HSet(CmdArgList args, ConnectionContext* cntx);
static void HSetNx(CmdArgList args, ConnectionContext* cntx);
static void HStrLen(CmdArgList args, ConnectionContext* cntx);
};
} // namespace dfly

64
src/server/zset_family.cc Normal file
View file

@ -0,0 +1,64 @@
// Copyright 2022, Roman Gershman. All rights reserved.
// See LICENSE for licensing terms.
//
#include "server/zset_family.h"
extern "C" {
#include "redis/zset.h"
}
#include "base/logging.h"
#include "server/command_registry.h"
#include "server/conn_context.h"
#include "server/engine_shard_set.h"
namespace dfly {
using namespace std;
namespace {
using CI = CommandId;
} // namespace
void ZSetFamily::ZCard(CmdArgList args, ConnectionContext* cntx) {
(*cntx)->SendLong(0);
}
void ZSetFamily::ZAdd(CmdArgList args, ConnectionContext* cntx) {
(*cntx)->SendLong(0);
}
void ZSetFamily::ZIncrBy(CmdArgList args, ConnectionContext* cntx) {
(*cntx)->SendLong(0);
}
void ZSetFamily::ZRange(CmdArgList args, ConnectionContext* cntx) {
}
void ZSetFamily::ZRangeByScore(CmdArgList args, ConnectionContext* cntx) {
}
void ZSetFamily::ZRem(CmdArgList args, ConnectionContext* cntx) {
(*cntx)->SendLong(0);
}
void ZSetFamily::ZScore(CmdArgList args, ConnectionContext* cntx) {
(*cntx)->SendDouble(0);
}
#define HFUNC(x) SetHandler(&ZSetFamily::x)
void ZSetFamily::Register(CommandRegistry* registry) {
*registry << CI{"ZCARD", CO::FAST | CO::READONLY, 2, 1, 1, 1}.HFUNC(ZCard)
<< CI{"ZADD", CO::FAST | CO::WRITE | CO::DENYOOM, -4, 1, 1, 1}.HFUNC(ZAdd)
<< CI{"ZINCRBY", CO::FAST | CO::WRITE | CO::DENYOOM, 4, 1, 1, 1}.HFUNC(ZIncrBy)
<< CI{"ZREM", CO::FAST | CO::WRITE, -3, 1, 1, 1}.HFUNC(ZRem)
<< CI{"ZRANGE", CO::READONLY, -4, 1, 1, 1}.HFUNC(ZRange)
<< CI{"ZRANGEBYSCORE", CO::READONLY, -4, 1, 1, 1}.HFUNC(ZRangeByScore)
<< CI{"ZSCORE", CO::READONLY | CO::FAST, 3, 1, 1, 1}.HFUNC(ZScore);
}
} // namespace dfly

31
src/server/zset_family.h Normal file
View file

@ -0,0 +1,31 @@
// Copyright 2022, Roman Gershman. All rights reserved.
// See LICENSE for licensing terms.
//
#pragma once
#include <variant>
#include "core/op_status.h"
#include "server/common_types.h"
namespace dfly {
class ConnectionContext;
class CommandRegistry;
class ZSetFamily {
public:
static void Register(CommandRegistry* registry);
private:
static void ZCard(CmdArgList args, ConnectionContext* cntx);
static void ZAdd(CmdArgList args, ConnectionContext* cntx);
static void ZIncrBy(CmdArgList args, ConnectionContext* cntx);
static void ZRange(CmdArgList args, ConnectionContext* cntx);
static void ZRem(CmdArgList args, ConnectionContext* cntx);
static void ZScore(CmdArgList args, ConnectionContext* cntx);
static void ZRangeByScore(CmdArgList args, ConnectionContext* cntx);
};
} // namespace dfly