Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(247)

Side by Side Diff: filter/count/mc.go

Issue 1270063003: Make the rest of the services have a similar raw/user interface structure. (Closed) Base URL: https://github.com/luci/gae.git@add_datastore
Patch Set: address comments Created 5 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « filter/count/count_test.go ('k') | filter/count/tq.go » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 package count 5 package count
6 6
7 import ( 7 import (
8 "golang.org/x/net/context" 8 "golang.org/x/net/context"
9 9
10 mc "github.com/luci/gae/service/memcache" 10 mc "github.com/luci/gae/service/memcache"
11 ) 11 )
12 12
13 // MCCounter is the counter object for the Memcache service. 13 // MCCounter is the counter object for the Memcache service.
14 type MCCounter struct { 14 type MCCounter struct {
15 NewItem Entry 15 NewItem Entry
16 Add Entry
17 Set Entry
18 Get Entry
19 Delete Entry
20 CompareAndSwap Entry
21 AddMulti Entry 16 AddMulti Entry
22 SetMulti Entry 17 SetMulti Entry
23 GetMulti Entry 18 GetMulti Entry
24 DeleteMulti Entry 19 DeleteMulti Entry
25 CompareAndSwapMulti Entry 20 CompareAndSwapMulti Entry
26 Increment Entry 21 Increment Entry
27 IncrementExisting Entry
28 Flush Entry 22 Flush Entry
29 Stats Entry 23 Stats Entry
30 } 24 }
31 25
32 type mcCounter struct { 26 type mcCounter struct {
33 c *MCCounter 27 c *MCCounter
34 28
35 » mc mc.Interface 29 » mc mc.RawInterface
36 } 30 }
37 31
38 var _ mc.Interface = (*mcCounter)(nil) 32 var _ mc.RawInterface = (*mcCounter)(nil)
39 33
40 func (m *mcCounter) NewItem(key string) mc.Item { 34 func (m *mcCounter) NewItem(key string) mc.Item {
41 m.c.NewItem.up() 35 m.c.NewItem.up()
42 return m.mc.NewItem(key) 36 return m.mc.NewItem(key)
43 } 37 }
44 38
45 func (m *mcCounter) Get(key string) (mc.Item, error) { 39 func (m *mcCounter) GetMulti(keys []string, cb mc.RawItemCB) error {
46 » ret, err := m.mc.Get(key) 40 » return m.c.GetMulti.up(m.mc.GetMulti(keys, cb))
47 » return ret, m.c.Get.up(err)
48 } 41 }
49 42
50 func (m *mcCounter) GetMulti(keys []string) (map[string]mc.Item, error) { 43 func (m *mcCounter) AddMulti(items []mc.Item, cb mc.RawCB) error {
51 » ret, err := m.mc.GetMulti(keys) 44 » return m.c.AddMulti.up(m.mc.AddMulti(items, cb))
52 » return ret, m.c.GetMulti.up(err)
53 } 45 }
54 46
55 func (m *mcCounter) Add(item mc.Item) error { return m.c.Add.up(m.mc.Add(item)) } 47 func (m *mcCounter) SetMulti(items []mc.Item, cb mc.RawCB) error {
56 func (m *mcCounter) Set(item mc.Item) error { return m.c.Set.up(m.mc.Set(item)) } 48 » return m.c.SetMulti.up(m.mc.SetMulti(items, cb))
57 func (m *mcCounter) Delete(key string) error { return m.c.Delete.up(m.mc.Delete( key)) }
58 func (m *mcCounter) CompareAndSwap(item mc.Item) error {
59 » return m.c.CompareAndSwap.up(m.mc.CompareAndSwap(item))
60 } 49 }
61 func (m *mcCounter) AddMulti(items []mc.Item) error { return m.c.AddMulti.up(m.m c.AddMulti(items)) } 50
62 func (m *mcCounter) SetMulti(items []mc.Item) error { return m.c.SetMulti.up(m.m c.SetMulti(items)) } 51 func (m *mcCounter) DeleteMulti(keys []string, cb mc.RawCB) error {
63 func (m *mcCounter) DeleteMulti(keys []string) error { 52 » return m.c.DeleteMulti.up(m.mc.DeleteMulti(keys, cb))
64 » return m.c.DeleteMulti.up(m.mc.DeleteMulti(keys))
65 } 53 }
54
55 func (m *mcCounter) CompareAndSwapMulti(items []mc.Item, cb mc.RawCB) error {
56 return m.c.CompareAndSwapMulti.up(m.mc.CompareAndSwapMulti(items, cb))
57 }
58
66 func (m *mcCounter) Flush() error { return m.c.Flush.up(m.mc.Flush()) } 59 func (m *mcCounter) Flush() error { return m.c.Flush.up(m.mc.Flush()) }
67 60
68 func (m *mcCounter) CompareAndSwapMulti(items []mc.Item) error { 61 func (m *mcCounter) Increment(key string, delta int64, initialValue *uint64) (ne wValue uint64, err error) {
69 » return m.c.CompareAndSwapMulti.up(m.mc.CompareAndSwapMulti(items))
70 }
71
72 func (m *mcCounter) Increment(key string, delta int64, initialValue uint64) (new Value uint64, err error) {
73 ret, err := m.mc.Increment(key, delta, initialValue) 62 ret, err := m.mc.Increment(key, delta, initialValue)
74 return ret, m.c.Increment.up(err) 63 return ret, m.c.Increment.up(err)
75 } 64 }
76 65
77 func (m *mcCounter) IncrementExisting(key string, delta int64) (newValue uint64, err error) {
78 ret, err := m.mc.IncrementExisting(key, delta)
79 return ret, m.c.IncrementExisting.up(err)
80 }
81
82 func (m *mcCounter) Stats() (*mc.Statistics, error) { 66 func (m *mcCounter) Stats() (*mc.Statistics, error) {
83 ret, err := m.mc.Stats() 67 ret, err := m.mc.Stats()
84 return ret, m.c.Stats.up(err) 68 return ret, m.c.Stats.up(err)
85 } 69 }
86 70
87 // FilterMC installs a counter Memcache filter in the context. 71 // FilterMC installs a counter Memcache filter in the context.
88 func FilterMC(c context.Context) (context.Context, *MCCounter) { 72 func FilterMC(c context.Context) (context.Context, *MCCounter) {
89 state := &MCCounter{} 73 state := &MCCounter{}
90 » return mc.AddFilters(c, func(ic context.Context, mc mc.Interface) mc.Int erface { 74 » return mc.AddRawFilters(c, func(ic context.Context, mc mc.RawInterface) mc.RawInterface {
91 return &mcCounter{state, mc} 75 return &mcCounter{state, mc}
92 }), state 76 }), state
93 } 77 }
OLDNEW
« no previous file with comments | « filter/count/count_test.go ('k') | filter/count/tq.go » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698