-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
117 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package cache | ||
|
||
import ( | ||
"testing" | ||
"time" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
var ( | ||
key = "test-local-cache" | ||
values = []string{"a", "b", "c", "d"} | ||
) | ||
|
||
func TestPut(t *testing.T) { | ||
for _, v := range values { | ||
ok := Put(key, v) | ||
assert.Equal(t, true, ok) | ||
} | ||
} | ||
|
||
func TestGet(t *testing.T) { | ||
for _, v := range values { | ||
ok := Put(key, v) | ||
assert.Equal(t, true, ok) | ||
getV, ret := Get(key) | ||
assert.Equal(t, v, getV.(string)) | ||
assert.Equal(t, 0, ret) | ||
} | ||
} | ||
|
||
func TestForget(t *testing.T) { | ||
for _, v := range values { | ||
ok := Put(key, v) | ||
assert.Equal(t, true, ok) | ||
|
||
ok = Forget(key) | ||
assert.Equal(t, true, ok) | ||
|
||
getV, ret := Get(key) | ||
assert.Equal(t, nil, getV) | ||
assert.Equal(t, -2, ret) | ||
} | ||
} | ||
|
||
func TestExpire(t *testing.T) { | ||
for _, v := range values { | ||
ok := Put(key, v) | ||
assert.Equal(t, true, ok) | ||
|
||
ok = Expire(key, time.Minute) | ||
assert.Equal(t, true, ok) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package cache | ||
|
||
import "github.com/keepchen/message-queue/queue" | ||
|
||
var listInstance *queue.Instance | ||
|
||
// InitList 初始化列表 | ||
func InitList() { | ||
listInstance = queue.GetDBInstance("<localList>") | ||
listInstance.SetDebugMode(false) | ||
} | ||
|
||
// GetListInstance 获取列表实例 | ||
func GetListInstance() *queue.Instance { | ||
return listInstance | ||
} | ||
|
||
// NewList 新建列表 | ||
func NewList(listName string) *queue.Instance { | ||
instance := queue.GetDBInstance(listName) | ||
instance.SetDebugMode(false) | ||
|
||
return instance | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters