From 999a268ca87fd2b68a5c40e9e6bcc4d5736d2ed7 Mon Sep 17 00:00:00 2001 From: cpb8010 Date: Sat, 31 Aug 2013 01:17:12 -0400 Subject: [PATCH] The rest of the files needed to pass Redis tests --- cache/cache.go | 1 + cache/redis/redis.go | 13 +++++++++++-- config/example.json | 6 +++++- 3 files changed, 17 insertions(+), 3 deletions(-) diff --git a/cache/cache.go b/cache/cache.go index 85470c3..5f3ef69 100644 --- a/cache/cache.go +++ b/cache/cache.go @@ -17,6 +17,7 @@ import ( var ( drivers = make(map[string]Driver) ErrTxDone = errors.New("cache: Transaction has already been committed or rolled back") + ErrTxConflict = errors.New("cache: Commit interrupted, update transaction and repeat") ) type Driver interface { diff --git a/cache/redis/redis.go b/cache/redis/redis.go index 84b006d..4b7ed5a 100644 --- a/cache/redis/redis.go +++ b/cache/redis/redis.go @@ -106,6 +106,7 @@ func (tx *Tx) initiateWrite() error { return cache.ErrTxDone } if tx.multi != true { + tx.multi = true return tx.Send("MULTI") } return nil @@ -126,7 +127,11 @@ func (tx *Tx) Commit() error { return cache.ErrTxDone } if tx.multi == true { - _, err := tx.Do("EXEC") + execResponse, err := tx.Do("EXEC") + if execResponse == nil { + tx.multi = false + return cache.ErrTxConflict + } if err != nil { return err } @@ -139,7 +144,11 @@ func (tx *Tx) Rollback() error { if tx.done { return cache.ErrTxDone } - // Redis doesn't need to do anything. Exec is atomic. + // Undoes watches and multi + if _, err := tx.Do("DISCARD") ; err != nil { + return err + } + tx.multi = false tx.close() return nil } diff --git a/config/example.json b/config/example.json index cd1ae21..1131614 100644 --- a/config/example.json +++ b/config/example.json @@ -12,7 +12,11 @@ "prefix": "test:", "max_idle_conn": 3, - "idle_timeout": "240s" + "idle_timeout": "240s", + + "network": "tcp", + "schema": "schema", + "encoding": "encoding" }, "storage": {