2017-06-20 14:38
浏览 390


I am using golang and go-redis package I would like to store a key-value pair in redis (e.g one time token). When this token is read, I generate a permanent token. But the one time token should be deleted once I have read the value. This is to avoid fast-replay attack. What is the best way to implement this. I have been thinking of mutex.

图片转代码服务由CSDN问答提供 功能建议

我正在使用golang和go-redis包 我想在Redis中存储键值对(例如 一次令牌)。 读取此令牌后,我将生成一个永久令牌。 但是,一旦我读取了值,就应该删除一次令牌。 这是为了避免快速重播攻击。 实现此目的的最佳方法是什么。 我一直在考虑互斥锁。

  • 写回答
  • 好问题 提建议
  • 追加酬金
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • doutui9606 2017-06-20 17:04

    This is a perfect use case for the MULTI-EXEC functionality:

    GET key
    DELETE key

    Or in go:

    pipe := client.TxPipeline()
    get := pipe.Get("key")
    _, err := pipe.Exec()
    fmt.Println(incr.Val(), err)

    This will ensure that both commands execute in a transaction, so the key will either be retrieved and deleted or not retrieved at all.

    解决 无用
    打赏 举报

相关推荐 更多相似问题