command develop tasks
- Dominant language
- C++
- Stars
- 49
- Forks
- 8
- PR merge metrics
- No merged PRs in 30d
Description
pikiwidb 命令处理相关功能的开发
在pikiwidb中, 每一个命令处理对应一个C++的class, 当服务端收到一条命令时,会去找这个命令处理对应的对象, 如果没有找到返回错误, 如果找到后, 执行对应的命令.
函数入口(这是临时处理函数,后面会调整这个函数的实现) https://github.com/OpenAtomFoundation/pikiwidb/blob/e05878dfe99c232be3a6f40b6dc9ab73785c7db0/src/client.cc#L244
#### 命令处理相关代码
`BaseCmd` 是所有命令处理类的基类, https://github.com/OpenAtomFoundation/pikiwidb/blob/e05878dfe99c232be3a6f40b6dc9ab73785c7db0/src/base_cmd.h#L89
所有命令处理的class需要继承这个类, 并且重写 `DoInitial` 和 `DoCmd` 这两个虚函数.
`DoInitial` 函数, 在命令执行前调用, 负责处理命令执行需要的参数, 例如把 命令的key找到, 命令参数的大小写转换等等
`DoCmd` 函数, 命令执行时的逻辑处理函数, 负责整个命令的具体处理逻辑
需要在 构造函数中,给 `BaseCmd` 的 `flag` 赋值, flag值根据实际情况确定, 例子:https://github.com/OpenAtomFoundation/pikiwidb/blob/e05878dfe99c232be3a6f40b6dc9ab73785c7db0/src/cmd_kv.cc#L13
#### 命令分类
命令分为两大类
* 没有子命令的命令, 常见的 命令都是 没有子命令的, 例如 `GET`, `SET`, `HSET`, `HMGET` 等等
* 有子命令的命令, 常见的 `CONFIG`, `CLINET` 等等, 这些命令通过第二个参数来区分, 具体执行的是哪个命令, 每个不同的子命令, 有不同的处理逻辑, 例如 `CONFIG GET XXX`和 `CONFIG SET XXX` 是两个不同的命令.
有子命令的需要特殊处理, 具体可以参考 `CONFIG` 命令的实现 https://github.com/OpenAtomFoundation/pikiwidb/blob/e05878dfe99c232be3a6f40b6dc9ab73785c7db0/src/cmd_admin.h#L15
#### 命令注册
所有的命令需要把命令对象的指针注册(写入)到 commandManager 这个map中, map的 **key** 是 命令名, **value** 是处理这个命令的指针
命令注册函数
https://github.com/OpenAtomFoundation/pikiwidb/blob/e05878dfe99c232be3a6f40b6dc9ab73785c7db0/src/cmd_table_manager.cc#L20
#### 代码文件
代码文件, 每个类型的命令有一个单独的文件, 并且命令处理相关的文件以 `cmd` 开头, 例如 `STRING` 相关的命令, 文件名`cmd_kv.cc`和`cmd_kv.h`, `HASH` 相关的命令 `cmd_hash.cc`, `cmd_hash.h`
- [x] #31
- [x] #38
#### 实现步骤
- 1 看 Pika 实现;看 Redis 实现;看 PikiwiDB 当前的实现;在 PikiwiDB 重新实现;参照 https://github.com/OpenAtomFoundation/pika/tree/unstable/tests/integration 添加 go test
- 2 如果 Pika 与 Redis 有差异,按照 Redis 接口标准来,同时反哺给 Pika
- 3 示例 https://github.com/OpenAtomFoundation/pikiwidb/pull/107
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
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
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
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](https://redis.com.cn/commands/lmove.html) 替代
brpoplpush 从 Redis 6.2.0 起,建议使用 [BLMOVE](https://redis.com.cn/commands/blmove.html) 替代 [BRPOPLPUSH](https://redis.com.cn/commands/brpoplpush.html)
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
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
// admin
select done
dingxiaoshuai
config done
panlei:
scan
pcy
flushdb done
flushall done
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 的时候,保证一致性比较难,暂时不做
hello done
slowlog zrk
scan @mingxuan
Contributor guide
No contributing guide indexed for this repository
Research direction
Start with the unfinished command entries in the checklist, then read src/client.cc, src/base_cmd.h, src/cmd_table_manager.cc, and the relevant cmd_*.cc and .h files. Compare the Pika and Redis implementations and add the Go integration tests under tests/integration. Done means the selected command is implemented, registered, and covered by tests.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp, go, redis
- Domain
- backend, databases, testing
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 20/100