Skip to content

Commit

Permalink
Release: v1.0.31-alpha
Browse files Browse the repository at this point in the history
  • Loading branch information
amir-the-h committed Dec 28, 2021
1 parent 0e94bc1 commit 14c1399
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 5 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,13 @@ Changelog
=========
All notable changes to this project will be documented in this file.

v1.0.31-alpha
------------
### Changed

- Fixed in-memory storage implementation
- Fixed redis storage implementation

v1.0.30-alpha
------------
### Changed
Expand Down
9 changes: 7 additions & 2 deletions in-memory.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,11 @@ func (s *InMemoryStorage) Get(openTime time.Time) (*Candle, error) {
return candle, nil
}

// GetByIndex retrieves candle from the storage by index.
func (s *InMemoryStorage) GetByIndex(index int) (*Candle, error) {
return (*s.Q)[index], nil
}

// Put stores the given value for the given key.
func (s *InMemoryStorage) Put(c ...*Candle) error {
s.mutex.Lock()
Expand All @@ -50,8 +55,8 @@ func (s *InMemoryStorage) Put(c ...*Candle) error {
}

// Update updates the value for the given key.
func (s *InMemoryStorage) Update(c *Candle) error {
return s.Put(c)
func (s *InMemoryStorage) Update(c ...*Candle) error {
return s.Put(c...)
}

// Delete deletes the value for the given key.
Expand Down
23 changes: 21 additions & 2 deletions redis-storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,25 @@ func (s *RedisStorage) Get(openTime time.Time) (*Candle, error) {
return candle, nil
}

// GetByIndex retrieves candle from the storage by index.
func (s *RedisStorage) GetByIndex(index int) (*Candle, error) {
s.mutex.RLock()
defer s.mutex.RUnlock()

tmp := fmt.Sprint(index)
index64, _ := strconv.ParseInt(tmp, 10, 64)
// Retrieve the value.
timestamp, err := s.client.LIndex(s.ctx, fmt.Sprintf(REDIS_TIMESTAMPS_KEY, REDIS_KEY_PREFIX), index64).Result()
if err != nil {
return nil, fmt.Errorf("failed to get the timestamp: %s", err)
}

timestamp64, _ := strconv.ParseInt(timestamp, 10, 64)
openTime := time.Unix(timestamp64, 0)

return s.Get(openTime)
}

// Put stores the value for the given key.
func (s *RedisStorage) Put(c ...*Candle) error {
s.mutex.Lock()
Expand Down Expand Up @@ -134,8 +153,8 @@ func (s *RedisStorage) Put(c ...*Candle) error {
}

// Update updates the value for the given key.
func (s *RedisStorage) Update(candle *Candle) error {
return s.Put(candle)
func (s *RedisStorage) Update(candle ...*Candle) error {
return s.Put(candle...)
}

// Delete removes the value for the given key.
Expand Down
2 changes: 1 addition & 1 deletion storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ type Storage interface {
Update(candle ...*Candle) error

// Delete removes the candle from the storage.
Delete(key string) error
Delete(candle *Candle) error

// Close closes the storage.
Close() error
Expand Down

0 comments on commit 14c1399

Please sign in to comment.