

本文属于机器翻译版本。若本译文内容与英语原文存在差异，则一律以英文原文为准。

# 使用 openCypher 和 Bolt 的 Neptune 最佳实践
<a name="best-practices-opencypher"></a>

将 openCypher 查询语言和 Bolt 协议与 Neptune 结合使用时，请遵循以下最佳实践。有关在 Neptune 中使用 openCypher 的信息，请参阅[使用 openCypher 访问 Neptune 图形](access-graph-opencypher.md)。

**Topics**
+ [在失效转移后创建新连接](#best-practices-opencypher-renew-connection)
+ [长寿命应用程序的连接处理](#best-practices-opencypher-long-connections)
+ [的连接处理 AWS Lambda](#best-practices-opencypher-lambda-connections)
+ [在查询中首选定向边缘而非双向边缘](best-practices-opencypher-directed-edges.md)
+ [Neptune 不支持在一个事务中进行多个并发查询](best-practices-opencypher-multiple-queries.md)
+ [完成后关闭驱动程序对象](best-practices-opencypher-close-driver.md)
+ [使用显式事务模式进行读写](best-practices-opencypher-use-explicit-txs.md)
+ [异常的重试逻辑](best-practices-opencypher-retry-logic.md)
+ [使用单个 SET 子句一次设置多个属性](best-practices-content-0.md)
+ [使用参数化查询](best-practices-content-2.md)
+ [在 UNWIND 子句中使用扁平化映射而非嵌套映射](best-practices-content-3.md)
+ [在可变长度路径（VLP）表达式中将限制性更强的节点放在左侧](best-practices-content-4.md)
+ [使用精细的关系名称避免冗余节点标签检查](best-practices-content-5.md)
+ [尽可能指定边缘标签](best-practices-content-6.md)
+ [尽可能避免使用 WITH 子句](best-practices-content-7.md)
+ [尽早在查询中放置限制性筛选条件](best-practices-content-8.md)
+ [显式检查属性是否存在](best-practices-content-9.md)
+ [不要使用命名路径（除非必需）](best-practices-content-10.md)
+ [避免使用 COLLECT(DISTINCT())](best-practices-content-11.md)
+ [检索所有属性值时，最好使用 properties 函数而不是单个属性查找](best-practices-content-12.md)
+ [在查询之外执行静态计算](best-practices-content-13.md)
+ [对批量输入使用 UNWIND（而非单个语句）](best-practices-content-14.md)
+ [最好 IDs 对节点/关系使用自定义](best-practices-content-15.md)
+ [避免在查询中进行 \$1id 计算](best-practices-content-16.md)
+ [更新/合并多个节点](best-practices-merge-multiple-nodes.md)

## 在失效转移后创建新连接
<a name="best-practices-opencypher-renew-connection"></a>

在失效转移的情况下，Bolt 驱动程序可以继续连接到旧的写入器实例，而不是新的活动写入器实例，因为 DNS 名称已解析为特定的 IP 地址。

为防止出现这种情况，请在进行任何失效转移后关闭 `Driver` 对象，然后重新连接该对象。

## 长寿命应用程序的连接处理
<a name="best-practices-opencypher-long-connections"></a>

在构建长寿命的应用程序（例如，在容器内或 Amazon EC2 实例上运行的应用程序）时，只需实例化 `Driver` 对象一次，然后在应用程序的生命周期内重用该对象。`Driver` 对象是线程安全的，并且将其初始化的开销非常大。

## 的连接处理 AWS Lambda
<a name="best-practices-opencypher-lambda-connections"></a>

不建议在 AWS Lambda 功能中使用螺栓驱动器，因为它们具有连接开销和管理要求。请改用 [HTTPS 端点](access-graph-opencypher-queries.md)。