Skip to content

Commit fd50da2

Browse files
authored
Merge pull request #1 from daangn/feat/context
feat: support passing context
2 parents a41fca8 + 98773b6 commit fd50da2

3 files changed

Lines changed: 204 additions & 83 deletions

File tree

README.md

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,17 +15,25 @@ After this command *gomemcache* is ready to use. Its source will be in:
1515

1616
## Example
1717

18-
import (
19-
"github.com/bradfitz/gomemcache/memcache"
20-
)
21-
22-
func main() {
23-
mc := memcache.New("10.0.0.1:11211", "10.0.0.2:11211", "10.0.0.3:11212")
24-
mc.Set(&memcache.Item{Key: "foo", Value: []byte("my value")})
25-
26-
it, err := mc.Get("foo")
27-
...
28-
}
18+
```go
19+
import (
20+
"github.com/bradfitz/gomemcache/memcache"
21+
)
22+
23+
func main() {
24+
mc := memcache.New("10.0.0.1:11211", "10.0.0.2:11211", "10.0.0.3:11212")
25+
mc.Set(&memcache.Item{Key: "foo", Value: []byte("my value")})
26+
27+
it, err := mc.Get("foo")
28+
29+
// With context
30+
ctx, cancel := context.WithTimeout(2 * time.Second)
31+
doLongTimeJob(ctx)
32+
...
33+
it, err = mc.GetWithContext(ctx, "bar")
34+
...
35+
}
36+
```
2937

3038
## Full docs, see:
3139

0 commit comments

Comments
 (0)