gpt4 book ai didi

redis数据结构存储股票日 yield

转载 作者:IT王子 更新时间:2023-10-29 06:10:56 26 4
gpt4 key购买 nike

我有来自市场的股票日 yield 数据,想把它们放到redis,当前数据格式为 [stock_id, date, profit],我最多的操作是从间隔天开始搜索股票列表,例如stock_id_list: (203, 512, 532), date: from '20050101' to '20151231'

如果从mysql查询数据,会比较慢。

我想让你帮我设计一个redis数据结构来存储这些数据,并且可以快速查询

最佳答案

您可以使用排序集。使用日期作为值并将其他人作为成员放入 json 中。查询时,使用 zrangebyscore。在 redis ZADD 文档中:

The score values should be the string representation of a double precision floating point number. +inf and -inf values are valid values as well.

因此您应该将日期转换为数字,使用时间戳或天数作为早期时间点或将日期更改为数字2017-08-11 至 20170811

注意一点:score可以重复,但member不能在sorted set中,

If a specified member is already a member of the sorted set, the score is updated and the element reinserted at the right position to ensure the correct ordering.

所以你应该添加一个字段使你的股票数据唯一,比如你将它插入到redis中的uuid或时间戳。

关于redis数据结构存储股票日 yield ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45636122/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com