LevelDB 意外的排序结果

LevelDB unexpected sorting results

levelup API (https://github.com/Level/levelup#api) 将排序选项描述为:

You can supply an options object as the first parameter to createReadStream() with the following properties:

gt (greater than), gte (greater than or equal) define the lower bound of the range to be streamed. Only entries where the key is greater than (or equal to) this option will be included in the range.

lt (less than), lte (less than or equal) define the higher bound of the range to be streamed. Only entries where the key is less than (or equal to) this option will be included in the range.

我设置了一个快速测试来尝试调试我在基于 levelDB 的 kv 存储中看到的奇怪结果。

const level = require('level');
const levelDb = level('./db');

const put = (key, val) => new Promise(resolve => {
    levelDb.put(key, val, err => {
        if (err) resolve(false);
        resolve(true);
    });
});

const stream = options => new Promise(resolve => {
    let output = [];
    levelDb.createReadStream(options)
        .on('data', data => { output.push({ k: data.key, v: data.value }); })
        .on('end', () => { resolve(output); });
});

const runTest = async() => {
    await put('a', 123);
    await put('b:ab', 123);
    await put('b:X345345:234', 123);
    await put('c', 123);

    const results = await stream({ gte: 'b:0', lte:'b:Z' });
    console.log(results);
}

runTest();

我有一把钥匙 b:ab 和一把钥匙 b:X345345:234,它们似乎介于 b:0b:Z 之间,但我只收到 b:X345345:234结果。

这是为什么?

b:ab 不属于 b:0 和 b:Z,因为 aascii table.

中位于 Z 之后