sofastack / sofa-jraft

A production-grade java implementation of RAFT consensus algorithm.
https://www.sofastack.tech/projects/sofa-jraft/
Apache License 2.0
3.57k stars 1.14k forks source link

Is there a containsKey api? #288

Closed zhangjun050754 closed 4 years ago

zhangjun050754 commented 4 years ago

containsKey api有吗

sofastack-bot[bot] commented 4 years ago

Hi @zhangjun050754, we detect non-English characters in the issue. This comment is an auto translation by @sofastack-robot to help other users to understand this issue.

We encourage you to describe your issue in English which is more friendly to other users.

Is there a containsKey api?

fengjiachun commented 4 years ago

没有这个 api, 不用 get 是因为不想 return value? 仅仅是不想 return value 的话可以使用 scan api

scan(key, BytesUtil.nextBytes(key), true, false)

zhangjun050754 commented 4 years ago

没有这个 api, 不用 get 是因为不想 return value? 仅仅是不想 return value 的话可以使用 scan api

scan(key, BytesUtil.nextBytes(key), true, false)

startKey, endKey 含义是什么?没太理解 意思是说先put的key和后put的key区间?

fengjiachun commented 4 years ago

没有这个 api, 不用 get 是因为不想 return value? 仅仅是不想 return value 的话可以使用 scan api scan(key, BytesUtil.nextBytes(key), true, false)

startKey, endKey 含义是什么?没太理解 意思是说先put的key和后put的key区间?

scan 是扫描 startKey 和 endKey 这个区间的所有键值对,左闭右开,最后一个参数为 false 表示不返回 value,详见文档:https://www.sofastack.tech/projects/sofa-jraft/jraft-rheakv-user-guide/

zhangjun050754 commented 4 years ago

没有这个 api, 不用 get 是因为不想 return value? 仅仅是不想 return value 的话可以使用 scan api scan(key, BytesUtil.nextBytes(key), true, false)

startKey, endKey 含义是什么?没太理解 意思是说先put的key和后put的key区间?

scan 是扫描 startKey 和 endKey 这个区间的所有键值对,左闭右开,最后一个参数为 false 表示不返回 value,详见文档:https://www.sofastack.tech/projects/sofa-jraft/jraft-rheakv-user-guide/

可以模糊查询key吗?

fengjiachun commented 4 years ago

可以参考 redis 的 scan

fengjiachun commented 4 years ago

没其他问题先关闭了

killme2008 commented 4 years ago

@fengjiachun 我觉的是否可以提供这么一个 api ? containsKey 对于 kv 来说也是很常见的,比如 rocksdb 也有类似的 exists 方法

fengjiachun commented 4 years ago

@fengjiachun 我觉的是否可以提供这么一个 api ? containsKey 对于 kv 来说也是很常见的,比如 rocksdb 也有类似的 exists 方法

也可以,先记一个 issue

zhangjun050754 commented 4 years ago

redis 的 scan

建议增加一下key的前缀查询方面的api

fengjiachun commented 4 years ago

redis 的 scan

建议增加一下key的前缀查询方面的api

scan 就是

zhangjun050754 commented 4 years ago

redis 的 scan

建议增加一下key的前缀查询方面的api

scan 就是 请教一下 如下两个key 如何得到 ‘gr10:’为前缀的所有key? gr10:111_r0 gr10:111_r8

fengjiachun commented 4 years ago

redis 的 scan

建议增加一下key的前缀查询方面的api

scan 就是 请教一下 如下两个key 如何得到 ‘gr10:’为前缀的所有key? gr10:111_r0 gr10:111_r8

`

 byte[] start = "gr10".getBytes();

 byte[] end = BytesUtil.nextBytes(start);

 scan(start, end)

`

zhangjun050754 commented 4 years ago

redis 的 scan

建议增加一下key的前缀查询方面的api

scan 就是 请教一下 如下两个key 如何得到 ‘gr10:’为前缀的所有key? gr10:111_r0 gr10:111_r8

`

 byte[] start = "gr10".getBytes();

 byte[] end = BytesUtil.nextBytes(start);

 scan(start, end)

`

感谢支持,还是匹配不到 不知道什么原因

fengjiachun commented 4 years ago

@zhangjun050754 不好意思,是我写错了 按照你的需求,应该这样构造 endKey

`

String key = "gr10"

String start = key + ':';

String end = key + (char) (':' + 1);

scan(start, end)

`

fengjiachun commented 4 years ago

@zhangjun050754 scan 入参要求 endKey, 按照字节顺序 compare ,所以本质上就是如何构造 endKey

zhangjun050754 commented 4 years ago

@zhangjun050754 不好意思,是我写错了 按照你的需求,应该这样构造 endKey

`

String key = "gr10"

String start = key + ':';

String end = key + (char) (':' + 1);

scan(start, end)

`

可以了 感谢支持,我在摸索摸索。。