Skip to content

Commit 14c1399

Browse files
committed
Release: v1.0.31-alpha
1 parent 0e94bc1 commit 14c1399

File tree

4 files changed

+36
-5
lines changed

4 files changed

+36
-5
lines changed

CHANGELOG.md

+7
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,13 @@ Changelog
22
=========
33
All notable changes to this project will be documented in this file.
44

5+
v1.0.31-alpha
6+
------------
7+
### Changed
8+
9+
- Fixed in-memory storage implementation
10+
- Fixed redis storage implementation
11+
512
v1.0.30-alpha
613
------------
714
### Changed

in-memory.go

+7-2
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,11 @@ func (s *InMemoryStorage) Get(openTime time.Time) (*Candle, error) {
3939
return candle, nil
4040
}
4141

42+
// GetByIndex retrieves candle from the storage by index.
43+
func (s *InMemoryStorage) GetByIndex(index int) (*Candle, error) {
44+
return (*s.Q)[index], nil
45+
}
46+
4247
// Put stores the given value for the given key.
4348
func (s *InMemoryStorage) Put(c ...*Candle) error {
4449
s.mutex.Lock()
@@ -50,8 +55,8 @@ func (s *InMemoryStorage) Put(c ...*Candle) error {
5055
}
5156

5257
// Update updates the value for the given key.
53-
func (s *InMemoryStorage) Update(c *Candle) error {
54-
return s.Put(c)
58+
func (s *InMemoryStorage) Update(c ...*Candle) error {
59+
return s.Put(c...)
5560
}
5661

5762
// Delete deletes the value for the given key.

redis-storage.go

+21-2
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,25 @@ func (s *RedisStorage) Get(openTime time.Time) (*Candle, error) {
103103
return candle, nil
104104
}
105105

106+
// GetByIndex retrieves candle from the storage by index.
107+
func (s *RedisStorage) GetByIndex(index int) (*Candle, error) {
108+
s.mutex.RLock()
109+
defer s.mutex.RUnlock()
110+
111+
tmp := fmt.Sprint(index)
112+
index64, _ := strconv.ParseInt(tmp, 10, 64)
113+
// Retrieve the value.
114+
timestamp, err := s.client.LIndex(s.ctx, fmt.Sprintf(REDIS_TIMESTAMPS_KEY, REDIS_KEY_PREFIX), index64).Result()
115+
if err != nil {
116+
return nil, fmt.Errorf("failed to get the timestamp: %s", err)
117+
}
118+
119+
timestamp64, _ := strconv.ParseInt(timestamp, 10, 64)
120+
openTime := time.Unix(timestamp64, 0)
121+
122+
return s.Get(openTime)
123+
}
124+
106125
// Put stores the value for the given key.
107126
func (s *RedisStorage) Put(c ...*Candle) error {
108127
s.mutex.Lock()
@@ -134,8 +153,8 @@ func (s *RedisStorage) Put(c ...*Candle) error {
134153
}
135154

136155
// Update updates the value for the given key.
137-
func (s *RedisStorage) Update(candle *Candle) error {
138-
return s.Put(candle)
156+
func (s *RedisStorage) Update(candle ...*Candle) error {
157+
return s.Put(candle...)
139158
}
140159

141160
// Delete removes the value for the given key.

storage.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ type Storage interface {
2222
Update(candle ...*Candle) error
2323

2424
// Delete removes the candle from the storage.
25-
Delete(key string) error
25+
Delete(candle *Candle) error
2626

2727
// Close closes the storage.
2828
Close() error

0 commit comments

Comments
 (0)