Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

command develop tasks #30

Open
2 tasks done
lqxhub opened this issue Nov 7, 2023 · 20 comments
Open
2 tasks done

command develop tasks #30

lqxhub opened this issue Nov 7, 2023 · 20 comments
Assignees
Labels
0.1.0 core ✏️ Feature New feature or request

Comments

@lqxhub
Copy link
Collaborator

lqxhub commented Nov 7, 2023

pikiwidb 命令处理相关功能的开发

在pikiwidb中, 每一个命令处理对应一个C++的class, 当服务端收到一条命令时,会去找这个命令处理对应的对象, 如果没有找到返回错误, 如果找到后, 执行对应的命令.

函数入口(这是临时处理函数,后面会调整这个函数的实现)

int PClient::handlePacketNew(const std::vector<std::string>& params, const std::string& cmd) {

命令处理相关代码

BaseCmd 是所有命令处理类的基类,

public:

所有命令处理的class需要继承这个类, 并且重写 DoInitialDoCmd 这两个虚函数.

DoInitial 函数, 在命令执行前调用, 负责处理命令执行需要的参数, 例如把 命令的key找到, 命令参数的大小写转换等等
DoCmd 函数, 命令执行时的逻辑处理函数, 负责整个命令的具体处理逻辑

需要在 构造函数中,给 BaseCmdflag 赋值, flag值根据实际情况确定, 例子:

GetCmd::GetCmd(const std::string& name, int16_t arity)

命令分类

命令分为两大类

  • 没有子命令的命令, 常见的 命令都是 没有子命令的, 例如 GET, SET, HSET, HMGET 等等
  • 有子命令的命令, 常见的 CONFIG, CLINET 等等, 这些命令通过第二个参数来区分, 具体执行的是哪个命令, 每个不同的子命令, 有不同的处理逻辑, 例如 CONFIG GET XXXCONFIG SET XXX 是两个不同的命令.
    有子命令的需要特殊处理, 具体可以参考 CONFIG 命令的实现
    class CmdConfig : public BaseCmdGroup {

命令注册

所有的命令需要把命令对象的指针注册(写入)到 commandManager 这个map中, map的 key 是 命令名, value 是处理这个命令的指针

命令注册函数

void CmdTableManager::InitCmdTable() {

代码文件

代码文件, 每个类型的命令有一个单独的文件, 并且命令处理相关的文件以 cmd 开头, 例如 STRING 相关的命令, 文件名cmd_kv.cccmd_kv.h, HASH 相关的命令 cmd_hash.cc, cmd_hash.h

实现步骤

@AlexStocks
Copy link
Contributor

AlexStocks commented Nov 11, 2023

string:

get done
set done
strlen done
mset done
setnx done
setex done
psetex done
getset done
mget done
append done
bitcount done
bitop done
getbit done
setbit done
incr done
decr done
incrby done
incrbyfloat done
decrby done
getrange done
setrange done
msetnx done

This was referenced Dec 5, 2023
@AlexStocks AlexStocks added ✏️ Feature New feature or request 0.1.0 core labels Dec 9, 2023
@AlexStocks
Copy link
Contributor

AlexStocks commented Dec 16, 2023

hashtable

ncy:
hlen over
hstrlen over
hset over
hget over
hgetall over
hmset over
hmget over
hkeys over
hrandfield over
hscan over

csx:
hsetnx done
hincrby done

pcy:
hincrbyfloat done
hvals over

qxh:
hdel over

ncy:
hexists done

@AlexStocks
Copy link
Contributor

AlexStocks commented Dec 16, 2023

set:

whr:
sadd over
scard done

cwl:
sismember over

crp:
srem over
srandmember done

whr:
smembers done
sdiff done
sdiffstore done

cwl:
sinter done
sinterstore done
sscan done

Henry:
sunion over
sunionstore over

pcy:
smove done
spop done

@longfar-ncy
Copy link
Collaborator

longfar-ncy commented Dec 16, 2023

我写了个小工具用于对比 pikiwidb 与 redis 输出,在实现命令时可以用来与 redis 对比。
代码放在我 fork 的仓库了:https://github.com/longfar-ncy/pikiwidb/tree/feat/pr-cli/tool/pr-cli
效果如图:
image
image

@578223592

This comment was marked as resolved.

@Centurybbx
Copy link
Collaborator

Centurybbx commented Dec 30, 2023

list:

cwl:
lpush done
rpush done

liuhuan:
lpushx done
rpushx done
lpop done
lindex done
llen done

csq:
rpop done

cwl:
lset done
ltrim done
lrange done
linsert done

henry:
lrem done

lh:
blpop
brpop
rpoplpush 从 Redis 6.2.0起, RPOPLPUSH 被废弃,使用 LMOVE 替代
brpoplpush 从 Redis 6.2.0 起,建议使用 BLMOVE 替代 BRPOPLPUSH

@panlei-coder
Copy link
Collaborator

panlei-coder commented Jan 13, 2024

zset done

whr:
zcard done

pl:
zrank done
zrevrank done
zrem done
zincrby done

wxr:
zadd done
zrevrange done
zrangebyscore done

csx:
zrevrangebyscore done
zremrangebyrank done
zrangebylex done
zrevrangebylex done
zscore done
zrange done
zremrangebyscore done

@AlexStocks
Copy link
Contributor

AlexStocks commented Jan 20, 2024

key:

henry:
exists done
del done

lft:
type done
expire done
ttl done

cwl:
pexpire done
pttl done
expireat done
pexpireat done

lh:
persist done
keys done

@AlexStocks
Copy link
Contributor

AlexStocks commented Jan 20, 2024

// admin

select done

dingxiaoshuai
config done

panlei:
scan

pcy
flushdb done
flushall done

lft:
hello
slowlog

renzhenfeng(0629):
dbsize pr
bgsave pr

lh:
save 实现成本比较高
lastsave 实现成本比较高

tangruilin:
echo pr
auth pr

bzm:
shutdown done

smj
info pr

zzl:
rename done
renamenx done

zhy: 2024.6.15
sort done

gkj: 2024.6.15
client pr
monitor pr

optics:
debug done

ping done

todo:
randomkey
move:涉及多 db 的时候,保证一致性比较难,暂时不做

@hahahashen
Copy link
Contributor

hahahashen commented Apr 2, 2024

我想认领一下string 的 msetnx命令的实现,我目前的想法是:参照PikiviDB MSetCmd类的实现和pika MsetCmd MsetnxCmd类的实现,在PikiwiDB实现一个新的MSetNXCmd类,这个类主要的函数有DoInitial,DoCmd
DoInitial函数给client key赋值,类型为std::vectorstd::string,也就是msetnx命令将要赋值的keys
DoCmd函数是msetnx命令处理的处理逻辑,参照pika实现,调用storage层的MSetnx函数,这个函数目前在PikiwiDB已经被实现了;但storage层的MSetnx函数并没有上锁,所以具体实现的时候还要再看一下这个细节
其他还有一些初始化相关的地方,目前看到了两处,一处是cmd_table_manager.cc处InitCmdTable要ADD_COMMAND,另一处是base_cmd.h文件中也要添加对应的常量

@AlexStocks
Copy link
Contributor

AlexStocks commented Apr 3, 2024

测试:
1 string 缺少 go-test
2 hashtable 有一半命令没有 go-test
3 tcl 测试

@Mixficsol
Copy link
Collaborator

Go Test测试移植Pika的到PikiwiDB @dingxiaoshuai123

@Issues-translate-bot
Copy link

Bot detected the issue body's language is not English, translate it automatically.


Go Test tests porting Pika to PikiwiDB @dingxiaoshuai123

@panlei-coder
Copy link
Collaborator

@Tangruilin 看todo

@Issues-translate-bot
Copy link

Bot detected the issue body's language is not English, translate it automatically.


@Tangruilin nantodo

@Tangruilin
Copy link
Collaborator

ping

trl:
ping

我先把这个实现以下吧

@Issues-translate-bot
Copy link

Bot detected the issue body's language is not English, translate it automatically.


ping

trl:
ping

Let me implement this first:

happy-v587 added a commit to happy-v587/pikiwidb that referenced this issue May 26, 2024
happy-v587 added a commit to happy-v587/pikiwidb that referenced this issue May 26, 2024
happy-v587 added a commit to happy-v587/pikiwidb that referenced this issue May 26, 2024
happy-v587 added a commit to happy-v587/pikiwidb that referenced this issue May 26, 2024
happy-v587 added a commit to happy-v587/pikiwidb that referenced this issue May 26, 2024
AlexStocks pushed a commit that referenced this issue May 29, 2024
@AlexStocks
Copy link
Contributor

RedisRaft 支持的 Redis 命令列表 https://github.com/RedisLabs/redisraft/blob/master/docs/Using.md

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
0.1.0 core ✏️ Feature New feature or request
Projects
None yet
Development

No branches or pull requests