Skip to content

Commit

Permalink
Add some documentation for Expire command
Browse files Browse the repository at this point in the history
  • Loading branch information
buraksezer committed Oct 30, 2019
1 parent 24edcdd commit 2f4e62a
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 1 deletion.
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ This project is a work in progress. The implementation is incomplete. The docume
* [Put](#put)
* [PutEx](#putex)
* [Get](#get)
* [Expire](#expire)
* [Delete](#delete)
* [LockWithTimeout](#lockwithtimeout)
* [Unlock](#unlock)
Expand Down Expand Up @@ -191,6 +192,16 @@ value, err := dm.Get("my-key")

It is safe to modify the contents of the returned value. It is safe to modify the contents of the argument after Get returns.

### Expire

Expire updates or sets the expiry for the given key. It's thread-safe.

```go
err := dm.Expire("my-key", time.Second)
```

The key has to be `string`. The second parameter is `time.Duration`.

### Delete

Delete deletes the value for the given key. Delete will not return error if key doesn't exist. It's thread-safe.
Expand Down
1 change: 1 addition & 0 deletions client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,7 @@ func (d *DMap) GetPut(key string, value interface{}) (interface{}, error) {
return d.processGetPutResponse(resp)
}

// Expire updates the expiry for the given key.
func (d *DMap) Expire(key string, timeout time.Duration) error {
m := &protocol.Message{
DMap: d.name,
Expand Down
1 change: 1 addition & 0 deletions client/pipeline.go
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,7 @@ func (p *Pipeline) Flush() ([]PipelineResponse, error) {
return responses, resErr
}

// Expire updates the expiry for the given key.
func (p *Pipeline) Expire(dmap, key string, timeout time.Duration) error {
p.m.Lock()
defer p.m.Unlock()
Expand Down
1 change: 1 addition & 0 deletions client/pipeline_response.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ func (pr *PipelineResponse) Unlock() error {
return checkStatusCode(&pr.response)
}

// Expire updates the expiry for the given key.
func (pr *PipelineResponse) Expire() error {
return checkStatusCode(&pr.response)
}
4 changes: 3 additions & 1 deletion dmap_expire.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,12 @@ package olric

import (
"fmt"
"time"

"github.com/buraksezer/olric/config"
"github.com/buraksezer/olric/internal/discovery"
"github.com/buraksezer/olric/internal/protocol"
"github.com/buraksezer/olric/internal/storage"
"time"
)

func (db *Olric) localExpire(hkey uint64, dm *dmap, w *writeop) error {
Expand Down Expand Up @@ -157,6 +158,7 @@ func (db *Olric) exExpireOperation(req *protocol.Message) *protocol.Message {
return db.prepareResponse(req, db.expire(w))
}

// Expire updates the expiry for the given key.
func (dm *DMap) Expire(key string, timeout time.Duration) error {
w := &writeop{
dmap: dm.name,
Expand Down
1 change: 1 addition & 0 deletions internal/storage/storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,7 @@ func (s *Storage) Delete(hkey uint64) error {
return nil
}

// UpdateTTL updates the expiry for the given key.
func (s *Storage) UpdateTTL(hkey uint64, data *VData) error {
if len(s.tables) == 0 {
panic("tables cannot be empty")
Expand Down

0 comments on commit 2f4e62a

Please sign in to comment.