@@ -180,16 +180,16 @@ func (n *Notification) Send() error {
180
180
}
181
181
182
182
func (n * Notification ) Prefix () string {
183
- return "n:" + n .Id + ":000:"
183
+ return "n:id: " + n .Id + ":000:"
184
184
}
185
185
func (n * Notification ) PrefixBytes () []byte {
186
- return []byte ("n:" + n .Id + ":000:" )
186
+ return []byte ("n:id: " + n .Id + ":000:" )
187
187
}
188
188
189
189
func (n * Notification ) Save () (int , error ) {
190
190
nextVersion := uint64 (0 )
191
191
var err error
192
- prefix := []byte ("n:" + n .Id + ":" )
192
+ prefix := []byte ("n:id: " + n .Id + ":" )
193
193
for {
194
194
keys , next , err := db .GetKeysWithPrefix (prefix , prefix , 100 )
195
195
if err != nil {
@@ -200,23 +200,36 @@ func (n *Notification) Save() (int, error) {
200
200
break
201
201
}
202
202
}
203
- nextKey := []byte ("n:" + n .Id + ":" + fmt .Sprintf ("%03d" , nextVersion ))
203
+ nextKey := []byte ("n:id: " + n .Id + ":" + fmt .Sprintf ("%03d" , nextVersion ))
204
204
n .Version = & nextVersion
205
205
notificationBytes , err := proto .Marshal (n )
206
206
if err != nil {
207
207
return 0 , fmt .Errorf ("Error marshaling notification: %v" , err )
208
208
}
209
209
err = db .Set (nextKey , notificationBytes )
210
210
if err != nil {
211
- return 0 , fmt .Errorf ("Error putting notification: %v" , err )
211
+ return 0 , fmt .Errorf ("Error saving notification: %v" , err )
212
212
}
213
213
return int (nextVersion ), nil
214
214
}
215
215
216
+ func (n * Notification ) Update () (int , error ) {
217
+ key := []byte ("n:id:" + n .Id + ":" + fmt .Sprintf ("%03d" , n .GetVersion ()))
218
+ notificationBytes , err := proto .Marshal (n )
219
+ if err != nil {
220
+ return 0 , fmt .Errorf ("Error marshaling notification: %v" , err )
221
+ }
222
+ err = db .Set (key , notificationBytes )
223
+ if err != nil {
224
+ return 0 , fmt .Errorf ("Error saving notification: %v" , err )
225
+ }
226
+ return int (* n .Version ), nil
227
+ }
228
+
216
229
func (n * Notification ) Load (id string ) ([]* Notification , error ) {
217
230
var notifications []* Notification
218
- prefix := []byte ("n:" + id + ":" )
219
- next := []byte ("n:" + id + ":0" )
231
+ prefix := []byte ("n:id: " + id + ":" )
232
+ next := []byte ("n:id: " + id + ":0" )
220
233
for {
221
234
keys , next , err := db .GetKeysWithPrefix (prefix , next , 100 )
222
235
if err != nil {
0 commit comments