1

如何将setAerospike 中的 a 转储为 JSON(换行符分隔的 JSON)?

我试过了

aql -h 10.0.0.1 --no-config-file --outputmode=json -c "select * fromnamespace.set_name" >> whatever.json

(echo "select * from namespace.set_name" && cat) | aql -h 10.0.0.1 --no-config-file --outputmode=json > whatever.txt

但在转储 ~25MB 后两者都卡住了(原因不明)。

编辑:格式化。

4

1 回答 1

2

长话短说,我走了很长的路(写了一个剧本):

import aerospike
import json

config = {
    'hosts': [ ('10.0.0.1', 3000) ]
}

try:
    client = aerospike.client(config).connect()
except:
    import sys
    print("rekt lol dump yourself", config['hosts'])
    sys.exit(1)

query = client.query('dmp', 'whatever')
query.select('id', 'not_id', 'not_id_at_all')

with open('whatever.json', 'w') as out:
    def processRecord(arg):
        key, metadata, record = arg
        out.write(json.dumps(record))
        out.write('\n')

    query.foreach(processRecord)
于 2018-06-14T05:14:14.853 回答