<tfoot id='WFuxt'></tfoot>

    <bdo id='WFuxt'></bdo><ul id='WFuxt'></ul>

  • <legend id='WFuxt'><style id='WFuxt'><dir id='WFuxt'><q id='WFuxt'></q></dir></style></legend>

      <small id='WFuxt'></small><noframes id='WFuxt'>

        <i id='WFuxt'><tr id='WFuxt'><dt id='WFuxt'><q id='WFuxt'><span id='WFuxt'><b id='WFuxt'><form id='WFuxt'><ins id='WFuxt'></ins><ul id='WFuxt'></ul><sub id='WFuxt'></sub></form><legend id='WFuxt'></legend><bdo id='WFuxt'><pre id='WFuxt'><center id='WFuxt'></center></pre></bdo></b><th id='WFuxt'></th></span></q></dt></tr></i><div id='WFuxt'><tfoot id='WFuxt'></tfoot><dl id='WFuxt'><fieldset id='WFuxt'></fieldset></dl></div>
      1. 如何将值附加到 AWS DynamoDB 上的列表属性?

        How to append a value to list attribute on AWS DynamoDB?(如何将值附加到 AWS DynamoDB 上的列表属性?)
          <tbody id='7HlGF'></tbody>
        <tfoot id='7HlGF'></tfoot>
        <i id='7HlGF'><tr id='7HlGF'><dt id='7HlGF'><q id='7HlGF'><span id='7HlGF'><b id='7HlGF'><form id='7HlGF'><ins id='7HlGF'></ins><ul id='7HlGF'></ul><sub id='7HlGF'></sub></form><legend id='7HlGF'></legend><bdo id='7HlGF'><pre id='7HlGF'><center id='7HlGF'></center></pre></bdo></b><th id='7HlGF'></th></span></q></dt></tr></i><div id='7HlGF'><tfoot id='7HlGF'></tfoot><dl id='7HlGF'><fieldset id='7HlGF'></fieldset></dl></div>

          <legend id='7HlGF'><style id='7HlGF'><dir id='7HlGF'><q id='7HlGF'></q></dir></style></legend>

              • <bdo id='7HlGF'></bdo><ul id='7HlGF'></ul>
                • <small id='7HlGF'></small><noframes id='7HlGF'>

                  本文介绍了如何将值附加到 AWS DynamoDB 上的列表属性?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我将 DynamoDB 用作 K-V db(因为没有太多数据,我认为这很好),并且V"的一部分是列表类型(大约 10 个元素).有一些会话可以为其附加一个新值,但我无法在 1 个请求中找到执行此操作的方法.我的做法是这样的:

                  I'm using DynamoDB as an K-V db (cause there's not much data, I think that's fine) , and part of 'V' is list type (about 10 elements). There's some session to append a new value to it, and I cannot find a way to do this in 1 request. What I did is like this:

                  item = self.list_table.get_item(**{'k': 'some_key'})
                  item['v'].append('some_value')
                  item.partial_save()
                  

                  我先请求服务器,修改值后保存.这不是原子的,看起来很丑.有没有办法在一个请求中做到这一点?

                  I request the server first and save it after modified the value. That's not atomic and looks ugly. Is there any way to do this in one request?

                  推荐答案

                  以下代码应该适用于boto3:

                  The following code should work with boto3:

                  table = get_dynamodb_resource().Table("table_name")
                  result = table.update_item(
                      Key={
                          'hash_key': hash_key,
                          'range_key': range_key
                      },
                      UpdateExpression="SET some_attr = list_append(some_attr, :i)",
                      ExpressionAttributeValues={
                          ':i': [some_value],
                      },
                      ReturnValues="UPDATED_NEW"
                  )
                  if result['ResponseMetadata']['HTTPStatusCode'] == 200 and 'Attributes' in result:
                      return result['Attributes']['some_attr']
                  

                  这里的get_dynamodb_resource方法就是:

                  The get_dynamodb_resource method here is just:

                  def get_dynamodb_resource():
                      return boto3.resource(
                              'dynamodb',
                              region_name=os.environ['AWS_DYNAMO_REGION'],
                              endpoint_url=os.environ['AWS_DYNAMO_ENDPOINT'],
                              aws_secret_access_key=os.environ['AWS_SECRET_ACCESS_KEY'],
                              aws_access_key_id=os.environ['AWS_ACCESS_KEY_ID'])
                  

                  这篇关于如何将值附加到 AWS DynamoDB 上的列表属性?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  env: python: No such file or directory(env: python: 没有这样的文件或目录)
                  How to evaluate environment variables into a string in Python?(如何在 Python 中将环境变量评估为字符串?)
                  Python - temporarily modify the current process#39;s environment(Python - 临时修改当前进程的环境)
                  Change current process environment#39;s LD_LIBRARY_PATH(更改当前进程环境的 LD_LIBRARY_PATH)
                  Reading and writing environment variables in Python?(在 Python 中读写环境变量?)
                  When to use sys.path.append and when modifying %PYTHONPATH% is enough(何时使用 sys.path.append 以及何时修改 %PYTHONPATH% 就足够了)
                • <i id='jOYKj'><tr id='jOYKj'><dt id='jOYKj'><q id='jOYKj'><span id='jOYKj'><b id='jOYKj'><form id='jOYKj'><ins id='jOYKj'></ins><ul id='jOYKj'></ul><sub id='jOYKj'></sub></form><legend id='jOYKj'></legend><bdo id='jOYKj'><pre id='jOYKj'><center id='jOYKj'></center></pre></bdo></b><th id='jOYKj'></th></span></q></dt></tr></i><div id='jOYKj'><tfoot id='jOYKj'></tfoot><dl id='jOYKj'><fieldset id='jOYKj'></fieldset></dl></div>

                    <tbody id='jOYKj'></tbody>

                        <small id='jOYKj'></small><noframes id='jOYKj'>

                        <tfoot id='jOYKj'></tfoot>
                          <bdo id='jOYKj'></bdo><ul id='jOYKj'></ul>
                          <legend id='jOYKj'><style id='jOYKj'><dir id='jOYKj'><q id='jOYKj'></q></dir></style></legend>