DynamoDb使用指南-go

  • 最后一页的判断请使用一下代码
PagingKey := make(dynamo.PagingKey)
if len(PagingKey) == 0 {
   //
}
  • count一定不要用limit,而是采用searchlimit.否则可能会死循环读取,导致读容量暴涨!!!
noticeTable.Get("uid", uid).
   Order(dynamo.Descending).
  Range("notice_time", dynamo.Greater, ts). SearchLimit(100). CountWithContext(ctx)

 

  • Consistent属性非必需就使用默认的false。否则读性能会很差
  • 大量写入/读取可以使用pipeline
userActDyPipeline := userActivityTable.Batch().Write()
userActDyPipeline.Put(userActList)
_, err := userActDyPipeline.RunWithContext(ctx)
if err != nil {
   return err
}
  • batch的get只能走一级索引,二级无效
//这里只能是主键的分区键和排序键
ChannelMuteTable
.Batch("uid", "channel_id")
.Get(keys...)
.AllWithContext(ctx, &ts)
  • 二级索引的分区字段尽量设置omitempty,保证不会建立空的二级索引
GroupTime  int64  `dynamo:"group_time,omitempty"`

官方文档

https://docs.aws.amazon.com/zh_cn/amazondynamodb/latest/developerguide/Introduction.html
posted @ 2022-07-20 11:41  程序实验室  阅读(144)  评论(0)    收藏  举报