forked from rosedblabs/rosedb
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdb_set_test.go
162 lines (131 loc) · 3.04 KB
/
db_set_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
package rosedb
import (
"testing"
)
func TestRoseDB_SAdd(t *testing.T) {
var key = "my_set"
t.Run("normal situation", func(t *testing.T) {
db := InitDb()
defer db.Close()
db.SAdd(nil, nil)
db.SAdd([]byte(key), []byte("set_data_001"), []byte("set_data_002"), []byte("set_data_003"))
res, _ := db.SAdd([]byte(key), []byte("set_data_004"), []byte("set_data_005"), []byte("set_data_006"))
t.Log(res)
})
t.Run("reopen and add", func(t *testing.T) {
db := ReopenDb()
defer db.Close()
res, _ := db.SAdd([]byte(key), []byte("set_data_007"), []byte("set_data_008"), []byte("set_data_009"))
t.Log(res)
})
//
//t.Run("large data", func(t *testing.T) {
// db := ReopenDb()
// defer db.Close()
// rand.Seed(time.Now().Unix())
//
// valPrefix := "set_data_"
//
// var res int
// for i := 0; i < 100000; i++ {
// val := valPrefix + strconv.Itoa(rand.Intn(1000000))
//
// res, _ = db.SAdd([]byte(key), []byte(val))
// }
// t.Log(res)
//})
}
func TestRoseDB_SPop(t *testing.T) {
db := ReopenDb()
defer db.Close()
var key = []byte("my_set")
db.SPop(nil, 3)
values, _ := db.SPop(key, 2)
for _, v := range values {
t.Log(string(v))
}
}
func TestRoseDB_SCard(t *testing.T) {
db := ReopenDb()
defer db.Close()
var key = []byte("my_set")
db.SCard(nil)
card := db.SCard(key)
t.Log(card)
card1 := db.SCard([]byte("not exist"))
t.Log(card1)
}
func TestRoseDB_SIsMember(t *testing.T) {
db := ReopenDb()
defer db.Close()
var key = []byte("my_set")
t.Log(db.SIsMember(key, []byte("set_data_009")))
t.Log(db.SIsMember(key, []byte("set_data_001")))
t.Log(db.SIsMember(key, []byte("not exist one")))
}
func TestRoseDB_SMembers(t *testing.T) {
db := ReopenDb()
defer db.Close()
var key = []byte("my_set")
db.SMembers(nil)
members := db.SMembers(key)
for _, m := range members {
t.Log(string(m))
}
}
func TestRoseDB_SRem(t *testing.T) {
db := ReopenDb()
defer db.Close()
var key = []byte("my_set")
db.SRem(nil, nil)
t.Log(db.SRem(key, []byte("set_data_009")))
t.Log(db.SRem(key, []byte("set_data_001")))
t.Log(db.SRem(key, []byte("not exist one")))
}
func TestRoseDB_SRandMember(t *testing.T) {
db := ReopenDb()
defer db.Close()
var key = []byte("my_set")
randMem := func(count int) {
vals := db.SRandMember(key, count)
for _, v := range vals {
t.Log(string(v))
}
}
randMem(3)
randMem(20)
randMem(-3)
randMem(-20)
}
func TestRoseDB_SDiff(t *testing.T) {
db := ReopenDb()
defer db.Close()
var keys = [][]byte{
[]byte("my_set1"),
[]byte("my_set2"),
}
var emptyKeys [][]byte
db.SDiff(emptyKeys...)
db.SDiff(keys...)
}
func TestRoseDB_SMove(t *testing.T) {
db := ReopenDb()
defer db.Close()
var key1 = []byte("my_set1")
var key2 = []byte("my_set2")
db.SAdd(key1, [][]byte{[]byte("1")}...)
db.SAdd(key2, [][]byte{[]byte("2")}...)
db.SMove(nil, nil, nil)
db.SMove(key1, key2, []byte("1"))
}
func TestRoseDB_SUnion(t *testing.T) {
db := ReopenDb()
defer db.Close()
var keys = [][]byte{
[]byte("my_set1"),
[]byte("my_set2"),
}
var emptyKeys [][]byte
db.SUnion(emptyKeys...)
db.SUnion(keys...)
}