Couchbase: python SDK “uppend”

霸气de小男生 提交于 2019-12-24 00:44:27

问题


I want to do an "uppend_multi": an append_multi (http://pythonhosted.org/couchbase/api/couchbase.html#couchbase.bucket.Bucket.append_multi) where some of the keys may not exist. If they do not already exist then the append operation should be an insert. How can I do this? Nothing in the API docs suggests this is supported, but I imagine it is a very common operation.

Right now I am doing this, but it seems so natural of a thing to need to do that I highly doubt this is the best way to do it:

def _uppend_multi(bucket, append_dict):
    reinsert_dict = {}
    try:
        bucket.append_multi(append_dict, format = couchbase.FMT_UTF8)

    except CouchbaseError as exc:
        for k, res in exc.all_results.items():
            if res.success:
                pass
            else:
                reinsert_dict[k] = append_dict[k]

    if len(reinsert_dict.keys()) > 0:
        bucket.insert_multi(reinsert_dict, format = couchbase.FMT_UTF8)

回答1:


As far as I know there is no such "uppend" operation in the Couchbase Python SDK, nor in the lower-level C API (libcouchbase).

What you're currently doing is probably a pretty reasonable solution.



来源:https://stackoverflow.com/questions/32866825/couchbase-python-sdk-uppend

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!