├── .github └── workflows │ ├── build.yml │ ├── commitlint.yml │ └── golangci-lint.yml ├── .gitignore ├── LICENSE ├── README.md ├── client_test.go ├── cluster_test.go ├── commands_test.go ├── example ├── example.go └── ordinary │ ├── main.go │ └── main_test.go ├── expect.go ├── go.mod ├── go.sum ├── mock.go └── mock_test.go /.github/workflows/build.yml: -------------------------------------------------------------------------------- 1 | name: Go 2 | 3 | on: 4 | push: 5 | branches: [master, v8, v9] 6 | pull_request: 7 | branches: [master, v8, v9] 8 | 9 | permissions: 10 | contents: read 11 | 12 | jobs: 13 | build: 14 | name: build 15 | runs-on: ubuntu-latest 16 | strategy: 17 | fail-fast: false 18 | matrix: 19 | go-version: [1.18.x, 1.19.x] 20 | 21 | steps: 22 | - name: Set up ${{ matrix.go-version }} 23 | uses: actions/setup-go@v3 24 | with: 25 | go-version: ${{ matrix.go-version }} 26 | 27 | - name: Checkout code 28 | uses: actions/checkout@v3 29 | 30 | - name: Test 31 | run: | 32 | go vet ./... 33 | go test ./... 34 | go test ./... -short -race 35 | go test ./... -run=NONE -bench=. -benchmem 36 | -------------------------------------------------------------------------------- /.github/workflows/commitlint.yml: -------------------------------------------------------------------------------- 1 | name: Lint Commit Messages 2 | on: [pull_request] 3 | 4 | jobs: 5 | commitlint: 6 | runs-on: ubuntu-latest 7 | steps: 8 | - uses: actions/checkout@v3 9 | with: 10 | fetch-depth: 0 11 | - uses: wagoid/commitlint-github-action@v5 12 | -------------------------------------------------------------------------------- /.github/workflows/golangci-lint.yml: -------------------------------------------------------------------------------- 1 | name: golangci-lint 2 | 3 | on: 4 | push: 5 | tags: 6 | - v* 7 | branches: 8 | - master 9 | - main 10 | - v9 11 | - v8 12 | pull_request: 13 | 14 | permissions: 15 | contents: read 16 | 17 | jobs: 18 | golangci: 19 | permissions: 20 | contents: read # for actions/checkout to fetch code 21 | pull-requests: read # for golangci/golangci-lint-action to fetch pull requests 22 | name: lint 23 | runs-on: ubuntu-latest 24 | steps: 25 | - uses: actions/checkout@v3 26 | - name: golangci-lint 27 | uses: golangci/golangci-lint-action@v3 28 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .idea/ -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2013 The github.com/go-redis/redismock Authors. 2 | All rights reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without 5 | modification, are permitted provided that the following conditions are 6 | met: 7 | 8 | * Redistributions of source code must retain the above copyright 9 | notice, this list of conditions and the following disclaimer. 10 | * Redistributions in binary form must reproduce the above 11 | copyright notice, this list of conditions and the following disclaimer 12 | in the documentation and/or other materials provided with the 13 | distribution. 14 | 15 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 16 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 17 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 18 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 19 | OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 20 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 21 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 22 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 23 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 25 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Redis client Mock 2 | 3 | Provide mock test for redis query, Compatible with github.com/redis/go-redis/v9 4 | 5 | ## Install 6 | 7 | Confirm that you are using redis.Client the version is github.com/redis/go-redis/v9 8 | 9 | ```go 10 | go get github.com/go-redis/redismock/v9 11 | ``` 12 | 13 | ## Quick Start 14 | 15 | RedisClient 16 | ```go 17 | var ctx = context.TODO() 18 | 19 | func NewsInfoForCache(redisDB *redis.Client, newsID int) (info string, err error) { 20 | cacheKey := fmt.Sprintf("news_redis_cache_%d", newsID) 21 | info, err = redisDB.Get(ctx, cacheKey).Result() 22 | if err == redis.Nil { 23 | // info, err = call api() 24 | info = "test" 25 | err = redisDB.Set(ctx, cacheKey, info, 30 * time.Minute).Err() 26 | } 27 | return 28 | } 29 | 30 | func TestNewsInfoForCache(t *testing.T) { 31 | db, mock := redismock.NewClientMock() 32 | 33 | newsID := 123456789 34 | key := fmt.Sprintf("news_redis_cache_%d", newsID) 35 | 36 | // mock ignoring `call api()` 37 | 38 | mock.ExpectGet(key).RedisNil() 39 | mock.Regexp().ExpectSet(key, `[a-z]+`, 30 * time.Minute).SetErr(errors.New("FAIL")) 40 | 41 | _, err := NewsInfoForCache(db, newsID) 42 | if err == nil || err.Error() != "FAIL" { 43 | t.Error("wrong error") 44 | } 45 | 46 | if err := mock.ExpectationsWereMet(); err != nil { 47 | t.Error(err) 48 | } 49 | } 50 | ``` 51 | 52 | RedisCluster 53 | ```go 54 | clusterClient, clusterMock := redismock.NewClusterMock() 55 | ``` 56 | 57 | ## Unsupported Command 58 | 59 | RedisClient: 60 | 61 | - `Subscribe` / `PSubscribe` 62 | 63 | 64 | RedisCluster 65 | 66 | - `Subscribe` / `PSubscribe` 67 | - `Pipeline` / `TxPipeline` 68 | - `Watch` 69 | -------------------------------------------------------------------------------- /client_test.go: -------------------------------------------------------------------------------- 1 | package redismock 2 | 3 | import ( 4 | "errors" 5 | "fmt" 6 | "time" 7 | 8 | . "github.com/onsi/ginkgo" 9 | . "github.com/onsi/gomega" 10 | "github.com/redis/go-redis/v9" 11 | ) 12 | 13 | var _ = Describe("Client", func() { 14 | var ( 15 | client *redis.Client 16 | clientMock ClientMock 17 | ) 18 | 19 | BeforeEach(func() { 20 | client, clientMock = NewClientMock() 21 | }) 22 | 23 | AfterEach(func() { 24 | Expect(client.Close()).NotTo(HaveOccurred()) 25 | Expect(clientMock.ExpectationsWereMet()).NotTo(HaveOccurred()) 26 | }) 27 | 28 | Describe("tx pipeline", func() { 29 | var pipe redis.Pipeliner 30 | 31 | BeforeEach(func() { 32 | clientMock.ExpectTxPipeline() 33 | clientMock.ExpectGet("key1").SetVal("pipeline get") 34 | clientMock.ExpectHGet("hash_key", "hash_field").SetVal("pipeline hash get") 35 | clientMock.ExpectSet("set_key", "set value", 1*time.Minute).SetVal("OK") 36 | clientMock.ExpectTxPipelineExec() 37 | 38 | pipe = client.TxPipeline() 39 | }) 40 | 41 | AfterEach(func() { 42 | hasUnexpectedCall, unexpectedCalls := clientMock.UnexpectedCallsWereMade() 43 | Expect(hasUnexpectedCall).To(BeFalse()) 44 | Expect(unexpectedCalls).To(BeNil()) 45 | }) 46 | 47 | It("tx pipeline order", func() { 48 | get := pipe.Get(ctx, "key1") 49 | hashGet := pipe.HGet(ctx, "hash_key", "hash_field") 50 | set := pipe.Set(ctx, "set_key", "set value", 1*time.Minute) 51 | 52 | _, err := pipe.Exec(ctx) 53 | Expect(err).NotTo(HaveOccurred()) 54 | 55 | Expect(get.Err()).NotTo(HaveOccurred()) 56 | Expect(get.Val()).To(Equal("pipeline get")) 57 | 58 | Expect(hashGet.Err()).NotTo(HaveOccurred()) 59 | Expect(hashGet.Val()).To(Equal("pipeline hash get")) 60 | 61 | Expect(set.Err()).NotTo(HaveOccurred()) 62 | Expect(set.Val()).To(Equal("OK")) 63 | }) 64 | 65 | It("tx pipeline not order", func() { 66 | clientMock.MatchExpectationsInOrder(false) 67 | 68 | hashGet := pipe.HGet(ctx, "hash_key", "hash_field") 69 | set := pipe.Set(ctx, "set_key", "set value", 1*time.Minute) 70 | get := pipe.Get(ctx, "key1") 71 | 72 | _, err := pipe.Exec(ctx) 73 | Expect(err).NotTo(HaveOccurred()) 74 | 75 | Expect(get.Err()).NotTo(HaveOccurred()) 76 | Expect(get.Val()).To(Equal("pipeline get")) 77 | 78 | Expect(hashGet.Err()).NotTo(HaveOccurred()) 79 | Expect(hashGet.Val()).To(Equal("pipeline hash get")) 80 | 81 | Expect(set.Err()).NotTo(HaveOccurred()) 82 | Expect(set.Val()).To(Equal("OK")) 83 | }) 84 | }) 85 | 86 | Describe("pipeline", func() { 87 | var pipe redis.Pipeliner 88 | 89 | BeforeEach(func() { 90 | clientMock.ExpectGet("key1").SetVal("pipeline get") 91 | clientMock.ExpectHGet("hash_key", "hash_field").SetVal("pipeline hash get") 92 | clientMock.ExpectSet("set_key", "set value", 1*time.Minute).SetVal("OK") 93 | 94 | pipe = client.Pipeline() 95 | }) 96 | 97 | AfterEach(func() { 98 | hasUnexpectedCall, unexpectedCalls := clientMock.UnexpectedCallsWereMade() 99 | Expect(hasUnexpectedCall).To(BeFalse()) 100 | Expect(unexpectedCalls).To(BeNil()) 101 | }) 102 | 103 | It("pipeline order", func() { 104 | clientMock.MatchExpectationsInOrder(true) 105 | 106 | get := pipe.Get(ctx, "key1") 107 | hashGet := pipe.HGet(ctx, "hash_key", "hash_field") 108 | set := pipe.Set(ctx, "set_key", "set value", 1*time.Minute) 109 | 110 | _, err := pipe.Exec(ctx) 111 | Expect(err).NotTo(HaveOccurred()) 112 | 113 | Expect(get.Err()).NotTo(HaveOccurred()) 114 | Expect(get.Val()).To(Equal("pipeline get")) 115 | 116 | Expect(hashGet.Err()).NotTo(HaveOccurred()) 117 | Expect(hashGet.Val()).To(Equal("pipeline hash get")) 118 | 119 | Expect(set.Err()).NotTo(HaveOccurred()) 120 | Expect(set.Val()).To(Equal("OK")) 121 | }) 122 | 123 | It("pipeline not order", func() { 124 | clientMock.MatchExpectationsInOrder(false) 125 | 126 | hashGet := pipe.HGet(ctx, "hash_key", "hash_field") 127 | set := pipe.Set(ctx, "set_key", "set value", 1*time.Minute) 128 | get := pipe.Get(ctx, "key1") 129 | 130 | _, err := pipe.Exec(ctx) 131 | Expect(err).NotTo(HaveOccurred()) 132 | 133 | Expect(get.Err()).NotTo(HaveOccurred()) 134 | Expect(get.Val()).To(Equal("pipeline get")) 135 | 136 | Expect(hashGet.Err()).NotTo(HaveOccurred()) 137 | Expect(hashGet.Val()).To(Equal("pipeline hash get")) 138 | 139 | Expect(set.Err()).NotTo(HaveOccurred()) 140 | Expect(set.Val()).To(Equal("OK")) 141 | }) 142 | }) 143 | 144 | Describe("watch", func() { 145 | BeforeEach(func() { 146 | clientMock.ExpectWatch("key1", "key2") 147 | clientMock.ExpectGet("key1").SetVal("1") 148 | clientMock.ExpectSet("key2", "2", 1*time.Second).SetVal("OK") 149 | }) 150 | 151 | AfterEach(func() { 152 | hasUnexpectedCall, unexpectedCalls := clientMock.UnexpectedCallsWereMade() 153 | Expect(hasUnexpectedCall).To(BeTrue()) 154 | Expect(unexpectedCalls).ShouldNot(BeNil()) 155 | }) 156 | 157 | It("watch error", func() { 158 | clientMock.MatchExpectationsInOrder(false) 159 | txf := func(tx *redis.Tx) error { 160 | _ = tx.Get(ctx, "key1") 161 | _ = tx.Set(ctx, "key2", "2", 1*time.Second) 162 | return errors.New("watch tx error") 163 | } 164 | 165 | err := client.Watch(ctx, txf, "key1", "key2") 166 | Expect(err).To(Equal(errors.New("watch tx error"))) 167 | 168 | clientMock.ExpectWatch("key3", "key4").SetErr(errors.New("watch error")) 169 | txf = func(tx *redis.Tx) error { 170 | return nil 171 | } 172 | 173 | err = client.Watch(ctx, txf, "key3", "key4") 174 | Expect(err).To(Equal(errors.New("watch error"))) 175 | }) 176 | 177 | It("watch in order", func() { 178 | clientMock.MatchExpectationsInOrder(true) 179 | txf := func(tx *redis.Tx) error { 180 | val, err := tx.Get(ctx, "key1").Int64() 181 | if err != nil { 182 | return err 183 | } 184 | Expect(val).To(Equal(int64(1))) 185 | err = tx.Set(ctx, "key2", "2", 1*time.Second).Err() 186 | if err != nil { 187 | return err 188 | } 189 | return nil 190 | } 191 | 192 | err := client.Watch(ctx, txf, "key1", "key2") 193 | Expect(err).NotTo(HaveOccurred()) 194 | }) 195 | 196 | It("watch out of order", func() { 197 | clientMock.MatchExpectationsInOrder(false) 198 | txf := func(tx *redis.Tx) error { 199 | err := tx.Set(ctx, "key2", "2", 1*time.Second).Err() 200 | if err != nil { 201 | return err 202 | } 203 | val, err := tx.Get(ctx, "key1").Int64() 204 | if err != nil { 205 | return err 206 | } 207 | Expect(val).To(Equal(int64(1))) 208 | return nil 209 | } 210 | 211 | err := client.Watch(ctx, txf, "key1", "key2") 212 | Expect(err).NotTo(HaveOccurred()) 213 | }) 214 | }) 215 | 216 | Describe("work order", func() { 217 | 218 | BeforeEach(func() { 219 | clientMock.ExpectGet("key").RedisNil() 220 | clientMock.ExpectSet("key", "1", 1*time.Second).SetVal("OK") 221 | clientMock.ExpectGet("key").SetVal("1") 222 | clientMock.ExpectGetSet("key", "0").SetVal("1") 223 | }) 224 | 225 | It("ordinary", func() { 226 | get := client.Get(ctx, "key") 227 | Expect(get.Err()).To(Equal(redis.Nil)) 228 | Expect(get.Val()).To(Equal("")) 229 | 230 | set := client.Set(ctx, "key", "1", 1*time.Second) 231 | Expect(set.Err()).NotTo(HaveOccurred()) 232 | Expect(set.Val()).To(Equal("OK")) 233 | 234 | get = client.Get(ctx, "key") 235 | Expect(get.Err()).NotTo(HaveOccurred()) 236 | Expect(get.Val()).To(Equal("1")) 237 | 238 | getSet := client.GetSet(ctx, "key", "0") 239 | Expect(getSet.Err()).NotTo(HaveOccurred()) 240 | Expect(getSet.Val()).To(Equal("1")) 241 | 242 | hasUnexpectedCall, unexpectedCalls := clientMock.UnexpectedCallsWereMade() 243 | Expect(hasUnexpectedCall).To(BeFalse()) 244 | Expect(unexpectedCalls).To(BeNil()) 245 | }) 246 | 247 | It("surplus", func() { 248 | _ = client.Get(ctx, "key") 249 | 250 | set := client.Set(ctx, "key", "1", 1*time.Second) 251 | Expect(set.Err()).NotTo(HaveOccurred()) 252 | Expect(set.Val()).To(Equal("OK")) 253 | 254 | Expect(clientMock.ExpectationsWereMet()).To(HaveOccurred()) 255 | 256 | _ = client.Get(ctx, "key") 257 | Expect(clientMock.ExpectationsWereMet()).To(HaveOccurred()) 258 | 259 | hasUnexpectedCall, unexpectedCalls := clientMock.UnexpectedCallsWereMade() 260 | Expect(hasUnexpectedCall).To(BeFalse()) 261 | Expect(unexpectedCalls).To(BeNil()) 262 | 263 | _ = client.GetSet(ctx, "key", "0") 264 | }) 265 | 266 | It("not enough", func() { 267 | _ = client.Get(ctx, "key") 268 | _ = client.Set(ctx, "key", "1", 1*time.Second) 269 | _ = client.Get(ctx, "key") 270 | _ = client.GetSet(ctx, "key", "0") 271 | Expect(clientMock.ExpectationsWereMet()).NotTo(HaveOccurred()) 272 | 273 | get := client.HGet(ctx, "key", "field") 274 | Expect(get.Err()).To(HaveOccurred()) 275 | Expect(get.Val()).To(Equal("")) 276 | 277 | hasUnexpectedCall, unexpectedCalls := clientMock.UnexpectedCallsWereMade() 278 | Expect(hasUnexpectedCall).To(BeTrue()) 279 | Expect(unexpectedCalls).NotTo(BeNil()) 280 | }) 281 | }) 282 | 283 | Describe("work not order", func() { 284 | 285 | BeforeEach(func() { 286 | clientMock.MatchExpectationsInOrder(false) 287 | 288 | clientMock.ExpectSet("key", "1", 1*time.Second).SetVal("OK") 289 | clientMock.ExpectGet("key").SetVal("1") 290 | clientMock.ExpectGetSet("key", "0").SetVal("1") 291 | }) 292 | 293 | AfterEach(func() { 294 | hasUnexpectedCall, unexpectedCalls := clientMock.UnexpectedCallsWereMade() 295 | Expect(hasUnexpectedCall).To(BeFalse()) 296 | Expect(unexpectedCalls).To(BeNil()) 297 | }) 298 | 299 | It("ordinary", func() { 300 | get := client.Get(ctx, "key") 301 | Expect(get.Err()).NotTo(HaveOccurred()) 302 | Expect(get.Val()).To(Equal("1")) 303 | 304 | set := client.Set(ctx, "key", "1", 1*time.Second) 305 | Expect(set.Err()).NotTo(HaveOccurred()) 306 | Expect(set.Val()).To(Equal("OK")) 307 | 308 | getSet := client.GetSet(ctx, "key", "0") 309 | Expect(getSet.Err()).NotTo(HaveOccurred()) 310 | Expect(getSet.Val()).To(Equal("1")) 311 | }) 312 | }) 313 | 314 | Describe("work other match", func() { 315 | 316 | AfterEach(func() { 317 | hasUnexpectedCall, unexpectedCalls := clientMock.UnexpectedCallsWereMade() 318 | Expect(hasUnexpectedCall).To(BeFalse()) 319 | Expect(unexpectedCalls).To(BeNil()) 320 | }) 321 | 322 | It("regexp match", func() { 323 | clientMock.Regexp().ExpectSet("key", `^order_id_[0-9]{10}$`, 1*time.Second).SetVal("OK") 324 | clientMock.Regexp().ExpectSet("key2", `^order_id_[0-9]{4}\-[0-9]{2}\-[0-9]{2}T[0-9]{2}:[0-9]{2}:[0-9]{2}.+$`, 1*time.Second).SetVal("OK") 325 | 326 | set := client.Set(ctx, "key", fmt.Sprintf("order_id_%d", time.Now().Unix()), 1*time.Second) 327 | Expect(set.Err()).NotTo(HaveOccurred()) 328 | Expect(set.Val()).To(Equal("OK")) 329 | 330 | // no regexp 331 | set = client.Set(ctx, "key2", fmt.Sprintf("order_id_%s", time.Now().Format(time.UnixDate)), 1*time.Second) 332 | Expect(set.Err()).To(HaveOccurred()) 333 | Expect(set.Val()).To(Equal("")) 334 | 335 | set = client.Set(ctx, "key2", fmt.Sprintf("order_id_%s", time.Now().Format(time.RFC3339)), 1*time.Second) 336 | Expect(set.Err()).NotTo(HaveOccurred()) 337 | Expect(set.Val()).To(Equal("OK")) 338 | }) 339 | 340 | It("custom match", func() { 341 | clientMock.CustomMatch(func(expected, actual []interface{}) error { 342 | return errors.New("mismatch") 343 | }).ExpectGet("key").SetVal("OK") 344 | 345 | get := client.Get(ctx, "key") 346 | Expect(get.Err()).To(Equal(errors.New("mismatch"))) 347 | Expect(get.Val()).To(Equal("")) 348 | 349 | set := client.Incr(ctx, "key") 350 | Expect(set.Err()).To(HaveOccurred()) 351 | Expect(set.Err()).NotTo(Equal(errors.New("mismatch"))) 352 | Expect(set.Val()).To(Equal(int64(0))) 353 | 354 | // no match, no pass 355 | Expect(clientMock.ExpectationsWereMet()).To(HaveOccurred()) 356 | 357 | // let AfterEach pass 358 | clientMock.ClearExpect() 359 | }) 360 | 361 | }) 362 | 363 | Describe("work error", func() { 364 | 365 | AfterEach(func() { 366 | hasUnexpectedCall, unexpectedCalls := clientMock.UnexpectedCallsWereMade() 367 | Expect(hasUnexpectedCall).To(BeFalse()) 368 | Expect(unexpectedCalls).To(BeNil()) 369 | }) 370 | 371 | It("set error", func() { 372 | clientMock.ExpectGet("key").SetErr(errors.New("set error")) 373 | 374 | get := client.Get(ctx, "key") 375 | Expect(get.Err()).To(Equal(errors.New("set error"))) 376 | Expect(get.Val()).To(Equal("")) 377 | }) 378 | 379 | It("not set", func() { 380 | clientMock.ExpectGet("key") 381 | 382 | get := client.Get(ctx, "key") 383 | Expect(get.Err()).To(HaveOccurred()) 384 | Expect(get.Val()).To(Equal("")) 385 | }) 386 | 387 | It("set zero", func() { 388 | clientMock.ExpectGet("key").SetVal("") 389 | 390 | get := client.Get(ctx, "key") 391 | Expect(get.Err()).NotTo(HaveOccurred()) 392 | Expect(get.Val()).To(Equal("")) 393 | }) 394 | 395 | }) 396 | }) 397 | -------------------------------------------------------------------------------- /cluster_test.go: -------------------------------------------------------------------------------- 1 | package redismock 2 | 3 | import ( 4 | "errors" 5 | "fmt" 6 | "time" 7 | 8 | . "github.com/onsi/ginkgo" 9 | . "github.com/onsi/gomega" 10 | "github.com/redis/go-redis/v9" 11 | ) 12 | 13 | var _ = Describe("Cluster", func() { 14 | var ( 15 | client *redis.ClusterClient 16 | clusterMock ClusterClientMock 17 | ) 18 | 19 | BeforeEach(func() { 20 | client, clusterMock = NewClusterMock() 21 | }) 22 | 23 | AfterEach(func() { 24 | Expect(client.Close()).NotTo(HaveOccurred()) 25 | Expect(clusterMock.ExpectationsWereMet()).NotTo(HaveOccurred()) 26 | }) 27 | 28 | Describe("work order", func() { 29 | BeforeEach(func() { 30 | clusterMock.ExpectGet("key").RedisNil() 31 | clusterMock.ExpectSet("key", "1", 1*time.Second).SetVal("OK") 32 | clusterMock.ExpectGet("key").SetVal("1") 33 | clusterMock.ExpectGetSet("key", "0").SetVal("1") 34 | }) 35 | 36 | It("ordinary", func() { 37 | get := client.Get(ctx, "key") 38 | Expect(get.Err()).To(Equal(redis.Nil)) 39 | Expect(get.Val()).To(Equal("")) 40 | 41 | set := client.Set(ctx, "key", "1", 1*time.Second) 42 | Expect(set.Err()).NotTo(HaveOccurred()) 43 | Expect(set.Val()).To(Equal("OK")) 44 | 45 | get = client.Get(ctx, "key") 46 | Expect(get.Err()).NotTo(HaveOccurred()) 47 | Expect(get.Val()).To(Equal("1")) 48 | 49 | getSet := client.GetSet(ctx, "key", "0") 50 | Expect(getSet.Err()).NotTo(HaveOccurred()) 51 | Expect(getSet.Val()).To(Equal("1")) 52 | 53 | hasUnexpectedCall, unexpectedCalls := clusterMock.UnexpectedCallsWereMade() 54 | Expect(hasUnexpectedCall).To(BeFalse()) 55 | Expect(unexpectedCalls).To(BeNil()) 56 | }) 57 | 58 | It("surplus", func() { 59 | _ = client.Get(ctx, "key") 60 | 61 | set := client.Set(ctx, "key", "1", 1*time.Second) 62 | Expect(set.Err()).NotTo(HaveOccurred()) 63 | Expect(set.Val()).To(Equal("OK")) 64 | 65 | Expect(clusterMock.ExpectationsWereMet()).To(HaveOccurred()) 66 | 67 | _ = client.Get(ctx, "key") 68 | Expect(clusterMock.ExpectationsWereMet()).To(HaveOccurred()) 69 | 70 | hasUnexpectedCall, unexpectedCalls := clusterMock.UnexpectedCallsWereMade() 71 | Expect(hasUnexpectedCall).To(BeFalse()) 72 | Expect(unexpectedCalls).To(BeNil()) 73 | 74 | _ = client.GetSet(ctx, "key", "0") 75 | }) 76 | 77 | It("not enough", func() { 78 | _ = client.Get(ctx, "key") 79 | _ = client.Set(ctx, "key", "1", 1*time.Second) 80 | _ = client.Get(ctx, "key") 81 | _ = client.GetSet(ctx, "key", "0") 82 | Expect(clusterMock.ExpectationsWereMet()).NotTo(HaveOccurred()) 83 | 84 | get := client.HGet(ctx, "key", "field") 85 | Expect(get.Err()).To(HaveOccurred()) 86 | Expect(get.Val()).To(Equal("")) 87 | 88 | hasUnexpectedCall, unexpectedCalls := clusterMock.UnexpectedCallsWereMade() 89 | Expect(hasUnexpectedCall).To(BeTrue()) 90 | Expect(unexpectedCalls).NotTo(BeNil()) 91 | }) 92 | }) 93 | 94 | Describe("work not order", func() { 95 | 96 | BeforeEach(func() { 97 | clusterMock.MatchExpectationsInOrder(false) 98 | 99 | clusterMock.ExpectSet("key", "1", 1*time.Second).SetVal("OK") 100 | clusterMock.ExpectGet("key").SetVal("1") 101 | clusterMock.ExpectGetSet("key", "0").SetVal("1") 102 | }) 103 | 104 | AfterEach(func() { 105 | hasUnexpectedCall, unexpectedCalls := clusterMock.UnexpectedCallsWereMade() 106 | Expect(hasUnexpectedCall).To(BeFalse()) 107 | Expect(unexpectedCalls).To(BeNil()) 108 | }) 109 | 110 | It("ordinary", func() { 111 | get := client.Get(ctx, "key") 112 | Expect(get.Err()).NotTo(HaveOccurred()) 113 | Expect(get.Val()).To(Equal("1")) 114 | 115 | set := client.Set(ctx, "key", "1", 1*time.Second) 116 | Expect(set.Err()).NotTo(HaveOccurred()) 117 | Expect(set.Val()).To(Equal("OK")) 118 | 119 | getSet := client.GetSet(ctx, "key", "0") 120 | Expect(getSet.Err()).NotTo(HaveOccurred()) 121 | Expect(getSet.Val()).To(Equal("1")) 122 | }) 123 | }) 124 | 125 | Describe("work other match", func() { 126 | 127 | AfterEach(func() { 128 | hasUnexpectedCall, unexpectedCalls := clusterMock.UnexpectedCallsWereMade() 129 | Expect(hasUnexpectedCall).To(BeFalse()) 130 | Expect(unexpectedCalls).To(BeNil()) 131 | }) 132 | 133 | It("regexp match", func() { 134 | clusterMock.Regexp().ExpectSet("key", `^order_id_[0-9]{10}$`, 1*time.Second).SetVal("OK") 135 | clusterMock.Regexp().ExpectSet("key2", `^order_id_[0-9]{4}\-[0-9]{2}\-[0-9]{2}T[0-9]{2}:[0-9]{2}:[0-9]{2}.+$`, 1*time.Second).SetVal("OK") 136 | 137 | set := client.Set(ctx, "key", fmt.Sprintf("order_id_%d", time.Now().Unix()), 1*time.Second) 138 | Expect(set.Err()).NotTo(HaveOccurred()) 139 | Expect(set.Val()).To(Equal("OK")) 140 | 141 | // no regexp 142 | set = client.Set(ctx, "key2", fmt.Sprintf("order_id_%s", time.Now().Format(time.UnixDate)), 1*time.Second) 143 | Expect(set.Err()).To(HaveOccurred()) 144 | Expect(set.Val()).To(Equal("")) 145 | 146 | set = client.Set(ctx, "key2", fmt.Sprintf("order_id_%s", time.Now().Format(time.RFC3339)), 1*time.Second) 147 | Expect(set.Err()).NotTo(HaveOccurred()) 148 | Expect(set.Val()).To(Equal("OK")) 149 | }) 150 | 151 | It("custom match", func() { 152 | clusterMock.CustomMatch(func(expected, actual []interface{}) error { 153 | return errors.New("mismatch") 154 | }).ExpectGet("key").SetVal("OK") 155 | 156 | get := client.Get(ctx, "key") 157 | Expect(get.Err()).To(Equal(errors.New("mismatch"))) 158 | Expect(get.Val()).To(Equal("")) 159 | 160 | set := client.Incr(ctx, "key") 161 | Expect(set.Err()).To(HaveOccurred()) 162 | Expect(set.Err()).NotTo(Equal(errors.New("mismatch"))) 163 | Expect(set.Val()).To(Equal(int64(0))) 164 | 165 | // no match, no pass 166 | Expect(clusterMock.ExpectationsWereMet()).To(HaveOccurred()) 167 | 168 | // let AfterEach pass 169 | clusterMock.ClearExpect() 170 | }) 171 | 172 | }) 173 | 174 | Describe("work error", func() { 175 | 176 | AfterEach(func() { 177 | hasUnexpectedCall, unexpectedCalls := clusterMock.UnexpectedCallsWereMade() 178 | Expect(hasUnexpectedCall).To(BeFalse()) 179 | Expect(unexpectedCalls).To(BeNil()) 180 | }) 181 | 182 | It("set error", func() { 183 | clusterMock.ExpectGet("key").SetErr(errors.New("set error")) 184 | 185 | get := client.Get(ctx, "key") 186 | Expect(get.Err()).To(Equal(errors.New("set error"))) 187 | Expect(get.Val()).To(Equal("")) 188 | }) 189 | 190 | It("not set", func() { 191 | clusterMock.ExpectGet("key") 192 | 193 | get := client.Get(ctx, "key") 194 | Expect(get.Err()).To(HaveOccurred()) 195 | Expect(get.Val()).To(Equal("")) 196 | }) 197 | 198 | It("set zero", func() { 199 | clusterMock.ExpectGet("key").SetVal("") 200 | 201 | get := client.Get(ctx, "key") 202 | Expect(get.Err()).NotTo(HaveOccurred()) 203 | Expect(get.Val()).To(Equal("")) 204 | }) 205 | }) 206 | }) 207 | -------------------------------------------------------------------------------- /example/example.go: -------------------------------------------------------------------------------- 1 | package example 2 | 3 | import ( 4 | "context" 5 | "errors" 6 | "time" 7 | 8 | "github.com/go-redis/redismock/v9" 9 | ) 10 | 11 | var _ = example 12 | 13 | func example() { 14 | var ctx = context.TODO() 15 | 16 | // get redis.Client and mock 17 | db, mock := redismock.NewClientMock() 18 | 19 | //the order of commands expected and executed must be the same 20 | //this is the default value 21 | mock.MatchExpectationsInOrder(true) 22 | 23 | //simple matching 24 | 25 | //hget command return error 26 | mock.ExpectHGet("key", "field").SetErr(errors.New("error")) 27 | //db.HGet(ctx, "key", "field").Err() == errors.New("error") 28 | 29 | //hget command return value 30 | mock.ExpectHGet("key", "field").SetVal("test value") 31 | //db.HGet(ctx, "key", "field").Val() == "test value" 32 | 33 | //hget command return redis.Nil 34 | mock.ExpectHGet("key", "field").RedisNil() 35 | //db.HGet(ctx, "key", "field").Err() == redis.Nil 36 | 37 | //hget command... do not set return 38 | mock.ExpectHGet("key", "field") 39 | //db.HGet(ctx, "key", "field").Err() != nil 40 | 41 | //------------ 42 | 43 | //clean up all expectations 44 | //reset expected redis command 45 | mock.ClearExpect() 46 | 47 | //regular, uncertain value 48 | 49 | db.HSet(ctx, "key", "field", time.Now().Unix()) 50 | mock.Regexp().ExpectHSet("key", "field", `^[0-9]+$`).SetVal(1) 51 | 52 | //------------ 53 | mock.ClearExpect() 54 | 55 | //custom match, regular expression can not meet the requirements 56 | mock.CustomMatch(func(expected, actual []interface{}) error { 57 | //expected == cmd.Args() 58 | return nil 59 | }).ExpectGet("key").SetVal("value") 60 | 61 | //-------- 62 | 63 | //all the expected redis commands have been matched 64 | //otherwise return an error 65 | if err := mock.ExpectationsWereMet(); err != nil { 66 | //error 67 | panic(err) 68 | } 69 | 70 | //--------- 71 | 72 | //any order 73 | //this is useful if your redis commands are executed concurrently 74 | mock.MatchExpectationsInOrder(false) 75 | 76 | //1-2-3 77 | mock.ExpectGet("key").SetVal("value") 78 | mock.ExpectSet("set-key", "set-value", 1).SetVal("OK") 79 | mock.ExpectHGet("hash-get", "hash-field").SetVal("hash-value") 80 | 81 | //3-1-2 82 | _ = db.HGet(ctx, "hash-get", "hash-field") 83 | _ = db.Get(ctx, "key") 84 | _ = db.Set(ctx, "set-key", "set-value", 1) 85 | 86 | //-------------- 87 | 88 | //pipeline, pipeline is not a redis command, is a collection of commands 89 | mock.ExpectGet("key").SetVal("value") 90 | mock.ExpectSet("key", "value", 1).SetVal("OK") 91 | 92 | pipe := db.Pipeline() 93 | _ = pipe.Get(ctx, "key") 94 | _ = pipe.Set(ctx, "key", "value", 1) 95 | _, _ = pipe.Exec(ctx) 96 | 97 | //--------------------- 98 | mock.ClearExpect() 99 | 100 | //TxPipeline 101 | mock.ExpectTxPipeline() 102 | mock.ExpectGet("key").SetVal("value") 103 | mock.ExpectSet("key", "value", 1).SetVal("OK") 104 | mock.ExpectTxPipelineExec() 105 | 106 | pipe = db.TxPipeline() 107 | _ = pipe.Get(ctx, "key") 108 | _ = pipe.Set(ctx, "key", "value", 1) 109 | _, _ = pipe.Exec(ctx) 110 | 111 | //Watch 112 | mock.ExpectWatch("key1", "key2").SetErr(errors.New("watch error")) 113 | mock.ExpectGet("key1").SetVal("1") 114 | mock.ExpectSet("key2", "2", 1*time.Second).SetVal("OK") 115 | 116 | //err := db.Watch(ctx, func(tx *redis.Tx) error { 117 | // tx.Get(ctx, "key1") 118 | // tx.Set(ctx, "key2", "2", 1 * time.Second) 119 | // return nil 120 | //}, "key1", "key2") 121 | //reflect.DeepEqual(err, errors.New("watch error")) 122 | } 123 | -------------------------------------------------------------------------------- /example/ordinary/main.go: -------------------------------------------------------------------------------- 1 | package ordinary 2 | 3 | import ( 4 | "context" 5 | 6 | "github.com/redis/go-redis/v9" 7 | ) 8 | 9 | const itemKey = "item_cache" 10 | 11 | var ctx = context.TODO() 12 | 13 | func ItemCache(db *redis.Client, itemID string) (item string, err error) { 14 | item, err = db.HGet(ctx, itemKey, itemID).Result() 15 | if err == redis.Nil { 16 | // call api 17 | item = "information" 18 | 19 | err = db.HSet(ctx, itemKey, itemID, item).Err() 20 | } 21 | return 22 | } 23 | -------------------------------------------------------------------------------- /example/ordinary/main_test.go: -------------------------------------------------------------------------------- 1 | package ordinary 2 | 3 | import ( 4 | "errors" 5 | "testing" 6 | 7 | "github.com/go-redis/redismock/v9" 8 | ) 9 | 10 | func TestItemCacheFail(t *testing.T) { 11 | var ( 12 | itemID = "7d373ca58e" 13 | setErr = errors.New("bomb") 14 | ) 15 | db, mock := redismock.NewClientMock() 16 | 17 | mock.ExpectHGet(itemKey, itemID).RedisNil() 18 | mock.Regexp().ExpectHSet(itemKey, itemID, `^[a-z]+$`).SetErr(setErr) 19 | 20 | _, err := ItemCache(db, itemID) 21 | if err != setErr { 22 | t.Error("expectation error") 23 | } 24 | if err := mock.ExpectationsWereMet(); err != nil { 25 | t.Error(err) 26 | } 27 | } 28 | 29 | func TestItemCacheSuccess(t *testing.T) { 30 | var ( 31 | itemID = "7d373ca58e" 32 | ) 33 | db, mock := redismock.NewClientMock() 34 | 35 | mock.ExpectHGet(itemKey, itemID).RedisNil() 36 | mock.Regexp().ExpectHSet(itemKey, itemID, `^[a-z]+$`).SetVal(1) 37 | 38 | item, err := ItemCache(db, itemID) 39 | if err != nil { 40 | t.Errorf("unexpected error: %s", err.Error()) 41 | } 42 | if item != "information" { 43 | t.Errorf("unexpected item: %s", item) 44 | } 45 | if err := mock.ExpectationsWereMet(); err != nil { 46 | t.Error(err) 47 | } 48 | 49 | //---------- 50 | 51 | //clean up all expectations 52 | //reset expected redis command 53 | mock.ClearExpect() 54 | mock.ExpectHGet(itemKey, itemID).SetVal("news") 55 | 56 | item, err = ItemCache(db, itemID) 57 | if err != nil { 58 | t.Errorf("unexpected error: %s", err.Error()) 59 | } 60 | if item != "news" { 61 | t.Errorf("unexpected item: %s", item) 62 | } 63 | if err := mock.ExpectationsWereMet(); err != nil { 64 | t.Error(err) 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /expect.go: -------------------------------------------------------------------------------- 1 | package redismock 2 | 3 | import ( 4 | "fmt" 5 | "reflect" 6 | "sync" 7 | "time" 8 | "unsafe" 9 | 10 | "github.com/redis/go-redis/v9" 11 | ) 12 | 13 | type baseMock interface { 14 | // ClearExpect clear whether all queued expectations were met in order 15 | ClearExpect() 16 | 17 | // Regexp using the regular match command 18 | Regexp() *mock 19 | 20 | // CustomMatch using custom matching functions 21 | CustomMatch(fn CustomMatch) *mock 22 | 23 | // ExpectationsWereMet checks whether all queued expectations 24 | // were met in order. If any of them was not met - an error is returned. 25 | ExpectationsWereMet() error 26 | 27 | // UnexpectedCallsWereMade returns any unexpected calls which were made. 28 | // If any unexpected call was made, a list of unexpected call redis.Cmder is returned. 29 | UnexpectedCallsWereMade() (bool, []redis.Cmder) 30 | 31 | // MatchExpectationsInOrder gives an option whether to match all expectations in the order they were set or not. 32 | MatchExpectationsInOrder(b bool) 33 | 34 | ExpectDo(args ...interface{}) *ExpectedCmd 35 | ExpectCommand() *ExpectedCommandsInfo 36 | ExpectCommandList(filter *redis.FilterBy) *ExpectedStringSlice 37 | ExpectCommandGetKeys(commands ...interface{}) *ExpectedStringSlice 38 | ExpectCommandGetKeysAndFlags(commands ...interface{}) *ExpectedKeyFlags 39 | ExpectClientGetName() *ExpectedString 40 | ExpectEcho(message interface{}) *ExpectedString 41 | ExpectPing() *ExpectedStatus 42 | ExpectQuit() *ExpectedStatus 43 | ExpectDel(keys ...string) *ExpectedInt 44 | ExpectUnlink(keys ...string) *ExpectedInt 45 | ExpectDump(key string) *ExpectedString 46 | ExpectExists(keys ...string) *ExpectedInt 47 | ExpectExpire(key string, expiration time.Duration) *ExpectedBool 48 | ExpectExpireAt(key string, tm time.Time) *ExpectedBool 49 | ExpectExpireTime(key string) *ExpectedDuration 50 | ExpectExpireNX(key string, expiration time.Duration) *ExpectedBool 51 | ExpectExpireXX(key string, expiration time.Duration) *ExpectedBool 52 | ExpectExpireGT(key string, expiration time.Duration) *ExpectedBool 53 | ExpectExpireLT(key string, expiration time.Duration) *ExpectedBool 54 | ExpectKeys(pattern string) *ExpectedStringSlice 55 | ExpectMigrate(host, port, key string, db int, timeout time.Duration) *ExpectedStatus 56 | ExpectMove(key string, db int) *ExpectedBool 57 | ExpectObjectRefCount(key string) *ExpectedInt 58 | ExpectObjectEncoding(key string) *ExpectedString 59 | ExpectObjectIdleTime(key string) *ExpectedDuration 60 | ExpectPersist(key string) *ExpectedBool 61 | ExpectPExpire(key string, expiration time.Duration) *ExpectedBool 62 | ExpectPExpireAt(key string, tm time.Time) *ExpectedBool 63 | ExpectPExpireTime(key string) *ExpectedDuration 64 | ExpectPTTL(key string) *ExpectedDuration 65 | ExpectRandomKey() *ExpectedString 66 | ExpectRename(key, newkey string) *ExpectedStatus 67 | ExpectRenameNX(key, newkey string) *ExpectedBool 68 | ExpectRestore(key string, ttl time.Duration, value string) *ExpectedStatus 69 | ExpectRestoreReplace(key string, ttl time.Duration, value string) *ExpectedStatus 70 | ExpectSort(key string, sort *redis.Sort) *ExpectedStringSlice 71 | ExpectSortRO(key string, sort *redis.Sort) *ExpectedStringSlice 72 | ExpectSortStore(key, store string, sort *redis.Sort) *ExpectedInt 73 | ExpectSortInterfaces(key string, sort *redis.Sort) *ExpectedSlice 74 | ExpectTouch(keys ...string) *ExpectedInt 75 | ExpectTTL(key string) *ExpectedDuration 76 | ExpectType(key string) *ExpectedStatus 77 | ExpectAppend(key, value string) *ExpectedInt 78 | ExpectDecr(key string) *ExpectedInt 79 | ExpectDecrBy(key string, decrement int64) *ExpectedInt 80 | ExpectGet(key string) *ExpectedString 81 | ExpectGetRange(key string, start, end int64) *ExpectedString 82 | ExpectGetSet(key string, value interface{}) *ExpectedString 83 | ExpectGetEx(key string, expiration time.Duration) *ExpectedString 84 | ExpectGetDel(key string) *ExpectedString 85 | ExpectIncr(key string) *ExpectedInt 86 | ExpectIncrBy(key string, value int64) *ExpectedInt 87 | ExpectIncrByFloat(key string, value float64) *ExpectedFloat 88 | ExpectMGet(keys ...string) *ExpectedSlice 89 | ExpectMSet(values ...interface{}) *ExpectedStatus 90 | ExpectMSetNX(values ...interface{}) *ExpectedBool 91 | ExpectSet(key string, value interface{}, expiration time.Duration) *ExpectedStatus 92 | ExpectSetArgs(key string, value interface{}, a redis.SetArgs) *ExpectedStatus 93 | ExpectSetEx(key string, value interface{}, expiration time.Duration) *ExpectedStatus 94 | ExpectSetNX(key string, value interface{}, expiration time.Duration) *ExpectedBool 95 | ExpectSetXX(key string, value interface{}, expiration time.Duration) *ExpectedBool 96 | ExpectSetRange(key string, offset int64, value string) *ExpectedInt 97 | ExpectStrLen(key string) *ExpectedInt 98 | ExpectCopy(sourceKey string, destKey string, db int, replace bool) *ExpectedInt 99 | 100 | ExpectGetBit(key string, offset int64) *ExpectedInt 101 | ExpectSetBit(key string, offset int64, value int) *ExpectedInt 102 | ExpectBitCount(key string, bitCount *redis.BitCount) *ExpectedInt 103 | ExpectBitOpAnd(destKey string, keys ...string) *ExpectedInt 104 | ExpectBitOpOr(destKey string, keys ...string) *ExpectedInt 105 | ExpectBitOpXor(destKey string, keys ...string) *ExpectedInt 106 | ExpectBitOpNot(destKey string, key string) *ExpectedInt 107 | ExpectBitPos(key string, bit int64, pos ...int64) *ExpectedInt 108 | ExpectBitPosSpan(key string, bit int8, start, end int64, span string) *ExpectedInt 109 | ExpectBitField(key string, args ...interface{}) *ExpectedIntSlice 110 | 111 | ExpectScan(cursor uint64, match string, count int64) *ExpectedScan 112 | ExpectScanType(cursor uint64, match string, count int64, keyType string) *ExpectedScan 113 | ExpectSScan(key string, cursor uint64, match string, count int64) *ExpectedScan 114 | ExpectHScan(key string, cursor uint64, match string, count int64) *ExpectedScan 115 | ExpectZScan(key string, cursor uint64, match string, count int64) *ExpectedScan 116 | 117 | ExpectHDel(key string, fields ...string) *ExpectedInt 118 | ExpectHExists(key, field string) *ExpectedBool 119 | ExpectHGet(key, field string) *ExpectedString 120 | ExpectHGetAll(key string) *ExpectedMapStringString 121 | ExpectHIncrBy(key, field string, incr int64) *ExpectedInt 122 | ExpectHIncrByFloat(key, field string, incr float64) *ExpectedFloat 123 | ExpectHKeys(key string) *ExpectedStringSlice 124 | ExpectHLen(key string) *ExpectedInt 125 | ExpectHMGet(key string, fields ...string) *ExpectedSlice 126 | ExpectHSet(key string, values ...interface{}) *ExpectedInt 127 | ExpectHMSet(key string, values ...interface{}) *ExpectedBool 128 | ExpectHSetNX(key, field string, value interface{}) *ExpectedBool 129 | ExpectHVals(key string) *ExpectedStringSlice 130 | ExpectHRandField(key string, count int) *ExpectedStringSlice 131 | ExpectHRandFieldWithValues(key string, count int) *ExpectedKeyValueSlice 132 | 133 | ExpectBLPop(timeout time.Duration, keys ...string) *ExpectedStringSlice 134 | ExpectBLMPop(timeout time.Duration, direction string, count int64, keys ...string) *ExpectedKeyValues 135 | ExpectBRPop(timeout time.Duration, keys ...string) *ExpectedStringSlice 136 | ExpectBRPopLPush(source, destination string, timeout time.Duration) *ExpectedString 137 | ExpectLCS(q *redis.LCSQuery) *ExpectedLCS 138 | ExpectLIndex(key string, index int64) *ExpectedString 139 | ExpectLInsert(key, op string, pivot, value interface{}) *ExpectedInt 140 | ExpectLInsertBefore(key string, pivot, value interface{}) *ExpectedInt 141 | ExpectLInsertAfter(key string, pivot, value interface{}) *ExpectedInt 142 | ExpectLLen(key string) *ExpectedInt 143 | ExpectLPop(key string) *ExpectedString 144 | ExpectLPopCount(key string, count int) *ExpectedStringSlice 145 | ExpectLMPop(direction string, count int64, keys ...string) *ExpectedKeyValues 146 | ExpectLPos(key string, value string, args redis.LPosArgs) *ExpectedInt 147 | ExpectLPosCount(key string, value string, count int64, args redis.LPosArgs) *ExpectedIntSlice 148 | ExpectLPush(key string, values ...interface{}) *ExpectedInt 149 | ExpectLPushX(key string, values ...interface{}) *ExpectedInt 150 | ExpectLRange(key string, start, stop int64) *ExpectedStringSlice 151 | ExpectLRem(key string, count int64, value interface{}) *ExpectedInt 152 | ExpectLSet(key string, index int64, value interface{}) *ExpectedStatus 153 | ExpectLTrim(key string, start, stop int64) *ExpectedStatus 154 | ExpectRPop(key string) *ExpectedString 155 | ExpectRPopCount(key string, count int) *ExpectedStringSlice 156 | ExpectRPopLPush(source, destination string) *ExpectedString 157 | ExpectRPush(key string, values ...interface{}) *ExpectedInt 158 | ExpectRPushX(key string, values ...interface{}) *ExpectedInt 159 | ExpectLMove(source, destination, srcpos, destpos string) *ExpectedString 160 | ExpectBLMove(source, destination, srcpos, destpos string, timeout time.Duration) *ExpectedString 161 | 162 | ExpectSAdd(key string, members ...interface{}) *ExpectedInt 163 | ExpectSCard(key string) *ExpectedInt 164 | ExpectSDiff(keys ...string) *ExpectedStringSlice 165 | ExpectSDiffStore(destination string, keys ...string) *ExpectedInt 166 | ExpectSInter(keys ...string) *ExpectedStringSlice 167 | ExpectSInterCard(limit int64, keys ...string) *ExpectedInt 168 | ExpectSInterStore(destination string, keys ...string) *ExpectedInt 169 | ExpectSIsMember(key string, member interface{}) *ExpectedBool 170 | ExpectSMIsMember(key string, members ...interface{}) *ExpectedBoolSlice 171 | ExpectSMembers(key string) *ExpectedStringSlice 172 | ExpectSMembersMap(key string) *ExpectedStringStructMap 173 | ExpectSMove(source, destination string, member interface{}) *ExpectedBool 174 | ExpectSPop(key string) *ExpectedString 175 | ExpectSPopN(key string, count int64) *ExpectedStringSlice 176 | ExpectSRandMember(key string) *ExpectedString 177 | ExpectSRandMemberN(key string, count int64) *ExpectedStringSlice 178 | ExpectSRem(key string, members ...interface{}) *ExpectedInt 179 | ExpectSUnion(keys ...string) *ExpectedStringSlice 180 | ExpectSUnionStore(destination string, keys ...string) *ExpectedInt 181 | 182 | ExpectXAdd(a *redis.XAddArgs) *ExpectedString 183 | ExpectXDel(stream string, ids ...string) *ExpectedInt 184 | ExpectXLen(stream string) *ExpectedInt 185 | ExpectXRange(stream, start, stop string) *ExpectedXMessageSlice 186 | ExpectXRangeN(stream, start, stop string, count int64) *ExpectedXMessageSlice 187 | ExpectXRevRange(stream string, start, stop string) *ExpectedXMessageSlice 188 | ExpectXRevRangeN(stream string, start, stop string, count int64) *ExpectedXMessageSlice 189 | ExpectXRead(a *redis.XReadArgs) *ExpectedXStreamSlice 190 | ExpectXReadStreams(streams ...string) *ExpectedXStreamSlice 191 | ExpectXGroupCreate(stream, group, start string) *ExpectedStatus 192 | ExpectXGroupCreateMkStream(stream, group, start string) *ExpectedStatus 193 | ExpectXGroupSetID(stream, group, start string) *ExpectedStatus 194 | ExpectXGroupDestroy(stream, group string) *ExpectedInt 195 | ExpectXGroupCreateConsumer(stream, group, consumer string) *ExpectedInt 196 | ExpectXGroupDelConsumer(stream, group, consumer string) *ExpectedInt 197 | ExpectXReadGroup(a *redis.XReadGroupArgs) *ExpectedXStreamSlice 198 | ExpectXAck(stream, group string, ids ...string) *ExpectedInt 199 | ExpectXPending(stream, group string) *ExpectedXPending 200 | ExpectXPendingExt(a *redis.XPendingExtArgs) *ExpectedXPendingExt 201 | ExpectXClaim(a *redis.XClaimArgs) *ExpectedXMessageSlice 202 | ExpectXClaimJustID(a *redis.XClaimArgs) *ExpectedStringSlice 203 | ExpectXAutoClaim(a *redis.XAutoClaimArgs) *ExpectedXAutoClaim 204 | ExpectXAutoClaimJustID(a *redis.XAutoClaimArgs) *ExpectedXAutoClaimJustID 205 | ExpectXTrimMaxLen(key string, maxLen int64) *ExpectedInt 206 | ExpectXTrimMaxLenApprox(key string, maxLen, limit int64) *ExpectedInt 207 | ExpectXTrimMinID(key string, minID string) *ExpectedInt 208 | ExpectXTrimMinIDApprox(key string, minID string, limit int64) *ExpectedInt 209 | ExpectXInfoGroups(key string) *ExpectedXInfoGroups 210 | ExpectXInfoStream(key string) *ExpectedXInfoStream 211 | ExpectXInfoStreamFull(key string, count int) *ExpectedXInfoStreamFull 212 | ExpectXInfoConsumers(key string, group string) *ExpectedXInfoConsumers 213 | 214 | ExpectBZPopMax(timeout time.Duration, keys ...string) *ExpectedZWithKey 215 | ExpectBZPopMin(timeout time.Duration, keys ...string) *ExpectedZWithKey 216 | ExpectBZMPop(timeout time.Duration, order string, count int64, keys ...string) *ExpectedZSliceWithKey 217 | 218 | ExpectZAdd(key string, members ...redis.Z) *ExpectedInt 219 | ExpectZAddLT(key string, members ...redis.Z) *ExpectedInt 220 | ExpectZAddGT(key string, members ...redis.Z) *ExpectedInt 221 | ExpectZAddNX(key string, members ...redis.Z) *ExpectedInt 222 | ExpectZAddXX(key string, members ...redis.Z) *ExpectedInt 223 | ExpectZAddArgs(key string, args redis.ZAddArgs) *ExpectedInt 224 | ExpectZAddArgsIncr(key string, args redis.ZAddArgs) *ExpectedFloat 225 | ExpectZCard(key string) *ExpectedInt 226 | ExpectZCount(key, min, max string) *ExpectedInt 227 | ExpectZLexCount(key, min, max string) *ExpectedInt 228 | ExpectZIncrBy(key string, increment float64, member string) *ExpectedFloat 229 | ExpectZInter(store *redis.ZStore) *ExpectedStringSlice 230 | ExpectZInterWithScores(store *redis.ZStore) *ExpectedZSlice 231 | ExpectZInterCard(limit int64, keys ...string) *ExpectedInt 232 | ExpectZInterStore(destination string, store *redis.ZStore) *ExpectedInt 233 | ExpectZMPop(order string, count int64, keys ...string) *ExpectedZSliceWithKey 234 | ExpectZMScore(key string, members ...string) *ExpectedFloatSlice 235 | ExpectZPopMax(key string, count ...int64) *ExpectedZSlice 236 | ExpectZPopMin(key string, count ...int64) *ExpectedZSlice 237 | ExpectZRange(key string, start, stop int64) *ExpectedStringSlice 238 | ExpectZRangeWithScores(key string, start, stop int64) *ExpectedZSlice 239 | ExpectZRangeByScore(key string, opt *redis.ZRangeBy) *ExpectedStringSlice 240 | ExpectZRangeByLex(key string, opt *redis.ZRangeBy) *ExpectedStringSlice 241 | ExpectZRangeByScoreWithScores(key string, opt *redis.ZRangeBy) *ExpectedZSlice 242 | ExpectZRangeArgs(z redis.ZRangeArgs) *ExpectedStringSlice 243 | ExpectZRangeArgsWithScores(z redis.ZRangeArgs) *ExpectedZSlice 244 | ExpectZRangeStore(dst string, z redis.ZRangeArgs) *ExpectedInt 245 | ExpectZRank(key, member string) *ExpectedInt 246 | ExpectZRem(key string, members ...interface{}) *ExpectedInt 247 | ExpectZRemRangeByRank(key string, start, stop int64) *ExpectedInt 248 | ExpectZRemRangeByScore(key, min, max string) *ExpectedInt 249 | ExpectZRemRangeByLex(key, min, max string) *ExpectedInt 250 | ExpectZRevRange(key string, start, stop int64) *ExpectedStringSlice 251 | ExpectZRevRangeWithScores(key string, start, stop int64) *ExpectedZSlice 252 | ExpectZRevRangeByScore(key string, opt *redis.ZRangeBy) *ExpectedStringSlice 253 | ExpectZRevRangeByLex(key string, opt *redis.ZRangeBy) *ExpectedStringSlice 254 | ExpectZRevRangeByScoreWithScores(key string, opt *redis.ZRangeBy) *ExpectedZSlice 255 | ExpectZRevRank(key, member string) *ExpectedInt 256 | ExpectZScore(key, member string) *ExpectedFloat 257 | ExpectZUnionStore(dest string, store *redis.ZStore) *ExpectedInt 258 | ExpectZRandMember(key string, count int) *ExpectedStringSlice 259 | ExpectZRandMemberWithScores(key string, count int) *ExpectedZSlice 260 | ExpectZUnion(store redis.ZStore) *ExpectedStringSlice 261 | ExpectZUnionWithScores(store redis.ZStore) *ExpectedZSlice 262 | ExpectZDiff(keys ...string) *ExpectedStringSlice 263 | ExpectZDiffWithScores(keys ...string) *ExpectedZSlice 264 | ExpectZDiffStore(destination string, keys ...string) *ExpectedInt 265 | 266 | ExpectPFAdd(key string, els ...interface{}) *ExpectedInt 267 | ExpectPFCount(keys ...string) *ExpectedInt 268 | ExpectPFMerge(dest string, keys ...string) *ExpectedStatus 269 | 270 | ExpectBgRewriteAOF() *ExpectedStatus 271 | ExpectBgSave() *ExpectedStatus 272 | ExpectClientKill(ipPort string) *ExpectedStatus 273 | ExpectClientKillByFilter(keys ...string) *ExpectedInt 274 | ExpectClientList() *ExpectedString 275 | ExpectClientPause(dur time.Duration) *ExpectedBool 276 | ExpectClientUnpause() *ExpectedBool 277 | ExpectClientID() *ExpectedInt 278 | ExpectClientUnblock(id int64) *ExpectedInt 279 | ExpectClientUnblockWithError(id int64) *ExpectedInt 280 | ExpectConfigGet(parameter string) *ExpectedMapStringString 281 | ExpectConfigResetStat() *ExpectedStatus 282 | ExpectConfigSet(parameter, value string) *ExpectedStatus 283 | ExpectConfigRewrite() *ExpectedStatus 284 | ExpectDBSize() *ExpectedInt 285 | ExpectFlushAll() *ExpectedStatus 286 | ExpectFlushAllAsync() *ExpectedStatus 287 | ExpectFlushDB() *ExpectedStatus 288 | ExpectFlushDBAsync() *ExpectedStatus 289 | ExpectInfo(section ...string) *ExpectedString 290 | ExpectLastSave() *ExpectedInt 291 | ExpectSave() *ExpectedStatus 292 | ExpectShutdown() *ExpectedStatus 293 | ExpectShutdownSave() *ExpectedStatus 294 | ExpectShutdownNoSave() *ExpectedStatus 295 | ExpectSlaveOf(host, port string) *ExpectedStatus 296 | ExpectSlowLogGet(num int64) *ExpectedSlowLog 297 | ExpectTime() *ExpectedTime 298 | ExpectDebugObject(key string) *ExpectedString 299 | ExpectReadOnly() *ExpectedStatus 300 | ExpectReadWrite() *ExpectedStatus 301 | ExpectMemoryUsage(key string, samples ...int) *ExpectedInt 302 | 303 | ExpectEval(script string, keys []string, args ...interface{}) *ExpectedCmd 304 | ExpectEvalSha(sha1 string, keys []string, args ...interface{}) *ExpectedCmd 305 | ExpectEvalRO(script string, keys []string, args ...interface{}) *ExpectedCmd 306 | ExpectEvalShaRO(sha1 string, keys []string, args ...interface{}) *ExpectedCmd 307 | ExpectScriptExists(hashes ...string) *ExpectedBoolSlice 308 | ExpectScriptFlush() *ExpectedStatus 309 | ExpectScriptKill() *ExpectedStatus 310 | ExpectScriptLoad(script string) *ExpectedString 311 | 312 | ExpectPublish(channel string, message interface{}) *ExpectedInt 313 | ExpectSPublish(channel string, message interface{}) *ExpectedInt 314 | ExpectPubSubChannels(pattern string) *ExpectedStringSlice 315 | ExpectPubSubNumSub(channels ...string) *ExpectedMapStringInt 316 | ExpectPubSubNumPat() *ExpectedInt 317 | ExpectPubSubShardChannels(pattern string) *ExpectedStringSlice 318 | ExpectPubSubShardNumSub(channels ...string) *ExpectedMapStringInt 319 | 320 | ExpectClusterSlots() *ExpectedClusterSlots 321 | ExpectClusterShards() *ExpectedClusterShards 322 | ExpectClusterLinks() *ExpectedClusterLinks 323 | ExpectClusterNodes() *ExpectedString 324 | ExpectClusterMeet(host, port string) *ExpectedStatus 325 | ExpectClusterForget(nodeID string) *ExpectedStatus 326 | ExpectClusterReplicate(nodeID string) *ExpectedStatus 327 | ExpectClusterResetSoft() *ExpectedStatus 328 | ExpectClusterResetHard() *ExpectedStatus 329 | ExpectClusterInfo() *ExpectedString 330 | ExpectClusterKeySlot(key string) *ExpectedInt 331 | ExpectClusterGetKeysInSlot(slot int, count int) *ExpectedStringSlice 332 | ExpectClusterCountFailureReports(nodeID string) *ExpectedInt 333 | ExpectClusterCountKeysInSlot(slot int) *ExpectedInt 334 | ExpectClusterDelSlots(slots ...int) *ExpectedStatus 335 | ExpectClusterDelSlotsRange(min, max int) *ExpectedStatus 336 | ExpectClusterSaveConfig() *ExpectedStatus 337 | ExpectClusterSlaves(nodeID string) *ExpectedStringSlice 338 | ExpectClusterFailover() *ExpectedStatus 339 | ExpectClusterAddSlots(slots ...int) *ExpectedStatus 340 | ExpectClusterAddSlotsRange(min, max int) *ExpectedStatus 341 | 342 | ExpectGeoAdd(key string, geoLocation ...*redis.GeoLocation) *ExpectedInt 343 | ExpectGeoPos(key string, members ...string) *ExpectedGeoPos 344 | ExpectGeoRadius(key string, longitude, latitude float64, query *redis.GeoRadiusQuery) *ExpectedGeoLocation 345 | ExpectGeoRadiusStore(key string, longitude, latitude float64, query *redis.GeoRadiusQuery) *ExpectedInt 346 | ExpectGeoRadiusByMember(key, member string, query *redis.GeoRadiusQuery) *ExpectedGeoLocation 347 | ExpectGeoRadiusByMemberStore(key, member string, query *redis.GeoRadiusQuery) *ExpectedInt 348 | ExpectGeoSearch(key string, q *redis.GeoSearchQuery) *ExpectedStringSlice 349 | ExpectGeoSearchLocation(key string, q *redis.GeoSearchLocationQuery) *ExpectedGeoSearchLocation 350 | ExpectGeoSearchStore(key, store string, q *redis.GeoSearchStoreQuery) *ExpectedInt 351 | ExpectGeoDist(key string, member1, member2, unit string) *ExpectedFloat 352 | ExpectGeoHash(key string, members ...string) *ExpectedStringSlice 353 | 354 | ExpectFunctionLoad(code string) *ExpectedString 355 | ExpectFunctionLoadReplace(code string) *ExpectedString 356 | ExpectFunctionDelete(libName string) *ExpectedString 357 | ExpectFunctionFlush() *ExpectedString 358 | ExpectFunctionFlushAsync() *ExpectedString 359 | ExpectFunctionList(q redis.FunctionListQuery) *ExpectedFunctionList 360 | ExpectFunctionKill() *ExpectedString 361 | ExpectFunctionDump() *ExpectedString 362 | ExpectFunctionRestore(libDump string) *ExpectedString 363 | ExpectFCall(function string, keys []string, args ...interface{}) *ExpectedCmd 364 | ExpectFCallRo(function string, keys []string, args ...interface{}) *ExpectedCmd 365 | 366 | ExpectACLDryRun(username string, command ...interface{}) *ExpectedString 367 | 368 | ExpectTSAdd(key string, timestamp interface{}, value float64) *ExpectedInt 369 | ExpectTSAddWithArgs(key string, timestamp interface{}, value float64, options *redis.TSOptions) *ExpectedInt 370 | ExpectTSCreate(key string) *ExpectedStatus 371 | ExpectTSCreateWithArgs(key string, options *redis.TSOptions) *ExpectedStatus 372 | ExpectTSAlter(key string, options *redis.TSAlterOptions) *ExpectedStatus 373 | ExpectTSCreateRule(sourceKey string, destKey string, aggregator redis.Aggregator, bucketDuration int) *ExpectedStatus 374 | ExpectTSCreateRuleWithArgs(sourceKey string, destKey string, aggregator redis.Aggregator, bucketDuration int, options *redis.TSCreateRuleOptions) *ExpectedStatus 375 | ExpectTSIncrBy(Key string, timestamp float64) *ExpectedInt 376 | ExpectTSIncrByWithArgs(key string, timestamp float64, options *redis.TSIncrDecrOptions) *ExpectedInt 377 | ExpectTSDecrBy(Key string, timestamp float64) *ExpectedInt 378 | ExpectTSDecrByWithArgs(key string, timestamp float64, options *redis.TSIncrDecrOptions) *ExpectedInt 379 | ExpectTSDel(Key string, fromTimestamp int, toTimestamp int) *ExpectedInt 380 | ExpectTSDeleteRule(sourceKey string, destKey string) *ExpectedStatus 381 | ExpectTSGet(key string) *ExpectedTSTimestampValue 382 | ExpectTSGetWithArgs(key string, options *redis.TSGetOptions) *ExpectedTSTimestampValue 383 | ExpectTSInfo(key string) *ExpectedMapStringInterface 384 | ExpectTSInfoWithArgs(key string, options *redis.TSInfoOptions) *ExpectedMapStringInterface 385 | ExpectTSMAdd(ktvSlices [][]interface{}) *ExpectedIntSlice 386 | ExpectTSQueryIndex(filterExpr []string) *ExpectedStringSlice 387 | ExpectTSRevRange(key string, fromTimestamp int, toTimestamp int) *ExpectedTSTimestampValueSlice 388 | ExpectTSRevRangeWithArgs(key string, fromTimestamp int, toTimestamp int, options *redis.TSRevRangeOptions) *ExpectedTSTimestampValueSlice 389 | ExpectTSRange(key string, fromTimestamp int, toTimestamp int) *ExpectedTSTimestampValueSlice 390 | ExpectTSRangeWithArgs(key string, fromTimestamp int, toTimestamp int, options *redis.TSRangeOptions) *ExpectedTSTimestampValueSlice 391 | ExpectTSMRange(fromTimestamp int, toTimestamp int, filterExpr []string) *ExpectedMapStringSliceInterface 392 | ExpectTSMRangeWithArgs(fromTimestamp int, toTimestamp int, filterExpr []string, options *redis.TSMRangeOptions) *ExpectedMapStringSliceInterface 393 | ExpectTSMRevRange(fromTimestamp int, toTimestamp int, filterExpr []string) *ExpectedMapStringSliceInterface 394 | ExpectTSMRevRangeWithArgs(fromTimestamp int, toTimestamp int, filterExpr []string, options *redis.TSMRevRangeOptions) *ExpectedMapStringSliceInterface 395 | ExpectTSMGet(filters []string) *ExpectedMapStringSliceInterface 396 | ExpectTSMGetWithArgs(filters []string, options *redis.TSMGetOptions) *ExpectedMapStringSliceInterface 397 | } 398 | 399 | type pipelineMock interface { 400 | ExpectTxPipeline() 401 | ExpectTxPipelineExec() *ExpectedSlice 402 | } 403 | 404 | type watchMock interface { 405 | ExpectWatch(keys ...string) *ExpectedError 406 | } 407 | 408 | type ClientMock interface { 409 | baseMock 410 | pipelineMock 411 | watchMock 412 | } 413 | 414 | type ClusterClientMock interface { 415 | baseMock 416 | } 417 | 418 | func inflow(cmd redis.Cmder, key string, val interface{}) { 419 | v := reflect.ValueOf(cmd).Elem().FieldByName(key) 420 | if !v.IsValid() { 421 | panic(fmt.Sprintf("cmd did not find key '%s'", key)) 422 | } 423 | v = reflect.NewAt(v.Type(), unsafe.Pointer(v.UnsafeAddr())).Elem() 424 | 425 | setVal := reflect.ValueOf(val) 426 | if v.Kind() != reflect.Interface && setVal.Kind() != v.Kind() { 427 | panic(fmt.Sprintf("expected kind %v, got kind: %v", v.Kind(), setVal.Kind())) 428 | } 429 | v.Set(setVal) 430 | } 431 | 432 | type expectation interface { 433 | regexp() bool 434 | setRegexpMatch() 435 | custom() CustomMatch 436 | setCustomMatch(fn CustomMatch) 437 | usable() bool 438 | trigger() 439 | 440 | name() string 441 | args() []interface{} 442 | 443 | error() error 444 | SetErr(err error) 445 | 446 | RedisNil() 447 | isRedisNil() bool 448 | 449 | inflow(c redis.Cmder) 450 | 451 | isSetVal() bool 452 | 453 | lock() 454 | unlock() 455 | } 456 | 457 | type CustomMatch func(expected, actual []interface{}) error 458 | 459 | type expectedBase struct { 460 | cmd redis.Cmder 461 | err error 462 | redisNil bool 463 | triggered bool 464 | setVal bool 465 | regexpMatch bool 466 | customMatch CustomMatch 467 | 468 | rw sync.RWMutex 469 | } 470 | 471 | func (base *expectedBase) lock() { 472 | base.rw.Lock() 473 | } 474 | 475 | func (base *expectedBase) unlock() { 476 | base.rw.Unlock() 477 | } 478 | 479 | func (base *expectedBase) regexp() bool { 480 | return base.regexpMatch 481 | } 482 | 483 | func (base *expectedBase) setRegexpMatch() { 484 | base.regexpMatch = true 485 | } 486 | 487 | func (base *expectedBase) custom() CustomMatch { 488 | return base.customMatch 489 | } 490 | 491 | func (base *expectedBase) setCustomMatch(fn CustomMatch) { 492 | base.customMatch = fn 493 | } 494 | 495 | func (base *expectedBase) usable() bool { 496 | return !base.triggered 497 | } 498 | 499 | func (base *expectedBase) trigger() { 500 | base.triggered = true 501 | } 502 | 503 | func (base *expectedBase) name() string { 504 | return base.cmd.Name() 505 | } 506 | 507 | func (base *expectedBase) args() []interface{} { 508 | return base.cmd.Args() 509 | } 510 | 511 | func (base *expectedBase) SetErr(err error) { 512 | base.err = err 513 | } 514 | 515 | func (base *expectedBase) error() error { 516 | return base.err 517 | } 518 | 519 | func (base *expectedBase) RedisNil() { 520 | base.redisNil = true 521 | } 522 | 523 | func (base *expectedBase) isRedisNil() bool { 524 | return base.redisNil 525 | } 526 | 527 | func (base *expectedBase) isSetVal() bool { 528 | return base.setVal 529 | } 530 | 531 | //--------------------------------- 532 | 533 | type ExpectedCommandsInfo struct { 534 | expectedBase 535 | 536 | val map[string]*redis.CommandInfo 537 | } 538 | 539 | func (cmd *ExpectedCommandsInfo) SetVal(val []*redis.CommandInfo) { 540 | cmd.setVal = true 541 | cmd.val = make(map[string]*redis.CommandInfo) 542 | for _, v := range val { 543 | cmd.val[v.Name] = v 544 | } 545 | } 546 | 547 | func (cmd *ExpectedCommandsInfo) inflow(c redis.Cmder) { 548 | inflow(c, "val", cmd.val) 549 | } 550 | 551 | // ------------------------------------------------------------ 552 | 553 | type ExpectedString struct { 554 | expectedBase 555 | 556 | val string 557 | } 558 | 559 | func (cmd *ExpectedString) SetVal(val string) { 560 | cmd.setVal = true 561 | cmd.val = val 562 | } 563 | 564 | func (cmd *ExpectedString) inflow(c redis.Cmder) { 565 | inflow(c, "val", cmd.val) 566 | } 567 | 568 | // ------------------------------------------------------------ 569 | 570 | type ExpectedStatus struct { 571 | expectedBase 572 | 573 | val string 574 | } 575 | 576 | func (cmd *ExpectedStatus) SetVal(val string) { 577 | cmd.setVal = true 578 | cmd.val = val 579 | } 580 | 581 | func (cmd *ExpectedStatus) inflow(c redis.Cmder) { 582 | inflow(c, "val", cmd.val) 583 | } 584 | 585 | // ------------------------------------------------------------ 586 | 587 | type ExpectedInt struct { 588 | expectedBase 589 | 590 | val int64 591 | } 592 | 593 | func (cmd *ExpectedInt) SetVal(val int64) { 594 | cmd.setVal = true 595 | cmd.val = val 596 | } 597 | 598 | func (cmd *ExpectedInt) inflow(c redis.Cmder) { 599 | inflow(c, "val", cmd.val) 600 | } 601 | 602 | // ------------------------------------------------------------ 603 | 604 | type ExpectedBool struct { 605 | expectedBase 606 | 607 | val bool 608 | } 609 | 610 | func (cmd *ExpectedBool) SetVal(val bool) { 611 | cmd.setVal = true 612 | cmd.val = val 613 | } 614 | 615 | func (cmd *ExpectedBool) inflow(c redis.Cmder) { 616 | inflow(c, "val", cmd.val) 617 | } 618 | 619 | // ------------------------------------------------------------ 620 | 621 | type ExpectedStringSlice struct { 622 | expectedBase 623 | 624 | val []string 625 | } 626 | 627 | func (cmd *ExpectedStringSlice) SetVal(val []string) { 628 | cmd.setVal = true 629 | cmd.val = make([]string, len(val)) 630 | copy(cmd.val, val) 631 | } 632 | 633 | func (cmd *ExpectedStringSlice) inflow(c redis.Cmder) { 634 | inflow(c, "val", cmd.val) 635 | } 636 | 637 | // ------------------------------------------------------------ 638 | 639 | type ExpectedKeyValueSlice struct { 640 | expectedBase 641 | 642 | val []redis.KeyValue 643 | } 644 | 645 | func (cmd *ExpectedKeyValueSlice) SetVal(val []redis.KeyValue) { 646 | cmd.setVal = true 647 | cmd.val = make([]redis.KeyValue, len(val)) 648 | copy(cmd.val, val) 649 | } 650 | 651 | func (cmd *ExpectedKeyValueSlice) inflow(c redis.Cmder) { 652 | inflow(c, "val", cmd.val) 653 | } 654 | 655 | // ------------------------------------------------------------ 656 | 657 | type ExpectedDuration struct { 658 | expectedBase 659 | 660 | val time.Duration 661 | // precision time.Duration 662 | } 663 | 664 | func (cmd *ExpectedDuration) SetVal(val time.Duration) { 665 | cmd.setVal = true 666 | cmd.val = val 667 | } 668 | 669 | func (cmd *ExpectedDuration) inflow(c redis.Cmder) { 670 | inflow(c, "val", cmd.val) 671 | } 672 | 673 | // ------------------------------------------------------------ 674 | 675 | type ExpectedSlice struct { 676 | expectedBase 677 | 678 | val []interface{} 679 | } 680 | 681 | func (cmd *ExpectedSlice) SetVal(val []interface{}) { 682 | cmd.setVal = true 683 | cmd.val = make([]interface{}, len(val)) 684 | copy(cmd.val, val) 685 | } 686 | 687 | func (cmd *ExpectedSlice) inflow(c redis.Cmder) { 688 | inflow(c, "val", cmd.val) 689 | } 690 | 691 | // ------------------------------------------------------------ 692 | 693 | type ExpectedFloat struct { 694 | expectedBase 695 | 696 | val float64 697 | } 698 | 699 | func (cmd *ExpectedFloat) SetVal(val float64) { 700 | cmd.setVal = true 701 | cmd.val = val 702 | } 703 | 704 | func (cmd *ExpectedFloat) inflow(c redis.Cmder) { 705 | inflow(c, "val", cmd.val) 706 | } 707 | 708 | // ------------------------------------------------------------ 709 | 710 | type ExpectedFloatSlice struct { 711 | expectedBase 712 | 713 | val []float64 714 | } 715 | 716 | func (cmd *ExpectedFloatSlice) SetVal(val []float64) { 717 | cmd.setVal = true 718 | cmd.val = make([]float64, len(val)) 719 | copy(cmd.val, val) 720 | } 721 | 722 | func (cmd *ExpectedFloatSlice) inflow(c redis.Cmder) { 723 | inflow(c, "val", cmd.val) 724 | } 725 | 726 | // ------------------------------------------------------------ 727 | 728 | type ExpectedIntSlice struct { 729 | expectedBase 730 | 731 | val []int64 732 | } 733 | 734 | func (cmd *ExpectedIntSlice) SetVal(val []int64) { 735 | cmd.setVal = true 736 | cmd.val = make([]int64, len(val)) 737 | copy(cmd.val, val) 738 | } 739 | 740 | func (cmd *ExpectedIntSlice) inflow(c redis.Cmder) { 741 | inflow(c, "val", cmd.val) 742 | } 743 | 744 | // ------------------------------------------------------------ 745 | 746 | type ExpectedScan struct { 747 | expectedBase 748 | 749 | page []string 750 | cursor uint64 751 | } 752 | 753 | func (cmd *ExpectedScan) SetVal(page []string, cursor uint64) { 754 | cmd.setVal = true 755 | cmd.page = make([]string, len(page)) 756 | copy(cmd.page, page) 757 | cmd.cursor = cursor 758 | } 759 | 760 | func (cmd *ExpectedScan) inflow(c redis.Cmder) { 761 | inflow(c, "page", cmd.page) 762 | inflow(c, "cursor", cmd.cursor) 763 | } 764 | 765 | // ------------------------------------------------------------ 766 | 767 | type ExpectedMapStringString struct { 768 | expectedBase 769 | 770 | val map[string]string 771 | } 772 | 773 | func (cmd *ExpectedMapStringString) SetVal(val map[string]string) { 774 | cmd.setVal = true 775 | cmd.val = make(map[string]string) 776 | for k, v := range val { 777 | cmd.val[k] = v 778 | } 779 | } 780 | 781 | func (cmd *ExpectedMapStringString) inflow(c redis.Cmder) { 782 | inflow(c, "val", cmd.val) 783 | } 784 | 785 | // ------------------------------------------------------------ 786 | 787 | type ExpectedStringStructMap struct { 788 | expectedBase 789 | 790 | val map[string]struct{} 791 | } 792 | 793 | func (cmd *ExpectedStringStructMap) SetVal(val []string) { 794 | cmd.setVal = true 795 | cmd.val = make(map[string]struct{}) 796 | for _, v := range val { 797 | cmd.val[v] = struct{}{} 798 | } 799 | } 800 | 801 | func (cmd *ExpectedStringStructMap) inflow(c redis.Cmder) { 802 | inflow(c, "val", cmd.val) 803 | } 804 | 805 | // ------------------------------------------------------------ 806 | 807 | type ExpectedXMessageSlice struct { 808 | expectedBase 809 | 810 | val []redis.XMessage 811 | } 812 | 813 | func (cmd *ExpectedXMessageSlice) SetVal(val []redis.XMessage) { 814 | cmd.setVal = true 815 | cmd.val = make([]redis.XMessage, len(val)) 816 | copy(cmd.val, val) 817 | } 818 | 819 | func (cmd *ExpectedXMessageSlice) inflow(c redis.Cmder) { 820 | inflow(c, "val", cmd.val) 821 | } 822 | 823 | // ------------------------------------------------------------ 824 | 825 | type ExpectedXStreamSlice struct { 826 | expectedBase 827 | 828 | val []redis.XStream 829 | } 830 | 831 | func (cmd *ExpectedXStreamSlice) SetVal(val []redis.XStream) { 832 | cmd.setVal = true 833 | cmd.val = make([]redis.XStream, len(val)) 834 | copy(cmd.val, val) 835 | } 836 | 837 | func (cmd *ExpectedXStreamSlice) inflow(c redis.Cmder) { 838 | inflow(c, "val", cmd.val) 839 | } 840 | 841 | // ------------------------------------------------------------ 842 | 843 | type ExpectedXPending struct { 844 | expectedBase 845 | 846 | val *redis.XPending 847 | } 848 | 849 | func (cmd *ExpectedXPending) SetVal(val *redis.XPending) { 850 | cmd.setVal = true 851 | v := *val 852 | cmd.val = &v 853 | } 854 | 855 | func (cmd *ExpectedXPending) inflow(c redis.Cmder) { 856 | inflow(c, "val", cmd.val) 857 | } 858 | 859 | // ------------------------------------------------------------ 860 | 861 | type ExpectedXPendingExt struct { 862 | expectedBase 863 | 864 | val []redis.XPendingExt 865 | } 866 | 867 | func (cmd *ExpectedXPendingExt) SetVal(val []redis.XPendingExt) { 868 | cmd.setVal = true 869 | cmd.val = make([]redis.XPendingExt, len(val)) 870 | copy(cmd.val, val) 871 | } 872 | 873 | func (cmd *ExpectedXPendingExt) inflow(c redis.Cmder) { 874 | inflow(c, "val", cmd.val) 875 | } 876 | 877 | // ---------------------------------------------------------------------- 878 | 879 | type ExpectedXAutoClaim struct { 880 | expectedBase 881 | 882 | start string 883 | val []redis.XMessage 884 | } 885 | 886 | func (cmd *ExpectedXAutoClaim) SetVal(val []redis.XMessage, start string) { 887 | cmd.setVal = true 888 | cmd.start = start 889 | cmd.val = make([]redis.XMessage, len(val)) 890 | copy(cmd.val, val) 891 | } 892 | 893 | func (cmd *ExpectedXAutoClaim) inflow(c redis.Cmder) { 894 | inflow(c, "val", cmd.val) 895 | inflow(c, "start", cmd.start) 896 | } 897 | 898 | // ------------------------------------------------------------ 899 | 900 | type ExpectedXAutoClaimJustID struct { 901 | expectedBase 902 | 903 | start string 904 | val []string 905 | } 906 | 907 | func (cmd *ExpectedXAutoClaimJustID) SetVal(val []string, start string) { 908 | cmd.setVal = true 909 | cmd.start = start 910 | cmd.val = make([]string, len(val)) 911 | copy(cmd.val, val) 912 | } 913 | 914 | func (cmd *ExpectedXAutoClaimJustID) inflow(c redis.Cmder) { 915 | inflow(c, "val", cmd.val) 916 | inflow(c, "start", cmd.start) 917 | } 918 | 919 | // ------------------------------------------------------------ 920 | 921 | type ExpectedXInfoGroups struct { 922 | expectedBase 923 | 924 | val []redis.XInfoGroup 925 | } 926 | 927 | func (cmd *ExpectedXInfoGroups) SetVal(val []redis.XInfoGroup) { 928 | cmd.setVal = true 929 | cmd.val = make([]redis.XInfoGroup, len(val)) 930 | copy(cmd.val, val) 931 | } 932 | 933 | func (cmd *ExpectedXInfoGroups) inflow(c redis.Cmder) { 934 | inflow(c, "val", cmd.val) 935 | } 936 | 937 | // ------------------------------------------------------------ 938 | 939 | type ExpectedXInfoStream struct { 940 | expectedBase 941 | 942 | val *redis.XInfoStream 943 | } 944 | 945 | func (cmd *ExpectedXInfoStream) SetVal(val *redis.XInfoStream) { 946 | cmd.setVal = true 947 | v := *val 948 | cmd.val = &v 949 | } 950 | 951 | func (cmd *ExpectedXInfoStream) inflow(c redis.Cmder) { 952 | inflow(c, "val", cmd.val) 953 | } 954 | 955 | // ------------------------------------------------------------ 956 | 957 | type ExpectedXInfoConsumers struct { 958 | expectedBase 959 | 960 | val []redis.XInfoConsumer 961 | } 962 | 963 | func (cmd *ExpectedXInfoConsumers) SetVal(val []redis.XInfoConsumer) { 964 | cmd.setVal = true 965 | cmd.val = make([]redis.XInfoConsumer, len(val)) 966 | copy(cmd.val, val) 967 | } 968 | 969 | func (cmd *ExpectedXInfoConsumers) inflow(c redis.Cmder) { 970 | inflow(c, "val", cmd.val) 971 | } 972 | 973 | // ------------------------------------------------------------ 974 | 975 | type ExpectedXInfoStreamFull struct { 976 | expectedBase 977 | 978 | val *redis.XInfoStreamFull 979 | } 980 | 981 | func (cmd *ExpectedXInfoStreamFull) SetVal(val *redis.XInfoStreamFull) { 982 | cmd.setVal = true 983 | v := *val 984 | cmd.val = &v 985 | } 986 | 987 | func (cmd *ExpectedXInfoStreamFull) inflow(c redis.Cmder) { 988 | inflow(c, "val", cmd.val) 989 | } 990 | 991 | // ------------------------------------------------------------ 992 | 993 | type ExpectedZWithKey struct { 994 | expectedBase 995 | 996 | val *redis.ZWithKey 997 | } 998 | 999 | func (cmd *ExpectedZWithKey) SetVal(val *redis.ZWithKey) { 1000 | cmd.setVal = true 1001 | v := *val 1002 | cmd.val = &v 1003 | } 1004 | 1005 | func (cmd *ExpectedZWithKey) inflow(c redis.Cmder) { 1006 | inflow(c, "val", cmd.val) 1007 | } 1008 | 1009 | // ------------------------------------------------------------ 1010 | 1011 | type ExpectedZSlice struct { 1012 | expectedBase 1013 | 1014 | val []redis.Z 1015 | } 1016 | 1017 | func (cmd *ExpectedZSlice) SetVal(val []redis.Z) { 1018 | cmd.setVal = true 1019 | cmd.val = make([]redis.Z, len(val)) 1020 | copy(cmd.val, val) 1021 | } 1022 | 1023 | func (cmd *ExpectedZSlice) inflow(c redis.Cmder) { 1024 | inflow(c, "val", cmd.val) 1025 | } 1026 | 1027 | // ------------------------------------------------------------ 1028 | 1029 | type ExpectedTime struct { 1030 | expectedBase 1031 | 1032 | val time.Time 1033 | } 1034 | 1035 | func (cmd *ExpectedTime) SetVal(val time.Time) { 1036 | cmd.setVal = true 1037 | cmd.val = val 1038 | } 1039 | 1040 | func (cmd *ExpectedTime) inflow(c redis.Cmder) { 1041 | inflow(c, "val", cmd.val) 1042 | } 1043 | 1044 | // ------------------------------------------------------------ 1045 | 1046 | type ExpectedCmd struct { 1047 | expectedBase 1048 | 1049 | val interface{} 1050 | } 1051 | 1052 | func (cmd *ExpectedCmd) SetVal(val interface{}) { 1053 | cmd.setVal = true 1054 | cmd.val = val 1055 | } 1056 | 1057 | func (cmd *ExpectedCmd) inflow(c redis.Cmder) { 1058 | inflow(c, "val", cmd.val) 1059 | } 1060 | 1061 | // ------------------------------------------------------------ 1062 | 1063 | type ExpectedBoolSlice struct { 1064 | expectedBase 1065 | 1066 | val []bool 1067 | } 1068 | 1069 | func (cmd *ExpectedBoolSlice) SetVal(val []bool) { 1070 | cmd.setVal = true 1071 | cmd.val = make([]bool, len(val)) 1072 | copy(cmd.val, val) 1073 | } 1074 | 1075 | func (cmd *ExpectedBoolSlice) inflow(c redis.Cmder) { 1076 | inflow(c, "val", cmd.val) 1077 | } 1078 | 1079 | // ------------------------------------------------------------ 1080 | 1081 | type ExpectedClusterSlots struct { 1082 | expectedBase 1083 | 1084 | val []redis.ClusterSlot 1085 | } 1086 | 1087 | func (cmd *ExpectedClusterSlots) SetVal(val []redis.ClusterSlot) { 1088 | cmd.setVal = true 1089 | cmd.val = make([]redis.ClusterSlot, len(val)) 1090 | copy(cmd.val, val) 1091 | } 1092 | 1093 | func (cmd *ExpectedClusterSlots) inflow(c redis.Cmder) { 1094 | inflow(c, "val", cmd.val) 1095 | } 1096 | 1097 | // ------------------------------------------------------------ 1098 | 1099 | type ExpectedClusterLinks struct { 1100 | expectedBase 1101 | 1102 | val []redis.ClusterLink 1103 | } 1104 | 1105 | func (cmd *ExpectedClusterLinks) SetVal(val []redis.ClusterLink) { 1106 | cmd.setVal = true 1107 | cmd.val = make([]redis.ClusterLink, len(val)) 1108 | copy(cmd.val, val) 1109 | } 1110 | 1111 | func (cmd *ExpectedClusterLinks) inflow(c redis.Cmder) { 1112 | inflow(c, "val", cmd.val) 1113 | } 1114 | 1115 | // ------------------------------------------------------------ 1116 | 1117 | type ExpectedMapStringInt struct { 1118 | expectedBase 1119 | 1120 | val map[string]int64 1121 | } 1122 | 1123 | func (cmd *ExpectedMapStringInt) SetVal(val map[string]int64) { 1124 | cmd.setVal = true 1125 | cmd.val = make(map[string]int64) 1126 | for k, v := range val { 1127 | cmd.val[k] = v 1128 | } 1129 | } 1130 | 1131 | func (cmd *ExpectedMapStringInt) inflow(c redis.Cmder) { 1132 | inflow(c, "val", cmd.val) 1133 | } 1134 | 1135 | // ------------------------------------------------------------ 1136 | 1137 | type ExpectedGeoPos struct { 1138 | expectedBase 1139 | 1140 | val []*redis.GeoPos 1141 | } 1142 | 1143 | func (cmd *ExpectedGeoPos) SetVal(val []*redis.GeoPos) { 1144 | cmd.setVal = true 1145 | cmd.val = make([]*redis.GeoPos, len(val)) 1146 | copy(cmd.val, val) 1147 | } 1148 | 1149 | func (cmd *ExpectedGeoPos) inflow(c redis.Cmder) { 1150 | inflow(c, "val", cmd.val) 1151 | } 1152 | 1153 | // ------------------------------------------------------------ 1154 | 1155 | type ExpectedGeoLocation struct { 1156 | expectedBase 1157 | 1158 | locations []redis.GeoLocation 1159 | } 1160 | 1161 | func (cmd *ExpectedGeoLocation) SetVal(val []redis.GeoLocation) { 1162 | cmd.setVal = true 1163 | cmd.locations = make([]redis.GeoLocation, len(val)) 1164 | copy(cmd.locations, val) 1165 | } 1166 | 1167 | func (cmd *ExpectedGeoLocation) inflow(c redis.Cmder) { 1168 | inflow(c, "locations", cmd.locations) 1169 | } 1170 | 1171 | // ------------------------------------------------------------ 1172 | 1173 | type ExpectedGeoSearchLocation struct { 1174 | expectedBase 1175 | 1176 | val []redis.GeoLocation 1177 | } 1178 | 1179 | func (cmd *ExpectedGeoSearchLocation) SetVal(val []redis.GeoLocation) { 1180 | cmd.setVal = true 1181 | cmd.val = make([]redis.GeoLocation, len(val)) 1182 | copy(cmd.val, val) 1183 | } 1184 | 1185 | func (cmd *ExpectedGeoSearchLocation) inflow(c redis.Cmder) { 1186 | inflow(c, "val", cmd.val) 1187 | } 1188 | 1189 | // ------------------------------------------------------------ 1190 | 1191 | type ExpectedKeyValues struct { 1192 | expectedBase 1193 | 1194 | key string 1195 | val []string 1196 | } 1197 | 1198 | func (cmd *ExpectedKeyValues) SetVal(key string, val []string) { 1199 | cmd.setVal = true 1200 | cmd.key = key 1201 | cmd.val = make([]string, len(val)) 1202 | copy(cmd.val, val) 1203 | } 1204 | 1205 | func (cmd *ExpectedKeyValues) inflow(c redis.Cmder) { 1206 | inflow(c, "key", cmd.key) 1207 | inflow(c, "val", cmd.val) 1208 | } 1209 | 1210 | // ------------------------------------------------------------ 1211 | 1212 | type ExpectedZSliceWithKey struct { 1213 | expectedBase 1214 | 1215 | key string 1216 | val []redis.Z 1217 | } 1218 | 1219 | func (cmd *ExpectedZSliceWithKey) SetVal(key string, val []redis.Z) { 1220 | cmd.setVal = true 1221 | cmd.key = key 1222 | cmd.val = make([]redis.Z, len(val)) 1223 | copy(cmd.val, val) 1224 | } 1225 | 1226 | func (cmd *ExpectedZSliceWithKey) inflow(c redis.Cmder) { 1227 | inflow(c, "key", cmd.key) 1228 | inflow(c, "val", cmd.val) 1229 | } 1230 | 1231 | // ------------------------------------------------------------ 1232 | 1233 | type ExpectedSlowLog struct { 1234 | expectedBase 1235 | 1236 | val []redis.SlowLog 1237 | } 1238 | 1239 | func (cmd *ExpectedSlowLog) SetVal(val []redis.SlowLog) { 1240 | cmd.setVal = true 1241 | cmd.val = make([]redis.SlowLog, len(val)) 1242 | copy(cmd.val, val) 1243 | } 1244 | 1245 | func (cmd *ExpectedSlowLog) inflow(c redis.Cmder) { 1246 | inflow(c, "val", cmd.val) 1247 | } 1248 | 1249 | // ------------------------------------------------------------ 1250 | 1251 | type ExpectedFunctionList struct { 1252 | expectedBase 1253 | 1254 | val []redis.Library 1255 | } 1256 | 1257 | func (cmd *ExpectedFunctionList) SetVal(val []redis.Library) { 1258 | cmd.setVal = true 1259 | cmd.val = make([]redis.Library, len(val)) 1260 | copy(cmd.val, val) 1261 | } 1262 | 1263 | func (cmd *ExpectedFunctionList) inflow(c redis.Cmder) { 1264 | inflow(c, "val", cmd.val) 1265 | } 1266 | 1267 | // ------------------------------------------------------------ 1268 | 1269 | type ExpectedLCS struct { 1270 | expectedBase 1271 | 1272 | val *redis.LCSMatch 1273 | } 1274 | 1275 | func (cmd *ExpectedLCS) SetVal(val *redis.LCSMatch) { 1276 | cmd.setVal = true 1277 | v := *val 1278 | cmd.val = &v 1279 | } 1280 | 1281 | func (cmd *ExpectedLCS) inflow(c redis.Cmder) { 1282 | inflow(c, "val", cmd.val) 1283 | } 1284 | 1285 | // ------------------------------------------------------------ 1286 | 1287 | type ExpectedKeyFlags struct { 1288 | expectedBase 1289 | 1290 | val []redis.KeyFlags 1291 | } 1292 | 1293 | func (cmd *ExpectedKeyFlags) SetVal(val []redis.KeyFlags) { 1294 | cmd.setVal = true 1295 | cmd.val = make([]redis.KeyFlags, len(val)) 1296 | copy(cmd.val, val) 1297 | } 1298 | 1299 | func (cmd *ExpectedKeyFlags) inflow(c redis.Cmder) { 1300 | inflow(c, "val", cmd.val) 1301 | } 1302 | 1303 | // ------------------------------------------------------------ 1304 | 1305 | type ExpectedClusterShards struct { 1306 | expectedBase 1307 | 1308 | val []redis.ClusterShard 1309 | } 1310 | 1311 | func (cmd *ExpectedClusterShards) SetVal(val []redis.ClusterShard) { 1312 | cmd.setVal = true 1313 | cmd.val = make([]redis.ClusterShard, len(val)) 1314 | copy(cmd.val, val) 1315 | } 1316 | 1317 | func (cmd *ExpectedClusterShards) inflow(c redis.Cmder) { 1318 | inflow(c, "val", cmd.val) 1319 | } 1320 | 1321 | // ------------------------------------------------------------ 1322 | 1323 | type ExpectedTSTimestampValue struct { 1324 | expectedBase 1325 | 1326 | val redis.TSTimestampValue 1327 | } 1328 | 1329 | func (cmd *ExpectedTSTimestampValue) SetVal(val redis.TSTimestampValue) { 1330 | cmd.setVal = true 1331 | cmd.val = val 1332 | } 1333 | 1334 | func (cmd *ExpectedTSTimestampValue) inflow(c redis.Cmder) { 1335 | inflow(c, "val", cmd.val) 1336 | } 1337 | 1338 | // ------------------------------------------------------------ 1339 | 1340 | type ExpectedMapStringInterface struct { 1341 | expectedBase 1342 | 1343 | val map[string]interface{} 1344 | } 1345 | 1346 | func (cmd *ExpectedMapStringInterface) SetVal(val map[string]interface{}) { 1347 | cmd.setVal = true 1348 | cmd.val = make(map[string]interface{}) 1349 | for k, v := range val { 1350 | cmd.val[k] = v 1351 | } 1352 | } 1353 | 1354 | func (cmd *ExpectedMapStringInterface) inflow(c redis.Cmder) { 1355 | inflow(c, "val", cmd.val) 1356 | } 1357 | 1358 | // ------------------------------------------------------------ 1359 | 1360 | type ExpectedTSTimestampValueSlice struct { 1361 | expectedBase 1362 | 1363 | val []redis.TSTimestampValue 1364 | } 1365 | 1366 | func (cmd *ExpectedTSTimestampValueSlice) SetVal(val []redis.TSTimestampValue) { 1367 | cmd.setVal = true 1368 | cmd.val = make([]redis.TSTimestampValue, len(val)) 1369 | copy(cmd.val, val) 1370 | } 1371 | 1372 | func (cmd *ExpectedTSTimestampValueSlice) inflow(c redis.Cmder) { 1373 | inflow(c, "val", cmd.val) 1374 | } 1375 | 1376 | // ------------------------------------------------------------ 1377 | 1378 | type ExpectedMapStringSliceInterface struct { 1379 | expectedBase 1380 | 1381 | val map[string][]interface{} 1382 | } 1383 | 1384 | func (cmd *ExpectedMapStringSliceInterface) SetVal(val map[string][]interface{}) { 1385 | cmd.setVal = true 1386 | cmd.val = make(map[string][]interface{}) 1387 | for k, v := range val { 1388 | cmd.val[k] = make([]interface{}, len(v)) 1389 | copy(cmd.val[k], v) 1390 | } 1391 | } 1392 | 1393 | func (cmd *ExpectedMapStringSliceInterface) inflow(c redis.Cmder) { 1394 | inflow(c, "val", cmd.val) 1395 | } 1396 | 1397 | // ------------------------------------------------------------ 1398 | 1399 | type ExpectedError struct { 1400 | expectedBase 1401 | } 1402 | 1403 | func (cmd *ExpectedError) inflow(c redis.Cmder) {} 1404 | -------------------------------------------------------------------------------- /go.mod: -------------------------------------------------------------------------------- 1 | module github.com/go-redis/redismock/v9 2 | 3 | go 1.18 4 | 5 | require ( 6 | github.com/onsi/ginkgo v1.16.5 7 | github.com/onsi/gomega v1.25.0 8 | github.com/redis/go-redis/v9 v9.2.0 9 | ) 10 | 11 | require ( 12 | github.com/cespare/xxhash/v2 v2.2.0 // indirect 13 | github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f // indirect 14 | github.com/fsnotify/fsnotify v1.4.9 // indirect 15 | github.com/google/go-cmp v0.5.9 // indirect 16 | github.com/nxadm/tail v1.4.8 // indirect 17 | golang.org/x/net v0.5.0 // indirect 18 | golang.org/x/sys v0.4.0 // indirect 19 | golang.org/x/text v0.6.0 // indirect 20 | gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 // indirect 21 | gopkg.in/yaml.v3 v3.0.1 // indirect 22 | ) 23 | -------------------------------------------------------------------------------- /go.sum: -------------------------------------------------------------------------------- 1 | github.com/bsm/ginkgo/v2 v2.7.0 h1:ItPMPH90RbmZJt5GtkcNvIRuGEdwlBItdNVoyzaNQao= 2 | github.com/bsm/gomega v1.26.0 h1:LhQm+AFcgV2M0WyKroMASzAzCAJVpAxQXv4SaI9a69Y= 3 | github.com/cespare/xxhash/v2 v2.2.0 h1:DC2CZ1Ep5Y4k3ZQ899DldepgrayRUGE6BBZ/cd9Cj44= 4 | github.com/cespare/xxhash/v2 v2.2.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs= 5 | github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= 6 | github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= 7 | github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f h1:lO4WD4F/rVNCu3HqELle0jiPLLBs70cWOduZpkS1E78= 8 | github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f/go.mod h1:cuUVRXasLTGF7a8hSLbxyZXjz+1KgoB3wDUb6vlszIc= 9 | github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo= 10 | github.com/fsnotify/fsnotify v1.4.9 h1:hsms1Qyu0jgnwNXIxa+/V/PDsU6CfLf6CNO8H7IWoS4= 11 | github.com/fsnotify/fsnotify v1.4.9/go.mod h1:znqG4EE+3YCdAaPaxE2ZRY/06pZUdp0tY4IgpuI1SZQ= 12 | github.com/go-logr/logr v1.2.3 h1:2DntVwHkVopvECVRSlL5PSo9eG+cAkDCuckLubN+rq0= 13 | github.com/go-task/slim-sprig v0.0.0-20210107165309-348f09dbbbc0/go.mod h1:fyg7847qk6SyHyPtNmDHnmrv/HOrqktSC+C9fM+CJOE= 14 | github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= 15 | github.com/golang/protobuf v1.4.0-rc.1/go.mod h1:ceaxUfeHdC40wWswd/P6IGgMaK3YpKi5j83Wpe3EHw8= 16 | github.com/golang/protobuf v1.4.0-rc.1.0.20200221234624-67d41d38c208/go.mod h1:xKAWHe0F5eneWXFV3EuXVDTCmh+JuBKY0li0aMyXATA= 17 | github.com/golang/protobuf v1.4.0-rc.2/go.mod h1:LlEzMj4AhA7rCAGe4KMBDvJI+AwstrUpVNzEA03Pprs= 18 | github.com/golang/protobuf v1.4.0-rc.4.0.20200313231945-b860323f09d0/go.mod h1:WU3c8KckQ9AFe+yFwt9sWVRKCVIyN9cPHBJSNnbL67w= 19 | github.com/golang/protobuf v1.4.0/go.mod h1:jodUvKwWbYaEsadDk5Fwe5c77LiNKVO9IDvqG2KuDX0= 20 | github.com/golang/protobuf v1.4.2/go.mod h1:oDoupMAO8OvCJWAcko0GGGIgR6R6ocIYbsSw735rRwI= 21 | github.com/golang/protobuf v1.5.2 h1:ROPKBNFfQgOUMifHyP+KYbvpjbdoFNs+aK7DXlji0Tw= 22 | github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= 23 | github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= 24 | github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= 25 | github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38= 26 | github.com/google/go-cmp v0.5.9/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= 27 | github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU= 28 | github.com/nxadm/tail v1.4.4/go.mod h1:kenIhsEOeOJmVchQTgglprH7qJGnHDVpk1VPCcaMI8A= 29 | github.com/nxadm/tail v1.4.8 h1:nPr65rt6Y5JFSKQO7qToXr7pePgD6Gwiw05lkbyAQTE= 30 | github.com/nxadm/tail v1.4.8/go.mod h1:+ncqLTQzXmGhMZNUePPaPqPvBxHAIsmXswZKocGu+AU= 31 | github.com/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE= 32 | github.com/onsi/ginkgo v1.12.1/go.mod h1:zj2OWP4+oCPe1qIXoGWkgMRwljMUYCdkwsT2108oapk= 33 | github.com/onsi/ginkgo v1.16.5 h1:8xi0RTUf59SOSfEtZMvwTvXYMzG4gV23XVHOZiXNtnE= 34 | github.com/onsi/ginkgo v1.16.5/go.mod h1:+E8gABHa3K6zRBolWtd+ROzc/U5bkGt0FwiG042wbpU= 35 | github.com/onsi/ginkgo/v2 v2.7.0 h1:/XxtEV3I3Eif/HobnVx9YmJgk8ENdRsuUmM+fLCFNow= 36 | github.com/onsi/gomega v1.7.1/go.mod h1:XdKZgCCFLUoM/7CFJVPcG8C1xQ1AJ0vpAezJrB7JYyY= 37 | github.com/onsi/gomega v1.10.1/go.mod h1:iN09h71vgCQne3DLsj+A5owkum+a2tYe+TOCB1ybHNo= 38 | github.com/onsi/gomega v1.25.0 h1:Vw7br2PCDYijJHSfBOWhov+8cAnUf8MfMaIOV323l6Y= 39 | github.com/onsi/gomega v1.25.0/go.mod h1:r+zV744Re+DiYCIPRlYOTxn0YkOLcAnW8k1xXdMPGhM= 40 | github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= 41 | github.com/redis/go-redis/v9 v9.0.3 h1:+7mmR26M0IvyLxGZUHxu4GiBkJkVDid0Un+j4ScYu4k= 42 | github.com/redis/go-redis/v9 v9.0.3/go.mod h1:WqMKv5vnQbRuZstUwxQI195wHy+t4PuXDOjzMvcuQHk= 43 | github.com/redis/go-redis/v9 v9.2.0 h1:zwMdX0A4eVzse46YN18QhuDiM4uf3JmkOB4VZrdt5uI= 44 | github.com/redis/go-redis/v9 v9.2.0/go.mod h1:hdY0cQFCN4fnSYT6TkisLufl/4W5UIXyv0b/CLO2V2M= 45 | github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= 46 | github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA= 47 | github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= 48 | golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= 49 | golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= 50 | golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= 51 | golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= 52 | golang.org/x/net v0.0.0-20180906233101-161cd47e91fd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= 53 | golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= 54 | golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= 55 | golang.org/x/net v0.0.0-20200520004742-59133d7f0dd7/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A= 56 | golang.org/x/net v0.0.0-20201021035429-f5854403a974/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU= 57 | golang.org/x/net v0.5.0 h1:GyT4nK/YDHSqa1c4753ouYCDajOYKTja9Xb/OHtgvSw= 58 | golang.org/x/net v0.5.0/go.mod h1:DivGGAXEgPSlEBzxGzZI+ZLohi+xUj054jfeKui00ws= 59 | golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= 60 | golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= 61 | golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= 62 | golang.org/x/sys v0.0.0-20180909124046-d0be0721c37e/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= 63 | golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= 64 | golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= 65 | golang.org/x/sys v0.0.0-20190904154756-749cb33beabd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= 66 | golang.org/x/sys v0.0.0-20191005200804-aed5e4c7ecf9/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= 67 | golang.org/x/sys v0.0.0-20191120155948-bd437916bb0e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= 68 | golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= 69 | golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= 70 | golang.org/x/sys v0.0.0-20210112080510-489259a85091/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= 71 | golang.org/x/sys v0.4.0 h1:Zr2JFtRQNX3BCZ8YtxRE9hNJYC8J6I1MVbMg6owUp18= 72 | golang.org/x/sys v0.4.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= 73 | golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= 74 | golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= 75 | golang.org/x/text v0.6.0 h1:3XmdazWV+ubf7QgHSTWeykHOci5oeekaGJBLkrkaw4k= 76 | golang.org/x/text v0.6.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8= 77 | golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= 78 | golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= 79 | golang.org/x/tools v0.0.0-20201224043029-2b0845dc783e/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA= 80 | golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= 81 | golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= 82 | golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= 83 | golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= 84 | google.golang.org/protobuf v0.0.0-20200109180630-ec00e32a8dfd/go.mod h1:DFci5gLYBciE7Vtevhsrf46CRTquxDuWsQurQQe4oz8= 85 | google.golang.org/protobuf v0.0.0-20200221191635-4d8936d0db64/go.mod h1:kwYJMbMJ01Woi6D6+Kah6886xMZcty6N08ah7+eCXa0= 86 | google.golang.org/protobuf v0.0.0-20200228230310-ab0ca4ff8a60/go.mod h1:cfTl7dwQJ+fmap5saPgwCLgHXTUD7jkjRqWcaiX5VyM= 87 | google.golang.org/protobuf v1.20.1-0.20200309200217-e05f789c0967/go.mod h1:A+miEFZTKqfCUM6K7xSMQL9OKL/b6hQv+e19PK+JZNE= 88 | google.golang.org/protobuf v1.21.0/go.mod h1:47Nbq4nVaFHyn7ilMalzfO3qCViNmqZ2kzikPIcrTAo= 89 | google.golang.org/protobuf v1.23.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU= 90 | google.golang.org/protobuf v1.28.0 h1:w43yiav+6bVFTBQFZX0r7ipe9JQ1QsbMgHwbBziscLw= 91 | gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= 92 | gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= 93 | gopkg.in/fsnotify.v1 v1.4.7/go.mod h1:Tz8NjZHkW78fSQdbUxIjBTcgA1z1m8ZHf0WmKUhAMys= 94 | gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 h1:uRGJdciOHaEIrze2W8Q3AKkepLTh2hOroT7a+7czfdQ= 95 | gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7/go.mod h1:dt/ZhP58zS4L8KSrWDmTeBkI65Dw0HsyUHuEVlX15mw= 96 | gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= 97 | gopkg.in/yaml.v2 v2.2.4/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= 98 | gopkg.in/yaml.v2 v2.3.0/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= 99 | gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= 100 | gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= 101 | -------------------------------------------------------------------------------- /mock.go: -------------------------------------------------------------------------------- 1 | package redismock 2 | 3 | import ( 4 | "context" 5 | "fmt" 6 | "net" 7 | "reflect" 8 | "regexp" 9 | "strings" 10 | "time" 11 | 12 | "github.com/redis/go-redis/v9" 13 | ) 14 | 15 | type mockCmdable interface { 16 | redis.Cmdable 17 | redis.BitMapCmdable 18 | redis.StreamCmdable 19 | } 20 | 21 | type mock struct { 22 | ctx context.Context 23 | 24 | parent *mock 25 | 26 | factory mockCmdable 27 | client redis.Cmdable 28 | expected []expectation 29 | unexpected []redis.Cmder 30 | 31 | strictOrder bool 32 | 33 | expectRegexp bool 34 | expectCustom CustomMatch 35 | 36 | clientType redisClientType 37 | } 38 | 39 | type redisClientType int 40 | 41 | const ( 42 | redisClient redisClientType = iota + 1 43 | redisCluster 44 | ) 45 | 46 | func NewClientMock() (*redis.Client, ClientMock) { 47 | m := newMock(redisClient) 48 | return m.client.(*redis.Client), m 49 | } 50 | 51 | func NewClusterMock() (*redis.ClusterClient, ClusterClientMock) { 52 | m := newMock(redisCluster) 53 | return m.client.(*redis.ClusterClient), m 54 | } 55 | 56 | func newMock(typ redisClientType) *mock { 57 | m := &mock{ 58 | ctx: context.Background(), 59 | clientType: typ, 60 | } 61 | 62 | // MaxRetries/MaxRedirects set -2, avoid executing commands on the redis server 63 | switch typ { 64 | case redisClient: 65 | opt := &redis.Options{MaxRetries: -2} 66 | factory := redis.NewClient(opt) 67 | client := redis.NewClient(opt) 68 | factory.AddHook(nilHook{}) 69 | client.AddHook(redisClientHook{fn: m.process}) 70 | 71 | m.factory = factory 72 | m.client = client 73 | case redisCluster: 74 | opt := &redis.ClusterOptions{MaxRedirects: -2} 75 | factory := redis.NewClusterClient(opt) 76 | clusterClient := redis.NewClusterClient(opt) 77 | factory.AddHook(nilHook{}) 78 | clusterClient.AddHook(redisClientHook{fn: m.process}) 79 | 80 | m.factory = factory 81 | m.client = clusterClient 82 | } 83 | m.strictOrder = true 84 | 85 | return m 86 | } 87 | 88 | //------------------------------------------------------------------ 89 | 90 | type redisClientHook struct { 91 | returnErr error 92 | fn func(cmd redis.Cmder) error 93 | } 94 | 95 | func (redisClientHook) DialHook(hook redis.DialHook) redis.DialHook { 96 | return hook 97 | } 98 | 99 | func (h redisClientHook) ProcessHook(_ redis.ProcessHook) redis.ProcessHook { 100 | return func(ctx context.Context, cmd redis.Cmder) error { 101 | err := h.fn(cmd) 102 | if h.returnErr != nil && (err == nil || cmd.Err() == nil) { 103 | err = h.returnErr 104 | } 105 | return err 106 | } 107 | } 108 | 109 | func (h redisClientHook) ProcessPipelineHook(_ redis.ProcessPipelineHook) redis.ProcessPipelineHook { 110 | return func(ctx context.Context, cmds []redis.Cmder) error { 111 | for _, cmd := range cmds { 112 | err := h.fn(cmd) 113 | if h.returnErr != nil && (err == nil || cmd.Err() == nil) { 114 | err = h.returnErr 115 | } 116 | if err != nil { 117 | return err 118 | } 119 | } 120 | return nil 121 | } 122 | } 123 | 124 | type nilHook struct{} 125 | 126 | func (nilHook) DialHook(_ redis.DialHook) redis.DialHook { 127 | return func(_ context.Context, _, _ string) (net.Conn, error) { 128 | return &net.TCPConn{}, nil 129 | } 130 | } 131 | 132 | func (h nilHook) ProcessHook(_ redis.ProcessHook) redis.ProcessHook { 133 | return func(_ context.Context, _ redis.Cmder) error { 134 | return nil 135 | } 136 | } 137 | 138 | func (h nilHook) ProcessPipelineHook(_ redis.ProcessPipelineHook) redis.ProcessPipelineHook { 139 | return func(_ context.Context, _ []redis.Cmder) error { 140 | return nil 141 | } 142 | } 143 | 144 | //---------------------------------- 145 | 146 | func (m *mock) process(cmd redis.Cmder) (err error) { 147 | var miss int 148 | var expect expectation = nil 149 | 150 | for _, e := range m.expected { 151 | e.lock() 152 | 153 | // not available, has been matched 154 | if !e.usable() { 155 | e.unlock() 156 | miss++ 157 | continue 158 | } 159 | 160 | err = m.match(e, cmd) 161 | 162 | // matched 163 | if err == nil { 164 | expect = e 165 | break 166 | } 167 | 168 | // strict order of command execution 169 | if m.strictOrder { 170 | e.unlock() 171 | cmd.SetErr(err) 172 | return err 173 | } 174 | e.unlock() 175 | } 176 | 177 | if expect == nil { 178 | msg := "call to cmd '%+v' was not expected" 179 | if miss == len(m.expected) { 180 | msg = "all expectations were already fulfilled, " + msg 181 | } 182 | err = fmt.Errorf(msg, cmd.Args()) 183 | cmd.SetErr(err) 184 | m.unexpected = append(m.unexpected, cmd) 185 | return err 186 | } 187 | 188 | defer expect.unlock() 189 | 190 | expect.trigger() 191 | 192 | // write error 193 | if err = expect.error(); err != nil { 194 | cmd.SetErr(err) 195 | return err 196 | } 197 | 198 | // write redis.Nil 199 | if expect.isRedisNil() { 200 | err = redis.Nil 201 | cmd.SetErr(err) 202 | return err 203 | } 204 | 205 | // if you do not set error or redis.Nil, must set val 206 | if !expect.isSetVal() { 207 | err = fmt.Errorf("cmd(%s), return value is required", expect.name()) 208 | cmd.SetErr(err) 209 | return err 210 | } 211 | 212 | cmd.SetErr(nil) 213 | expect.inflow(cmd) 214 | 215 | return nil 216 | } 217 | 218 | func (m *mock) match(expect expectation, cmd redis.Cmder) error { 219 | expectArgs := expect.args() 220 | cmdArgs := cmd.Args() 221 | 222 | if len(expectArgs) != len(cmdArgs) { 223 | return fmt.Errorf("parameters do not match, expectation '%+v', but call to cmd '%+v'", expectArgs, cmdArgs) 224 | } 225 | 226 | if expect.name() != cmd.Name() { 227 | return fmt.Errorf("command not match, expectation '%s', but call to cmd '%s'", expect.name(), cmd.Name()) 228 | } 229 | 230 | // custom func match 231 | if fn := expect.custom(); fn != nil { 232 | return fn(expectArgs, cmdArgs) 233 | } 234 | 235 | isMapArgs := m.mapArgs(cmd.Name(), &cmdArgs) 236 | if isMapArgs { 237 | m.mapArgs(expect.name(), &expectArgs) 238 | } 239 | 240 | for i := 0; i < len(expectArgs); i++ { 241 | // is map? 242 | if isMapArgs { 243 | expectMapArgs, expectOK := expectArgs[i].(map[string]interface{}) 244 | cmdMapArgs, cmdOK := cmdArgs[i].(map[string]interface{}) 245 | if expectOK && cmdOK { 246 | // there may be the same key 247 | if len(expectMapArgs) != len(cmdMapArgs) { 248 | return fmt.Errorf("wrong number of arguments, expectation regular: '%+v', but gave: '%+v'", 249 | expectArgs, cmdArgs) 250 | } 251 | for expectKey, expectMapVal := range expectMapArgs { 252 | cmdMapVal, ok := cmdMapArgs[expectKey] 253 | if !ok { 254 | return fmt.Errorf("missing command(%s) parameters: %s", expect.name(), expectKey) 255 | } 256 | if err := m.compare(expect.regexp(), expectMapVal, cmdMapVal); err != nil { 257 | return err 258 | } 259 | } 260 | continue 261 | } 262 | } 263 | if err := m.compare(expect.regexp(), expectArgs[i], cmdArgs[i]); err != nil { 264 | return err 265 | } 266 | } 267 | 268 | return nil 269 | } 270 | 271 | func (m *mock) compare(isRegexp bool, expect, cmd interface{}) error { 272 | expr, ok := expect.(string) 273 | if isRegexp && ok { 274 | cmdValue := fmt.Sprint(cmd) 275 | re, err := regexp.Compile(expr) 276 | if err != nil { 277 | return err 278 | } 279 | if !re.MatchString(cmdValue) { 280 | return fmt.Errorf("args not match, expectation regular: '%s', but gave: '%s'", expr, cmdValue) 281 | } 282 | } else if !reflect.DeepEqual(expect, cmd) { 283 | return fmt.Errorf("args not `DeepEqual`, expectation: '%+v', but gave: '%+v'", expect, cmd) 284 | } 285 | return nil 286 | } 287 | 288 | // using map in command leads to disorder, change the command parameter to map[string]interface{} 289 | // for example: 290 | // 291 | // [mset key1 value1 key2 value2] => [mset map[string]interface{}{"key1": "value1", "key2": "value2"}] 292 | // 293 | // return bool, is it handled 294 | func (m *mock) mapArgs(cmd string, cmdArgs *[]interface{}) bool { 295 | var cut int 296 | cmd = strings.ToLower(cmd) 297 | switch cmd { 298 | case "mset", "msetnx": 299 | // 1 300 | cut = 1 301 | case "hset", "hmset": 302 | // 2 303 | cut = 2 304 | case "eval", "evalsha": 305 | // more, i guess nobody uses it (eval/evalsha), miss 306 | return false 307 | default: 308 | return false 309 | } 310 | 311 | if n := len(*cmdArgs); n <= cut || (n > (cut+1) && (n-cut)%2 != 0) { 312 | return false 313 | } 314 | 315 | mapArgs := make(map[string]interface{}) 316 | args := (*cmdArgs)[cut:] 317 | switch v := args[0].(type) { 318 | //[]string and map[string]interface{}, types will not appear normally 319 | case []string: 320 | if len(v)%2 != 0 { 321 | return false 322 | } 323 | for i := 0; i < len(v); i += 2 { 324 | mapArgs[v[i]] = v[i+1] 325 | } 326 | case map[string]interface{}: 327 | if len(v) > 0 { 328 | mapArgs = v 329 | } 330 | default: 331 | for i := 0; i < len(args); i += 2 { 332 | mapArgs[fmt.Sprint(args[i])] = args[i+1] 333 | } 334 | } 335 | 336 | if len(mapArgs) == 0 { 337 | return false 338 | } 339 | 340 | newCmd := make([]interface{}, cut, cut+1) 341 | copy(newCmd[:cut], (*cmdArgs)[:cut]) 342 | newCmd = append(newCmd, mapArgs) 343 | *cmdArgs = newCmd 344 | return true 345 | } 346 | 347 | func (m *mock) pushExpect(e expectation) { 348 | if m.expectRegexp { 349 | e.setRegexpMatch() 350 | } 351 | if m.expectCustom != nil { 352 | e.setCustomMatch(m.expectCustom) 353 | } 354 | if m.parent != nil { 355 | m.parent.pushExpect(e) 356 | return 357 | } 358 | m.expected = append(m.expected, e) 359 | } 360 | 361 | func (m *mock) ClearExpect() { 362 | if m.parent != nil { 363 | m.parent.ClearExpect() 364 | return 365 | } 366 | m.expected = nil 367 | m.unexpected = nil 368 | } 369 | 370 | func (m *mock) Regexp() *mock { 371 | if m.parent != nil { 372 | return m.parent.Regexp() 373 | } 374 | clone := *m 375 | clone.parent = m 376 | clone.expectRegexp = true 377 | 378 | return &clone 379 | } 380 | 381 | func (m *mock) CustomMatch(fn CustomMatch) *mock { 382 | if m.parent != nil { 383 | return m.parent.CustomMatch(fn) 384 | } 385 | clone := *m 386 | clone.parent = m 387 | clone.expectCustom = fn 388 | 389 | return &clone 390 | } 391 | 392 | func (m *mock) ExpectationsWereMet() error { 393 | if m.parent != nil { 394 | return m.ExpectationsWereMet() 395 | } 396 | for _, e := range m.expected { 397 | e.lock() 398 | usable := e.usable() 399 | e.unlock() 400 | 401 | if usable { 402 | return fmt.Errorf("there is a remaining expectation which was not matched: %+v", e.args()) 403 | } 404 | } 405 | return nil 406 | } 407 | 408 | func (m *mock) UnexpectedCallsWereMade() (bool, []redis.Cmder) { 409 | if m.parent != nil { 410 | return m.parent.UnexpectedCallsWereMade() 411 | } 412 | return len(m.unexpected) > 0, m.unexpected 413 | } 414 | 415 | func (m *mock) MatchExpectationsInOrder(b bool) { 416 | if m.parent != nil { 417 | m.MatchExpectationsInOrder(b) 418 | return 419 | } 420 | m.strictOrder = b 421 | } 422 | 423 | // ----------------------------------------------------- 424 | 425 | func (m *mock) ExpectTxPipeline() { 426 | e := &ExpectedStatus{} 427 | e.cmd = redis.NewStatusCmd(m.ctx, "multi") 428 | e.SetVal("OK") 429 | m.pushExpect(e) 430 | } 431 | 432 | func (m *mock) ExpectTxPipelineExec() *ExpectedSlice { 433 | e := &ExpectedSlice{} 434 | e.cmd = redis.NewSliceCmd(m.ctx, "exec") 435 | e.SetVal(nil) 436 | m.pushExpect(e) 437 | return e 438 | } 439 | 440 | func (m *mock) ExpectWatch(keys ...string) *ExpectedError { 441 | e := &ExpectedError{} 442 | args := make([]interface{}, 1+len(keys)) 443 | args[0] = "watch" 444 | for i, key := range keys { 445 | args[1+i] = key 446 | } 447 | e.cmd = redis.NewStatusCmd(m.ctx, args...) 448 | e.setVal = true 449 | m.pushExpect(e) 450 | return e 451 | } 452 | 453 | // ------------------------------------------------ 454 | 455 | func (m *mock) ExpectDo(args ...interface{}) *ExpectedCmd { 456 | e := &ExpectedCmd{} 457 | 458 | switch m.clientType { 459 | case redisClient: 460 | e.cmd = m.factory.(*redis.Client).Do(m.ctx, args...) 461 | case redisCluster: 462 | e.cmd = m.factory.(*redis.ClusterClient).Do(m.ctx, args...) 463 | default: 464 | panic("ExpectDo: unsupported client type") 465 | } 466 | 467 | m.pushExpect(e) 468 | return e 469 | } 470 | 471 | func (m *mock) ExpectCommand() *ExpectedCommandsInfo { 472 | e := &ExpectedCommandsInfo{} 473 | e.cmd = m.factory.Command(m.ctx) 474 | m.pushExpect(e) 475 | return e 476 | } 477 | 478 | func (m *mock) ExpectCommandList(filter *redis.FilterBy) *ExpectedStringSlice { 479 | e := &ExpectedStringSlice{} 480 | e.cmd = m.factory.CommandList(m.ctx, filter) 481 | m.pushExpect(e) 482 | return e 483 | } 484 | 485 | func (m *mock) ExpectCommandGetKeys(commands ...interface{}) *ExpectedStringSlice { 486 | e := &ExpectedStringSlice{} 487 | e.cmd = m.factory.CommandGetKeys(m.ctx, commands...) 488 | m.pushExpect(e) 489 | return e 490 | } 491 | 492 | func (m *mock) ExpectCommandGetKeysAndFlags(commands ...interface{}) *ExpectedKeyFlags { 493 | e := &ExpectedKeyFlags{} 494 | e.cmd = m.factory.CommandGetKeysAndFlags(m.ctx, commands...) 495 | m.pushExpect(e) 496 | return e 497 | } 498 | 499 | func (m *mock) ExpectClientGetName() *ExpectedString { 500 | e := &ExpectedString{} 501 | e.cmd = m.factory.ClientGetName(m.ctx) 502 | m.pushExpect(e) 503 | return e 504 | } 505 | 506 | func (m *mock) ExpectEcho(message interface{}) *ExpectedString { 507 | e := &ExpectedString{} 508 | e.cmd = m.factory.Echo(m.ctx, message) 509 | m.pushExpect(e) 510 | return e 511 | } 512 | 513 | func (m *mock) ExpectPing() *ExpectedStatus { 514 | e := &ExpectedStatus{} 515 | e.cmd = m.factory.Ping(m.ctx) 516 | m.pushExpect(e) 517 | return e 518 | } 519 | 520 | func (m *mock) ExpectQuit() *ExpectedStatus { 521 | e := &ExpectedStatus{} 522 | e.cmd = m.factory.Quit(m.ctx) 523 | m.pushExpect(e) 524 | return e 525 | } 526 | 527 | func (m *mock) ExpectDel(keys ...string) *ExpectedInt { 528 | e := &ExpectedInt{} 529 | e.cmd = m.factory.Del(m.ctx, keys...) 530 | m.pushExpect(e) 531 | return e 532 | } 533 | 534 | func (m *mock) ExpectUnlink(keys ...string) *ExpectedInt { 535 | e := &ExpectedInt{} 536 | e.cmd = m.factory.Unlink(m.ctx, keys...) 537 | m.pushExpect(e) 538 | return e 539 | } 540 | 541 | func (m *mock) ExpectDump(key string) *ExpectedString { 542 | e := &ExpectedString{} 543 | e.cmd = m.factory.Dump(m.ctx, key) 544 | m.pushExpect(e) 545 | return e 546 | } 547 | 548 | func (m *mock) ExpectExists(keys ...string) *ExpectedInt { 549 | e := &ExpectedInt{} 550 | e.cmd = m.factory.Exists(m.ctx, keys...) 551 | m.pushExpect(e) 552 | return e 553 | } 554 | 555 | func (m *mock) ExpectExpire(key string, expiration time.Duration) *ExpectedBool { 556 | e := &ExpectedBool{} 557 | e.cmd = m.factory.Expire(m.ctx, key, expiration) 558 | m.pushExpect(e) 559 | return e 560 | } 561 | 562 | func (m *mock) ExpectExpireAt(key string, tm time.Time) *ExpectedBool { 563 | e := &ExpectedBool{} 564 | e.cmd = m.factory.ExpireAt(m.ctx, key, tm) 565 | m.pushExpect(e) 566 | return e 567 | } 568 | 569 | func (m *mock) ExpectExpireTime(key string) *ExpectedDuration { 570 | e := &ExpectedDuration{} 571 | e.cmd = m.factory.ExpireTime(m.ctx, key) 572 | m.pushExpect(e) 573 | return e 574 | } 575 | 576 | func (m *mock) ExpectExpireNX(key string, expiration time.Duration) *ExpectedBool { 577 | e := &ExpectedBool{} 578 | e.cmd = m.factory.ExpireNX(m.ctx, key, expiration) 579 | m.pushExpect(e) 580 | return e 581 | } 582 | 583 | func (m *mock) ExpectExpireXX(key string, expiration time.Duration) *ExpectedBool { 584 | e := &ExpectedBool{} 585 | e.cmd = m.factory.ExpireXX(m.ctx, key, expiration) 586 | m.pushExpect(e) 587 | return e 588 | } 589 | 590 | func (m *mock) ExpectExpireGT(key string, expiration time.Duration) *ExpectedBool { 591 | e := &ExpectedBool{} 592 | e.cmd = m.factory.ExpireGT(m.ctx, key, expiration) 593 | m.pushExpect(e) 594 | return e 595 | } 596 | 597 | func (m *mock) ExpectExpireLT(key string, expiration time.Duration) *ExpectedBool { 598 | e := &ExpectedBool{} 599 | e.cmd = m.factory.ExpireLT(m.ctx, key, expiration) 600 | m.pushExpect(e) 601 | return e 602 | } 603 | 604 | func (m *mock) ExpectKeys(pattern string) *ExpectedStringSlice { 605 | e := &ExpectedStringSlice{} 606 | e.cmd = m.factory.Keys(m.ctx, pattern) 607 | m.pushExpect(e) 608 | return e 609 | } 610 | 611 | func (m *mock) ExpectMigrate(host, port, key string, db int, timeout time.Duration) *ExpectedStatus { 612 | e := &ExpectedStatus{} 613 | e.cmd = m.factory.Migrate(m.ctx, host, port, key, db, timeout) 614 | m.pushExpect(e) 615 | return e 616 | } 617 | 618 | func (m *mock) ExpectMove(key string, db int) *ExpectedBool { 619 | e := &ExpectedBool{} 620 | e.cmd = m.factory.Move(m.ctx, key, db) 621 | m.pushExpect(e) 622 | return e 623 | } 624 | 625 | func (m *mock) ExpectObjectRefCount(key string) *ExpectedInt { 626 | e := &ExpectedInt{} 627 | e.cmd = m.factory.ObjectRefCount(m.ctx, key) 628 | m.pushExpect(e) 629 | return e 630 | } 631 | 632 | func (m *mock) ExpectObjectEncoding(key string) *ExpectedString { 633 | e := &ExpectedString{} 634 | e.cmd = m.factory.ObjectEncoding(m.ctx, key) 635 | m.pushExpect(e) 636 | return e 637 | } 638 | 639 | func (m *mock) ExpectObjectIdleTime(key string) *ExpectedDuration { 640 | e := &ExpectedDuration{} 641 | e.cmd = m.factory.ObjectIdleTime(m.ctx, key) 642 | m.pushExpect(e) 643 | return e 644 | } 645 | 646 | func (m *mock) ExpectPersist(key string) *ExpectedBool { 647 | e := &ExpectedBool{} 648 | e.cmd = m.factory.Persist(m.ctx, key) 649 | m.pushExpect(e) 650 | return e 651 | } 652 | 653 | func (m *mock) ExpectPExpire(key string, expiration time.Duration) *ExpectedBool { 654 | e := &ExpectedBool{} 655 | e.cmd = m.factory.PExpire(m.ctx, key, expiration) 656 | m.pushExpect(e) 657 | return e 658 | } 659 | 660 | func (m *mock) ExpectPExpireAt(key string, tm time.Time) *ExpectedBool { 661 | e := &ExpectedBool{} 662 | e.cmd = m.factory.PExpireAt(m.ctx, key, tm) 663 | m.pushExpect(e) 664 | return e 665 | } 666 | 667 | func (m *mock) ExpectPExpireTime(key string) *ExpectedDuration { 668 | e := &ExpectedDuration{} 669 | e.cmd = m.factory.PExpireTime(m.ctx, key) 670 | m.pushExpect(e) 671 | return e 672 | } 673 | 674 | func (m *mock) ExpectPTTL(key string) *ExpectedDuration { 675 | e := &ExpectedDuration{} 676 | e.cmd = m.factory.PTTL(m.ctx, key) 677 | m.pushExpect(e) 678 | return e 679 | } 680 | 681 | func (m *mock) ExpectRandomKey() *ExpectedString { 682 | e := &ExpectedString{} 683 | e.cmd = m.factory.RandomKey(m.ctx) 684 | m.pushExpect(e) 685 | return e 686 | } 687 | 688 | func (m *mock) ExpectRename(key, newkey string) *ExpectedStatus { 689 | e := &ExpectedStatus{} 690 | e.cmd = m.factory.Rename(m.ctx, key, newkey) 691 | m.pushExpect(e) 692 | return e 693 | } 694 | 695 | func (m *mock) ExpectRenameNX(key, newkey string) *ExpectedBool { 696 | e := &ExpectedBool{} 697 | e.cmd = m.factory.RenameNX(m.ctx, key, newkey) 698 | m.pushExpect(e) 699 | return e 700 | } 701 | 702 | func (m *mock) ExpectRestore(key string, ttl time.Duration, value string) *ExpectedStatus { 703 | e := &ExpectedStatus{} 704 | e.cmd = m.factory.Restore(m.ctx, key, ttl, value) 705 | m.pushExpect(e) 706 | return e 707 | } 708 | 709 | func (m *mock) ExpectRestoreReplace(key string, ttl time.Duration, value string) *ExpectedStatus { 710 | e := &ExpectedStatus{} 711 | e.cmd = m.factory.RestoreReplace(m.ctx, key, ttl, value) 712 | m.pushExpect(e) 713 | return e 714 | } 715 | 716 | func (m *mock) ExpectSort(key string, sort *redis.Sort) *ExpectedStringSlice { 717 | e := &ExpectedStringSlice{} 718 | e.cmd = m.factory.Sort(m.ctx, key, sort) 719 | m.pushExpect(e) 720 | return e 721 | } 722 | 723 | func (m *mock) ExpectSortRO(key string, sort *redis.Sort) *ExpectedStringSlice { 724 | e := &ExpectedStringSlice{} 725 | e.cmd = m.factory.SortRO(m.ctx, key, sort) 726 | m.pushExpect(e) 727 | return e 728 | } 729 | 730 | func (m *mock) ExpectSortStore(key, store string, sort *redis.Sort) *ExpectedInt { 731 | e := &ExpectedInt{} 732 | e.cmd = m.factory.SortStore(m.ctx, key, store, sort) 733 | m.pushExpect(e) 734 | return e 735 | } 736 | 737 | func (m *mock) ExpectSortInterfaces(key string, sort *redis.Sort) *ExpectedSlice { 738 | e := &ExpectedSlice{} 739 | e.cmd = m.factory.SortInterfaces(m.ctx, key, sort) 740 | m.pushExpect(e) 741 | return e 742 | } 743 | 744 | func (m *mock) ExpectTouch(keys ...string) *ExpectedInt { 745 | e := &ExpectedInt{} 746 | e.cmd = m.factory.Touch(m.ctx, keys...) 747 | m.pushExpect(e) 748 | return e 749 | } 750 | 751 | func (m *mock) ExpectTTL(key string) *ExpectedDuration { 752 | e := &ExpectedDuration{} 753 | e.cmd = m.factory.TTL(m.ctx, key) 754 | m.pushExpect(e) 755 | return e 756 | } 757 | 758 | func (m *mock) ExpectType(key string) *ExpectedStatus { 759 | e := &ExpectedStatus{} 760 | e.cmd = m.factory.Type(m.ctx, key) 761 | m.pushExpect(e) 762 | return e 763 | } 764 | 765 | func (m *mock) ExpectAppend(key, value string) *ExpectedInt { 766 | e := &ExpectedInt{} 767 | e.cmd = m.factory.Append(m.ctx, key, value) 768 | m.pushExpect(e) 769 | return e 770 | } 771 | 772 | func (m *mock) ExpectDecr(key string) *ExpectedInt { 773 | e := &ExpectedInt{} 774 | e.cmd = m.factory.Decr(m.ctx, key) 775 | m.pushExpect(e) 776 | return e 777 | } 778 | 779 | func (m *mock) ExpectDecrBy(key string, decrement int64) *ExpectedInt { 780 | e := &ExpectedInt{} 781 | e.cmd = m.factory.DecrBy(m.ctx, key, decrement) 782 | m.pushExpect(e) 783 | return e 784 | } 785 | 786 | func (m *mock) ExpectGet(key string) *ExpectedString { 787 | e := &ExpectedString{} 788 | e.cmd = m.factory.Get(m.ctx, key) 789 | m.pushExpect(e) 790 | return e 791 | } 792 | 793 | func (m *mock) ExpectGetRange(key string, start, end int64) *ExpectedString { 794 | e := &ExpectedString{} 795 | e.cmd = m.factory.GetRange(m.ctx, key, start, end) 796 | m.pushExpect(e) 797 | return e 798 | } 799 | 800 | func (m *mock) ExpectGetSet(key string, value interface{}) *ExpectedString { 801 | e := &ExpectedString{} 802 | e.cmd = m.factory.GetSet(m.ctx, key, value) 803 | m.pushExpect(e) 804 | return e 805 | } 806 | 807 | func (m *mock) ExpectGetEx(key string, expiration time.Duration) *ExpectedString { 808 | e := &ExpectedString{} 809 | e.cmd = m.factory.GetEx(m.ctx, key, expiration) 810 | m.pushExpect(e) 811 | return e 812 | } 813 | 814 | func (m *mock) ExpectGetDel(key string) *ExpectedString { 815 | e := &ExpectedString{} 816 | e.cmd = m.factory.GetDel(m.ctx, key) 817 | m.pushExpect(e) 818 | return e 819 | } 820 | 821 | func (m *mock) ExpectIncr(key string) *ExpectedInt { 822 | e := &ExpectedInt{} 823 | e.cmd = m.factory.Incr(m.ctx, key) 824 | m.pushExpect(e) 825 | return e 826 | } 827 | 828 | func (m *mock) ExpectIncrBy(key string, value int64) *ExpectedInt { 829 | e := &ExpectedInt{} 830 | e.cmd = m.factory.IncrBy(m.ctx, key, value) 831 | m.pushExpect(e) 832 | return e 833 | } 834 | 835 | func (m *mock) ExpectIncrByFloat(key string, value float64) *ExpectedFloat { 836 | e := &ExpectedFloat{} 837 | e.cmd = m.factory.IncrByFloat(m.ctx, key, value) 838 | m.pushExpect(e) 839 | return e 840 | } 841 | 842 | func (m *mock) ExpectMGet(keys ...string) *ExpectedSlice { 843 | e := &ExpectedSlice{} 844 | e.cmd = m.factory.MGet(m.ctx, keys...) 845 | m.pushExpect(e) 846 | return e 847 | } 848 | 849 | func (m *mock) ExpectMSet(values ...interface{}) *ExpectedStatus { 850 | e := &ExpectedStatus{} 851 | e.cmd = m.factory.MSet(m.ctx, values...) 852 | m.pushExpect(e) 853 | return e 854 | } 855 | 856 | func (m *mock) ExpectMSetNX(values ...interface{}) *ExpectedBool { 857 | e := &ExpectedBool{} 858 | e.cmd = m.factory.MSetNX(m.ctx, values...) 859 | m.pushExpect(e) 860 | return e 861 | } 862 | 863 | func (m *mock) ExpectSet(key string, value interface{}, expiration time.Duration) *ExpectedStatus { 864 | e := &ExpectedStatus{} 865 | e.cmd = m.factory.Set(m.ctx, key, value, expiration) 866 | m.pushExpect(e) 867 | return e 868 | } 869 | 870 | func (m *mock) ExpectSetArgs(key string, value interface{}, a redis.SetArgs) *ExpectedStatus { 871 | e := &ExpectedStatus{} 872 | e.cmd = m.factory.SetArgs(m.ctx, key, value, a) 873 | m.pushExpect(e) 874 | return e 875 | } 876 | 877 | func (m *mock) ExpectSetEx(key string, value interface{}, expiration time.Duration) *ExpectedStatus { 878 | e := &ExpectedStatus{} 879 | e.cmd = m.factory.SetEx(m.ctx, key, value, expiration) 880 | m.pushExpect(e) 881 | return e 882 | } 883 | 884 | func (m *mock) ExpectSetNX(key string, value interface{}, expiration time.Duration) *ExpectedBool { 885 | e := &ExpectedBool{} 886 | e.cmd = m.factory.SetNX(m.ctx, key, value, expiration) 887 | m.pushExpect(e) 888 | return e 889 | } 890 | 891 | func (m *mock) ExpectSetXX(key string, value interface{}, expiration time.Duration) *ExpectedBool { 892 | e := &ExpectedBool{} 893 | e.cmd = m.factory.SetXX(m.ctx, key, value, expiration) 894 | m.pushExpect(e) 895 | return e 896 | } 897 | 898 | func (m *mock) ExpectSetRange(key string, offset int64, value string) *ExpectedInt { 899 | e := &ExpectedInt{} 900 | e.cmd = m.factory.SetRange(m.ctx, key, offset, value) 901 | m.pushExpect(e) 902 | return e 903 | } 904 | 905 | func (m *mock) ExpectStrLen(key string) *ExpectedInt { 906 | e := &ExpectedInt{} 907 | e.cmd = m.factory.StrLen(m.ctx, key) 908 | m.pushExpect(e) 909 | return e 910 | } 911 | 912 | func (m *mock) ExpectCopy(sourceKey string, destKey string, db int, replace bool) *ExpectedInt { 913 | e := &ExpectedInt{} 914 | e.cmd = m.factory.Copy(m.ctx, sourceKey, destKey, db, replace) 915 | m.pushExpect(e) 916 | return e 917 | } 918 | 919 | func (m *mock) ExpectGetBit(key string, offset int64) *ExpectedInt { 920 | e := &ExpectedInt{} 921 | e.cmd = m.factory.GetBit(m.ctx, key, offset) 922 | m.pushExpect(e) 923 | return e 924 | } 925 | 926 | func (m *mock) ExpectSetBit(key string, offset int64, value int) *ExpectedInt { 927 | e := &ExpectedInt{} 928 | e.cmd = m.factory.SetBit(m.ctx, key, offset, value) 929 | m.pushExpect(e) 930 | return e 931 | } 932 | 933 | func (m *mock) ExpectBitCount(key string, bitCount *redis.BitCount) *ExpectedInt { 934 | e := &ExpectedInt{} 935 | e.cmd = m.factory.BitCount(m.ctx, key, bitCount) 936 | m.pushExpect(e) 937 | return e 938 | } 939 | 940 | func (m *mock) ExpectBitOpAnd(destKey string, keys ...string) *ExpectedInt { 941 | e := &ExpectedInt{} 942 | e.cmd = m.factory.BitOpAnd(m.ctx, destKey, keys...) 943 | m.pushExpect(e) 944 | return e 945 | } 946 | 947 | func (m *mock) ExpectBitOpOr(destKey string, keys ...string) *ExpectedInt { 948 | e := &ExpectedInt{} 949 | e.cmd = m.factory.BitOpOr(m.ctx, destKey, keys...) 950 | m.pushExpect(e) 951 | return e 952 | } 953 | 954 | func (m *mock) ExpectBitOpXor(destKey string, keys ...string) *ExpectedInt { 955 | e := &ExpectedInt{} 956 | e.cmd = m.factory.BitOpXor(m.ctx, destKey, keys...) 957 | m.pushExpect(e) 958 | return e 959 | } 960 | 961 | func (m *mock) ExpectBitOpNot(destKey string, key string) *ExpectedInt { 962 | e := &ExpectedInt{} 963 | e.cmd = m.factory.BitOpNot(m.ctx, destKey, key) 964 | m.pushExpect(e) 965 | return e 966 | } 967 | 968 | func (m *mock) ExpectBitPos(key string, bit int64, pos ...int64) *ExpectedInt { 969 | e := &ExpectedInt{} 970 | e.cmd = m.factory.BitPos(m.ctx, key, bit, pos...) 971 | m.pushExpect(e) 972 | return e 973 | } 974 | 975 | func (m *mock) ExpectBitPosSpan(key string, bit int8, start, end int64, span string) *ExpectedInt { 976 | e := &ExpectedInt{} 977 | e.cmd = m.factory.BitPosSpan(m.ctx, key, bit, start, end, span) 978 | m.pushExpect(e) 979 | return e 980 | } 981 | 982 | func (m *mock) ExpectBitField(key string, args ...interface{}) *ExpectedIntSlice { 983 | e := &ExpectedIntSlice{} 984 | e.cmd = m.factory.BitField(m.ctx, key, args...) 985 | m.pushExpect(e) 986 | return e 987 | } 988 | 989 | func (m *mock) ExpectScan(cursor uint64, match string, count int64) *ExpectedScan { 990 | e := &ExpectedScan{} 991 | e.cmd = m.factory.Scan(m.ctx, cursor, match, count) 992 | m.pushExpect(e) 993 | return e 994 | } 995 | 996 | func (m *mock) ExpectScanType(cursor uint64, match string, count int64, keyType string) *ExpectedScan { 997 | e := &ExpectedScan{} 998 | e.cmd = m.factory.ScanType(m.ctx, cursor, match, count, keyType) 999 | m.pushExpect(e) 1000 | return e 1001 | } 1002 | 1003 | func (m *mock) ExpectSScan(key string, cursor uint64, match string, count int64) *ExpectedScan { 1004 | e := &ExpectedScan{} 1005 | e.cmd = m.factory.SScan(m.ctx, key, cursor, match, count) 1006 | m.pushExpect(e) 1007 | return e 1008 | } 1009 | 1010 | func (m *mock) ExpectHScan(key string, cursor uint64, match string, count int64) *ExpectedScan { 1011 | e := &ExpectedScan{} 1012 | e.cmd = m.factory.HScan(m.ctx, key, cursor, match, count) 1013 | m.pushExpect(e) 1014 | return e 1015 | } 1016 | 1017 | func (m *mock) ExpectZScan(key string, cursor uint64, match string, count int64) *ExpectedScan { 1018 | e := &ExpectedScan{} 1019 | e.cmd = m.factory.ZScan(m.ctx, key, cursor, match, count) 1020 | m.pushExpect(e) 1021 | return e 1022 | } 1023 | 1024 | func (m *mock) ExpectHDel(key string, fields ...string) *ExpectedInt { 1025 | e := &ExpectedInt{} 1026 | e.cmd = m.factory.HDel(m.ctx, key, fields...) 1027 | m.pushExpect(e) 1028 | return e 1029 | } 1030 | 1031 | func (m *mock) ExpectHExists(key, field string) *ExpectedBool { 1032 | e := &ExpectedBool{} 1033 | e.cmd = m.factory.HExists(m.ctx, key, field) 1034 | m.pushExpect(e) 1035 | return e 1036 | } 1037 | 1038 | func (m *mock) ExpectHGet(key, field string) *ExpectedString { 1039 | e := &ExpectedString{} 1040 | e.cmd = m.factory.HGet(m.ctx, key, field) 1041 | m.pushExpect(e) 1042 | return e 1043 | } 1044 | 1045 | func (m *mock) ExpectHGetAll(key string) *ExpectedMapStringString { 1046 | e := &ExpectedMapStringString{} 1047 | e.cmd = m.factory.HGetAll(m.ctx, key) 1048 | m.pushExpect(e) 1049 | return e 1050 | } 1051 | 1052 | func (m *mock) ExpectHIncrBy(key, field string, incr int64) *ExpectedInt { 1053 | e := &ExpectedInt{} 1054 | e.cmd = m.factory.HIncrBy(m.ctx, key, field, incr) 1055 | m.pushExpect(e) 1056 | return e 1057 | } 1058 | 1059 | func (m *mock) ExpectHIncrByFloat(key, field string, incr float64) *ExpectedFloat { 1060 | e := &ExpectedFloat{} 1061 | e.cmd = m.factory.HIncrByFloat(m.ctx, key, field, incr) 1062 | m.pushExpect(e) 1063 | return e 1064 | } 1065 | 1066 | func (m *mock) ExpectHKeys(key string) *ExpectedStringSlice { 1067 | e := &ExpectedStringSlice{} 1068 | e.cmd = m.factory.HKeys(m.ctx, key) 1069 | m.pushExpect(e) 1070 | return e 1071 | } 1072 | 1073 | func (m *mock) ExpectHLen(key string) *ExpectedInt { 1074 | e := &ExpectedInt{} 1075 | e.cmd = m.factory.HLen(m.ctx, key) 1076 | m.pushExpect(e) 1077 | return e 1078 | } 1079 | 1080 | func (m *mock) ExpectHMGet(key string, fields ...string) *ExpectedSlice { 1081 | e := &ExpectedSlice{} 1082 | e.cmd = m.factory.HMGet(m.ctx, key, fields...) 1083 | m.pushExpect(e) 1084 | return e 1085 | } 1086 | 1087 | func (m *mock) ExpectHSet(key string, values ...interface{}) *ExpectedInt { 1088 | e := &ExpectedInt{} 1089 | e.cmd = m.factory.HSet(m.ctx, key, values...) 1090 | m.pushExpect(e) 1091 | return e 1092 | } 1093 | 1094 | func (m *mock) ExpectHMSet(key string, values ...interface{}) *ExpectedBool { 1095 | e := &ExpectedBool{} 1096 | e.cmd = m.factory.HMSet(m.ctx, key, values...) 1097 | m.pushExpect(e) 1098 | return e 1099 | } 1100 | 1101 | func (m *mock) ExpectHSetNX(key, field string, value interface{}) *ExpectedBool { 1102 | e := &ExpectedBool{} 1103 | e.cmd = m.factory.HSetNX(m.ctx, key, field, value) 1104 | m.pushExpect(e) 1105 | return e 1106 | } 1107 | 1108 | func (m *mock) ExpectHVals(key string) *ExpectedStringSlice { 1109 | e := &ExpectedStringSlice{} 1110 | e.cmd = m.factory.HVals(m.ctx, key) 1111 | m.pushExpect(e) 1112 | return e 1113 | } 1114 | 1115 | func (m *mock) ExpectHRandField(key string, count int) *ExpectedStringSlice { 1116 | e := &ExpectedStringSlice{} 1117 | e.cmd = m.factory.HRandField(m.ctx, key, count) 1118 | m.pushExpect(e) 1119 | return e 1120 | } 1121 | 1122 | func (m *mock) ExpectHRandFieldWithValues(key string, count int) *ExpectedKeyValueSlice { 1123 | e := &ExpectedKeyValueSlice{} 1124 | e.cmd = m.factory.HRandFieldWithValues(m.ctx, key, count) 1125 | m.pushExpect(e) 1126 | return e 1127 | } 1128 | 1129 | func (m *mock) ExpectBLPop(timeout time.Duration, keys ...string) *ExpectedStringSlice { 1130 | e := &ExpectedStringSlice{} 1131 | e.cmd = m.factory.BLPop(m.ctx, timeout, keys...) 1132 | m.pushExpect(e) 1133 | return e 1134 | } 1135 | 1136 | func (m *mock) ExpectBLMPop(timeout time.Duration, direction string, count int64, keys ...string) *ExpectedKeyValues { 1137 | e := &ExpectedKeyValues{} 1138 | e.cmd = m.factory.BLMPop(m.ctx, timeout, direction, count, keys...) 1139 | m.pushExpect(e) 1140 | return e 1141 | } 1142 | 1143 | func (m *mock) ExpectBRPop(timeout time.Duration, keys ...string) *ExpectedStringSlice { 1144 | e := &ExpectedStringSlice{} 1145 | e.cmd = m.factory.BRPop(m.ctx, timeout, keys...) 1146 | m.pushExpect(e) 1147 | return e 1148 | } 1149 | 1150 | func (m *mock) ExpectBRPopLPush(source, destination string, timeout time.Duration) *ExpectedString { 1151 | e := &ExpectedString{} 1152 | e.cmd = m.factory.BRPopLPush(m.ctx, source, destination, timeout) 1153 | m.pushExpect(e) 1154 | return e 1155 | } 1156 | 1157 | func (m *mock) ExpectLCS(q *redis.LCSQuery) *ExpectedLCS { 1158 | e := &ExpectedLCS{} 1159 | e.cmd = m.factory.LCS(m.ctx, q) 1160 | m.pushExpect(e) 1161 | return e 1162 | } 1163 | 1164 | func (m *mock) ExpectLIndex(key string, index int64) *ExpectedString { 1165 | e := &ExpectedString{} 1166 | e.cmd = m.factory.LIndex(m.ctx, key, index) 1167 | m.pushExpect(e) 1168 | return e 1169 | } 1170 | 1171 | func (m *mock) ExpectLInsert(key, op string, pivot, value interface{}) *ExpectedInt { 1172 | e := &ExpectedInt{} 1173 | e.cmd = m.factory.LInsert(m.ctx, key, op, pivot, value) 1174 | m.pushExpect(e) 1175 | return e 1176 | } 1177 | 1178 | func (m *mock) ExpectLInsertBefore(key string, pivot, value interface{}) *ExpectedInt { 1179 | e := &ExpectedInt{} 1180 | e.cmd = m.factory.LInsertBefore(m.ctx, key, pivot, value) 1181 | m.pushExpect(e) 1182 | return e 1183 | } 1184 | 1185 | func (m *mock) ExpectLInsertAfter(key string, pivot, value interface{}) *ExpectedInt { 1186 | e := &ExpectedInt{} 1187 | e.cmd = m.factory.LInsertAfter(m.ctx, key, pivot, value) 1188 | m.pushExpect(e) 1189 | return e 1190 | } 1191 | 1192 | func (m *mock) ExpectLLen(key string) *ExpectedInt { 1193 | e := &ExpectedInt{} 1194 | e.cmd = m.factory.LLen(m.ctx, key) 1195 | m.pushExpect(e) 1196 | return e 1197 | } 1198 | 1199 | func (m *mock) ExpectLPop(key string) *ExpectedString { 1200 | e := &ExpectedString{} 1201 | e.cmd = m.factory.LPop(m.ctx, key) 1202 | m.pushExpect(e) 1203 | return e 1204 | } 1205 | 1206 | func (m *mock) ExpectLPopCount(key string, count int) *ExpectedStringSlice { 1207 | e := &ExpectedStringSlice{} 1208 | e.cmd = m.factory.LPopCount(m.ctx, key, count) 1209 | m.pushExpect(e) 1210 | return e 1211 | } 1212 | 1213 | func (m *mock) ExpectLMPop(direction string, count int64, keys ...string) *ExpectedKeyValues { 1214 | e := &ExpectedKeyValues{} 1215 | e.cmd = m.factory.LMPop(m.ctx, direction, count, keys...) 1216 | m.pushExpect(e) 1217 | return e 1218 | } 1219 | 1220 | func (m *mock) ExpectLPos(key string, value string, args redis.LPosArgs) *ExpectedInt { 1221 | e := &ExpectedInt{} 1222 | e.cmd = m.factory.LPos(m.ctx, key, value, args) 1223 | m.pushExpect(e) 1224 | return e 1225 | } 1226 | 1227 | func (m *mock) ExpectLPosCount(key string, value string, count int64, args redis.LPosArgs) *ExpectedIntSlice { 1228 | e := &ExpectedIntSlice{} 1229 | e.cmd = m.factory.LPosCount(m.ctx, key, value, count, args) 1230 | m.pushExpect(e) 1231 | return e 1232 | } 1233 | 1234 | func (m *mock) ExpectLPush(key string, values ...interface{}) *ExpectedInt { 1235 | e := &ExpectedInt{} 1236 | e.cmd = m.factory.LPush(m.ctx, key, values...) 1237 | m.pushExpect(e) 1238 | return e 1239 | } 1240 | 1241 | func (m *mock) ExpectLPushX(key string, values ...interface{}) *ExpectedInt { 1242 | e := &ExpectedInt{} 1243 | e.cmd = m.factory.LPushX(m.ctx, key, values...) 1244 | m.pushExpect(e) 1245 | return e 1246 | } 1247 | 1248 | func (m *mock) ExpectLRange(key string, start, stop int64) *ExpectedStringSlice { 1249 | e := &ExpectedStringSlice{} 1250 | e.cmd = m.factory.LRange(m.ctx, key, start, stop) 1251 | m.pushExpect(e) 1252 | return e 1253 | } 1254 | 1255 | func (m *mock) ExpectLRem(key string, count int64, value interface{}) *ExpectedInt { 1256 | e := &ExpectedInt{} 1257 | e.cmd = m.factory.LRem(m.ctx, key, count, value) 1258 | m.pushExpect(e) 1259 | return e 1260 | } 1261 | 1262 | func (m *mock) ExpectLSet(key string, index int64, value interface{}) *ExpectedStatus { 1263 | e := &ExpectedStatus{} 1264 | e.cmd = m.factory.LSet(m.ctx, key, index, value) 1265 | m.pushExpect(e) 1266 | return e 1267 | } 1268 | 1269 | func (m *mock) ExpectLTrim(key string, start, stop int64) *ExpectedStatus { 1270 | e := &ExpectedStatus{} 1271 | e.cmd = m.factory.LTrim(m.ctx, key, start, stop) 1272 | m.pushExpect(e) 1273 | return e 1274 | } 1275 | 1276 | func (m *mock) ExpectRPop(key string) *ExpectedString { 1277 | e := &ExpectedString{} 1278 | e.cmd = m.factory.RPop(m.ctx, key) 1279 | m.pushExpect(e) 1280 | return e 1281 | } 1282 | 1283 | func (m *mock) ExpectRPopCount(key string, count int) *ExpectedStringSlice { 1284 | e := &ExpectedStringSlice{} 1285 | e.cmd = m.factory.RPopCount(m.ctx, key, count) 1286 | m.pushExpect(e) 1287 | return e 1288 | } 1289 | 1290 | func (m *mock) ExpectRPopLPush(source, destination string) *ExpectedString { 1291 | e := &ExpectedString{} 1292 | e.cmd = m.factory.RPopLPush(m.ctx, source, destination) 1293 | m.pushExpect(e) 1294 | return e 1295 | } 1296 | 1297 | func (m *mock) ExpectRPush(key string, values ...interface{}) *ExpectedInt { 1298 | e := &ExpectedInt{} 1299 | e.cmd = m.factory.RPush(m.ctx, key, values...) 1300 | m.pushExpect(e) 1301 | return e 1302 | } 1303 | 1304 | func (m *mock) ExpectRPushX(key string, values ...interface{}) *ExpectedInt { 1305 | e := &ExpectedInt{} 1306 | e.cmd = m.factory.RPushX(m.ctx, key, values...) 1307 | m.pushExpect(e) 1308 | return e 1309 | } 1310 | 1311 | func (m *mock) ExpectLMove(source, destination, srcpos, destpos string) *ExpectedString { 1312 | e := &ExpectedString{} 1313 | e.cmd = m.factory.LMove(m.ctx, source, destination, srcpos, destpos) 1314 | m.pushExpect(e) 1315 | return e 1316 | } 1317 | 1318 | func (m *mock) ExpectBLMove(source, destination, srcpos, destpos string, timeout time.Duration) *ExpectedString { 1319 | e := &ExpectedString{} 1320 | e.cmd = m.factory.BLMove(m.ctx, source, destination, srcpos, destpos, timeout) 1321 | m.pushExpect(e) 1322 | return e 1323 | } 1324 | 1325 | // -------------------------------------------------------------- 1326 | 1327 | func (m *mock) ExpectSAdd(key string, members ...interface{}) *ExpectedInt { 1328 | e := &ExpectedInt{} 1329 | e.cmd = m.factory.SAdd(m.ctx, key, members...) 1330 | m.pushExpect(e) 1331 | return e 1332 | } 1333 | 1334 | func (m *mock) ExpectSCard(key string) *ExpectedInt { 1335 | e := &ExpectedInt{} 1336 | e.cmd = m.factory.SCard(m.ctx, key) 1337 | m.pushExpect(e) 1338 | return e 1339 | } 1340 | 1341 | func (m *mock) ExpectSDiff(keys ...string) *ExpectedStringSlice { 1342 | e := &ExpectedStringSlice{} 1343 | e.cmd = m.factory.SDiff(m.ctx, keys...) 1344 | m.pushExpect(e) 1345 | return e 1346 | } 1347 | 1348 | func (m *mock) ExpectSDiffStore(destination string, keys ...string) *ExpectedInt { 1349 | e := &ExpectedInt{} 1350 | e.cmd = m.factory.SDiffStore(m.ctx, destination, keys...) 1351 | m.pushExpect(e) 1352 | return e 1353 | } 1354 | 1355 | func (m *mock) ExpectSInter(keys ...string) *ExpectedStringSlice { 1356 | e := &ExpectedStringSlice{} 1357 | e.cmd = m.factory.SInter(m.ctx, keys...) 1358 | m.pushExpect(e) 1359 | return e 1360 | } 1361 | 1362 | func (m *mock) ExpectSInterCard(limit int64, keys ...string) *ExpectedInt { 1363 | e := &ExpectedInt{} 1364 | e.cmd = m.factory.SInterCard(m.ctx, limit, keys...) 1365 | m.pushExpect(e) 1366 | return e 1367 | } 1368 | 1369 | func (m *mock) ExpectSInterStore(destination string, keys ...string) *ExpectedInt { 1370 | e := &ExpectedInt{} 1371 | e.cmd = m.factory.SInterStore(m.ctx, destination, keys...) 1372 | m.pushExpect(e) 1373 | return e 1374 | } 1375 | 1376 | func (m *mock) ExpectSIsMember(key string, member interface{}) *ExpectedBool { 1377 | e := &ExpectedBool{} 1378 | e.cmd = m.factory.SIsMember(m.ctx, key, member) 1379 | m.pushExpect(e) 1380 | return e 1381 | } 1382 | 1383 | func (m *mock) ExpectSMIsMember(key string, members ...interface{}) *ExpectedBoolSlice { 1384 | e := &ExpectedBoolSlice{} 1385 | e.cmd = m.factory.SMIsMember(m.ctx, key, members...) 1386 | m.pushExpect(e) 1387 | return e 1388 | } 1389 | 1390 | func (m *mock) ExpectSMembers(key string) *ExpectedStringSlice { 1391 | e := &ExpectedStringSlice{} 1392 | e.cmd = m.factory.SMembers(m.ctx, key) 1393 | m.pushExpect(e) 1394 | return e 1395 | } 1396 | 1397 | func (m *mock) ExpectSMembersMap(key string) *ExpectedStringStructMap { 1398 | e := &ExpectedStringStructMap{} 1399 | e.cmd = m.factory.SMembersMap(m.ctx, key) 1400 | m.pushExpect(e) 1401 | return e 1402 | } 1403 | 1404 | func (m *mock) ExpectSMove(source, destination string, member interface{}) *ExpectedBool { 1405 | e := &ExpectedBool{} 1406 | e.cmd = m.factory.SMove(m.ctx, source, destination, member) 1407 | m.pushExpect(e) 1408 | return e 1409 | } 1410 | 1411 | func (m *mock) ExpectSPop(key string) *ExpectedString { 1412 | e := &ExpectedString{} 1413 | e.cmd = m.factory.SPop(m.ctx, key) 1414 | m.pushExpect(e) 1415 | return e 1416 | } 1417 | 1418 | func (m *mock) ExpectSPopN(key string, count int64) *ExpectedStringSlice { 1419 | e := &ExpectedStringSlice{} 1420 | e.cmd = m.factory.SPopN(m.ctx, key, count) 1421 | m.pushExpect(e) 1422 | return e 1423 | } 1424 | 1425 | func (m *mock) ExpectSRandMember(key string) *ExpectedString { 1426 | e := &ExpectedString{} 1427 | e.cmd = m.factory.SRandMember(m.ctx, key) 1428 | m.pushExpect(e) 1429 | return e 1430 | } 1431 | 1432 | func (m *mock) ExpectSRandMemberN(key string, count int64) *ExpectedStringSlice { 1433 | e := &ExpectedStringSlice{} 1434 | e.cmd = m.factory.SRandMemberN(m.ctx, key, count) 1435 | m.pushExpect(e) 1436 | return e 1437 | } 1438 | 1439 | func (m *mock) ExpectSRem(key string, members ...interface{}) *ExpectedInt { 1440 | e := &ExpectedInt{} 1441 | e.cmd = m.factory.SRem(m.ctx, key, members...) 1442 | m.pushExpect(e) 1443 | return e 1444 | } 1445 | 1446 | func (m *mock) ExpectSUnion(keys ...string) *ExpectedStringSlice { 1447 | e := &ExpectedStringSlice{} 1448 | e.cmd = m.factory.SUnion(m.ctx, keys...) 1449 | m.pushExpect(e) 1450 | return e 1451 | } 1452 | 1453 | func (m *mock) ExpectSUnionStore(destination string, keys ...string) *ExpectedInt { 1454 | e := &ExpectedInt{} 1455 | e.cmd = m.factory.SUnionStore(m.ctx, destination, keys...) 1456 | m.pushExpect(e) 1457 | return e 1458 | } 1459 | 1460 | func (m *mock) ExpectXAdd(a *redis.XAddArgs) *ExpectedString { 1461 | e := &ExpectedString{} 1462 | e.cmd = m.factory.XAdd(m.ctx, a) 1463 | m.pushExpect(e) 1464 | return e 1465 | } 1466 | 1467 | func (m *mock) ExpectXDel(stream string, ids ...string) *ExpectedInt { 1468 | e := &ExpectedInt{} 1469 | e.cmd = m.factory.XDel(m.ctx, stream, ids...) 1470 | m.pushExpect(e) 1471 | return e 1472 | } 1473 | 1474 | func (m *mock) ExpectXLen(stream string) *ExpectedInt { 1475 | e := &ExpectedInt{} 1476 | e.cmd = m.factory.XLen(m.ctx, stream) 1477 | m.pushExpect(e) 1478 | return e 1479 | } 1480 | 1481 | func (m *mock) ExpectXRange(stream, start, stop string) *ExpectedXMessageSlice { 1482 | e := &ExpectedXMessageSlice{} 1483 | e.cmd = m.factory.XRange(m.ctx, stream, start, stop) 1484 | m.pushExpect(e) 1485 | return e 1486 | } 1487 | 1488 | func (m *mock) ExpectXRangeN(stream, start, stop string, count int64) *ExpectedXMessageSlice { 1489 | e := &ExpectedXMessageSlice{} 1490 | e.cmd = m.factory.XRangeN(m.ctx, stream, start, stop, count) 1491 | m.pushExpect(e) 1492 | return e 1493 | } 1494 | 1495 | func (m *mock) ExpectXRevRange(stream string, start, stop string) *ExpectedXMessageSlice { 1496 | e := &ExpectedXMessageSlice{} 1497 | e.cmd = m.factory.XRevRange(m.ctx, stream, start, stop) 1498 | m.pushExpect(e) 1499 | return e 1500 | } 1501 | 1502 | func (m *mock) ExpectXRevRangeN(stream string, start, stop string, count int64) *ExpectedXMessageSlice { 1503 | e := &ExpectedXMessageSlice{} 1504 | e.cmd = m.factory.XRevRangeN(m.ctx, stream, start, stop, count) 1505 | m.pushExpect(e) 1506 | return e 1507 | } 1508 | 1509 | func (m *mock) ExpectXRead(a *redis.XReadArgs) *ExpectedXStreamSlice { 1510 | e := &ExpectedXStreamSlice{} 1511 | e.cmd = m.factory.XRead(m.ctx, a) 1512 | m.pushExpect(e) 1513 | return e 1514 | } 1515 | 1516 | func (m *mock) ExpectXReadStreams(streams ...string) *ExpectedXStreamSlice { 1517 | e := &ExpectedXStreamSlice{} 1518 | e.cmd = m.factory.XReadStreams(m.ctx, streams...) 1519 | m.pushExpect(e) 1520 | return e 1521 | } 1522 | 1523 | func (m *mock) ExpectXGroupCreate(stream, group, start string) *ExpectedStatus { 1524 | e := &ExpectedStatus{} 1525 | e.cmd = m.factory.XGroupCreate(m.ctx, stream, group, start) 1526 | m.pushExpect(e) 1527 | return e 1528 | } 1529 | 1530 | func (m *mock) ExpectXGroupCreateMkStream(stream, group, start string) *ExpectedStatus { 1531 | e := &ExpectedStatus{} 1532 | e.cmd = m.factory.XGroupCreateMkStream(m.ctx, stream, group, start) 1533 | m.pushExpect(e) 1534 | return e 1535 | } 1536 | 1537 | func (m *mock) ExpectXGroupSetID(stream, group, start string) *ExpectedStatus { 1538 | e := &ExpectedStatus{} 1539 | e.cmd = m.factory.XGroupSetID(m.ctx, stream, group, start) 1540 | m.pushExpect(e) 1541 | return e 1542 | } 1543 | 1544 | func (m *mock) ExpectXGroupDestroy(stream, group string) *ExpectedInt { 1545 | e := &ExpectedInt{} 1546 | e.cmd = m.factory.XGroupDestroy(m.ctx, stream, group) 1547 | m.pushExpect(e) 1548 | return e 1549 | } 1550 | 1551 | func (m *mock) ExpectXGroupCreateConsumer(stream, group, consumer string) *ExpectedInt { 1552 | e := &ExpectedInt{} 1553 | e.cmd = m.factory.XGroupCreateConsumer(m.ctx, stream, group, consumer) 1554 | m.pushExpect(e) 1555 | return e 1556 | } 1557 | 1558 | func (m *mock) ExpectXGroupDelConsumer(stream, group, consumer string) *ExpectedInt { 1559 | e := &ExpectedInt{} 1560 | e.cmd = m.factory.XGroupDelConsumer(m.ctx, stream, group, consumer) 1561 | m.pushExpect(e) 1562 | return e 1563 | } 1564 | 1565 | func (m *mock) ExpectXReadGroup(a *redis.XReadGroupArgs) *ExpectedXStreamSlice { 1566 | e := &ExpectedXStreamSlice{} 1567 | e.cmd = m.factory.XReadGroup(m.ctx, a) 1568 | m.pushExpect(e) 1569 | return e 1570 | } 1571 | 1572 | func (m *mock) ExpectXAck(stream, group string, ids ...string) *ExpectedInt { 1573 | e := &ExpectedInt{} 1574 | e.cmd = m.factory.XAck(m.ctx, stream, group, ids...) 1575 | m.pushExpect(e) 1576 | return e 1577 | } 1578 | 1579 | func (m *mock) ExpectXPending(stream, group string) *ExpectedXPending { 1580 | e := &ExpectedXPending{} 1581 | e.cmd = m.factory.XPending(m.ctx, stream, group) 1582 | m.pushExpect(e) 1583 | return e 1584 | } 1585 | 1586 | func (m *mock) ExpectXPendingExt(a *redis.XPendingExtArgs) *ExpectedXPendingExt { 1587 | e := &ExpectedXPendingExt{} 1588 | e.cmd = m.factory.XPendingExt(m.ctx, a) 1589 | m.pushExpect(e) 1590 | return e 1591 | } 1592 | 1593 | func (m *mock) ExpectXClaim(a *redis.XClaimArgs) *ExpectedXMessageSlice { 1594 | e := &ExpectedXMessageSlice{} 1595 | e.cmd = m.factory.XClaim(m.ctx, a) 1596 | m.pushExpect(e) 1597 | return e 1598 | } 1599 | 1600 | func (m *mock) ExpectXClaimJustID(a *redis.XClaimArgs) *ExpectedStringSlice { 1601 | e := &ExpectedStringSlice{} 1602 | e.cmd = m.factory.XClaimJustID(m.ctx, a) 1603 | m.pushExpect(e) 1604 | return e 1605 | } 1606 | 1607 | func (m *mock) ExpectXAutoClaim(a *redis.XAutoClaimArgs) *ExpectedXAutoClaim { 1608 | e := &ExpectedXAutoClaim{} 1609 | e.cmd = m.factory.XAutoClaim(m.ctx, a) 1610 | m.pushExpect(e) 1611 | return e 1612 | } 1613 | 1614 | func (m *mock) ExpectXAutoClaimJustID(a *redis.XAutoClaimArgs) *ExpectedXAutoClaimJustID { 1615 | e := &ExpectedXAutoClaimJustID{} 1616 | e.cmd = m.factory.XAutoClaimJustID(m.ctx, a) 1617 | m.pushExpect(e) 1618 | return e 1619 | } 1620 | 1621 | func (m *mock) ExpectXTrimMaxLen(key string, maxLen int64) *ExpectedInt { 1622 | e := &ExpectedInt{} 1623 | e.cmd = m.factory.XTrimMaxLen(m.ctx, key, maxLen) 1624 | m.pushExpect(e) 1625 | return e 1626 | } 1627 | 1628 | func (m *mock) ExpectXTrimMaxLenApprox(key string, maxLen, limit int64) *ExpectedInt { 1629 | e := &ExpectedInt{} 1630 | e.cmd = m.factory.XTrimMaxLenApprox(m.ctx, key, maxLen, limit) 1631 | m.pushExpect(e) 1632 | return e 1633 | } 1634 | 1635 | func (m *mock) ExpectXTrimMinID(key string, minID string) *ExpectedInt { 1636 | e := &ExpectedInt{} 1637 | e.cmd = m.factory.XTrimMinID(m.ctx, key, minID) 1638 | m.pushExpect(e) 1639 | return e 1640 | } 1641 | 1642 | func (m *mock) ExpectXTrimMinIDApprox(key string, minID string, limit int64) *ExpectedInt { 1643 | e := &ExpectedInt{} 1644 | e.cmd = m.factory.XTrimMinIDApprox(m.ctx, key, minID, limit) 1645 | m.pushExpect(e) 1646 | return e 1647 | } 1648 | 1649 | func (m *mock) ExpectXInfoGroups(key string) *ExpectedXInfoGroups { 1650 | e := &ExpectedXInfoGroups{} 1651 | e.cmd = m.factory.XInfoGroups(m.ctx, key) 1652 | m.pushExpect(e) 1653 | return e 1654 | } 1655 | 1656 | func (m *mock) ExpectXInfoStream(key string) *ExpectedXInfoStream { 1657 | e := &ExpectedXInfoStream{} 1658 | e.cmd = m.factory.XInfoStream(m.ctx, key) 1659 | m.pushExpect(e) 1660 | return e 1661 | } 1662 | 1663 | func (m *mock) ExpectXInfoStreamFull(key string, count int) *ExpectedXInfoStreamFull { 1664 | e := &ExpectedXInfoStreamFull{} 1665 | e.cmd = m.factory.XInfoStreamFull(m.ctx, key, count) 1666 | m.pushExpect(e) 1667 | return e 1668 | } 1669 | 1670 | func (m *mock) ExpectXInfoConsumers(key string, group string) *ExpectedXInfoConsumers { 1671 | e := &ExpectedXInfoConsumers{} 1672 | e.cmd = m.factory.XInfoConsumers(m.ctx, key, group) 1673 | m.pushExpect(e) 1674 | return e 1675 | } 1676 | 1677 | // ------------------------------------------------------------------------------------------ 1678 | 1679 | func (m *mock) ExpectBZPopMax(timeout time.Duration, keys ...string) *ExpectedZWithKey { 1680 | e := &ExpectedZWithKey{} 1681 | e.cmd = m.factory.BZPopMax(m.ctx, timeout, keys...) 1682 | m.pushExpect(e) 1683 | return e 1684 | } 1685 | 1686 | func (m *mock) ExpectBZPopMin(timeout time.Duration, keys ...string) *ExpectedZWithKey { 1687 | e := &ExpectedZWithKey{} 1688 | e.cmd = m.factory.BZPopMin(m.ctx, timeout, keys...) 1689 | m.pushExpect(e) 1690 | return e 1691 | } 1692 | 1693 | func (m *mock) ExpectBZMPop(timeout time.Duration, order string, count int64, keys ...string) *ExpectedZSliceWithKey { 1694 | e := &ExpectedZSliceWithKey{} 1695 | e.cmd = m.factory.BZMPop(m.ctx, timeout, order, count, keys...) 1696 | m.pushExpect(e) 1697 | return e 1698 | } 1699 | 1700 | func (m *mock) ExpectZAdd(key string, members ...redis.Z) *ExpectedInt { 1701 | e := &ExpectedInt{} 1702 | e.cmd = m.factory.ZAdd(m.ctx, key, members...) 1703 | m.pushExpect(e) 1704 | return e 1705 | } 1706 | 1707 | func (m *mock) ExpectZAddLT(key string, members ...redis.Z) *ExpectedInt { 1708 | e := &ExpectedInt{} 1709 | e.cmd = m.factory.ZAddLT(m.ctx, key, members...) 1710 | m.pushExpect(e) 1711 | return e 1712 | } 1713 | 1714 | func (m *mock) ExpectZAddGT(key string, members ...redis.Z) *ExpectedInt { 1715 | e := &ExpectedInt{} 1716 | e.cmd = m.factory.ZAddGT(m.ctx, key, members...) 1717 | m.pushExpect(e) 1718 | return e 1719 | } 1720 | 1721 | func (m *mock) ExpectZAddNX(key string, members ...redis.Z) *ExpectedInt { 1722 | e := &ExpectedInt{} 1723 | e.cmd = m.factory.ZAddNX(m.ctx, key, members...) 1724 | m.pushExpect(e) 1725 | return e 1726 | } 1727 | 1728 | func (m *mock) ExpectZAddXX(key string, members ...redis.Z) *ExpectedInt { 1729 | e := &ExpectedInt{} 1730 | e.cmd = m.factory.ZAddXX(m.ctx, key, members...) 1731 | m.pushExpect(e) 1732 | return e 1733 | } 1734 | 1735 | func (m *mock) ExpectZAddArgs(key string, args redis.ZAddArgs) *ExpectedInt { 1736 | e := &ExpectedInt{} 1737 | e.cmd = m.factory.ZAddArgs(m.ctx, key, args) 1738 | m.pushExpect(e) 1739 | return e 1740 | } 1741 | 1742 | func (m *mock) ExpectZAddArgsIncr(key string, args redis.ZAddArgs) *ExpectedFloat { 1743 | e := &ExpectedFloat{} 1744 | e.cmd = m.factory.ZAddArgsIncr(m.ctx, key, args) 1745 | m.pushExpect(e) 1746 | return e 1747 | } 1748 | 1749 | func (m *mock) ExpectZCard(key string) *ExpectedInt { 1750 | e := &ExpectedInt{} 1751 | e.cmd = m.factory.ZCard(m.ctx, key) 1752 | m.pushExpect(e) 1753 | return e 1754 | } 1755 | 1756 | func (m *mock) ExpectZCount(key, min, max string) *ExpectedInt { 1757 | e := &ExpectedInt{} 1758 | e.cmd = m.factory.ZCount(m.ctx, key, min, max) 1759 | m.pushExpect(e) 1760 | return e 1761 | } 1762 | 1763 | func (m *mock) ExpectZLexCount(key, min, max string) *ExpectedInt { 1764 | e := &ExpectedInt{} 1765 | e.cmd = m.factory.ZLexCount(m.ctx, key, min, max) 1766 | m.pushExpect(e) 1767 | return e 1768 | } 1769 | 1770 | func (m *mock) ExpectZIncrBy(key string, increment float64, member string) *ExpectedFloat { 1771 | e := &ExpectedFloat{} 1772 | e.cmd = m.factory.ZIncrBy(m.ctx, key, increment, member) 1773 | m.pushExpect(e) 1774 | return e 1775 | } 1776 | 1777 | func (m *mock) ExpectZInter(store *redis.ZStore) *ExpectedStringSlice { 1778 | e := &ExpectedStringSlice{} 1779 | e.cmd = m.factory.ZInter(m.ctx, store) 1780 | m.pushExpect(e) 1781 | return e 1782 | } 1783 | 1784 | func (m *mock) ExpectZInterWithScores(store *redis.ZStore) *ExpectedZSlice { 1785 | e := &ExpectedZSlice{} 1786 | e.cmd = m.factory.ZInterWithScores(m.ctx, store) 1787 | m.pushExpect(e) 1788 | return e 1789 | } 1790 | 1791 | func (m *mock) ExpectZInterCard(limit int64, keys ...string) *ExpectedInt { 1792 | e := &ExpectedInt{} 1793 | e.cmd = m.factory.ZInterCard(m.ctx, limit, keys...) 1794 | m.pushExpect(e) 1795 | return e 1796 | } 1797 | 1798 | func (m *mock) ExpectZInterStore(destination string, store *redis.ZStore) *ExpectedInt { 1799 | e := &ExpectedInt{} 1800 | e.cmd = m.factory.ZInterStore(m.ctx, destination, store) 1801 | m.pushExpect(e) 1802 | return e 1803 | } 1804 | 1805 | func (m *mock) ExpectZMPop(order string, count int64, keys ...string) *ExpectedZSliceWithKey { 1806 | e := &ExpectedZSliceWithKey{} 1807 | e.cmd = m.factory.ZMPop(m.ctx, order, count, keys...) 1808 | m.pushExpect(e) 1809 | return e 1810 | } 1811 | 1812 | func (m *mock) ExpectZMScore(key string, members ...string) *ExpectedFloatSlice { 1813 | e := &ExpectedFloatSlice{} 1814 | e.cmd = m.factory.ZMScore(m.ctx, key, members...) 1815 | m.pushExpect(e) 1816 | return e 1817 | } 1818 | 1819 | func (m *mock) ExpectZPopMax(key string, count ...int64) *ExpectedZSlice { 1820 | e := &ExpectedZSlice{} 1821 | e.cmd = m.factory.ZPopMax(m.ctx, key, count...) 1822 | m.pushExpect(e) 1823 | return e 1824 | } 1825 | 1826 | func (m *mock) ExpectZPopMin(key string, count ...int64) *ExpectedZSlice { 1827 | e := &ExpectedZSlice{} 1828 | e.cmd = m.factory.ZPopMin(m.ctx, key, count...) 1829 | m.pushExpect(e) 1830 | return e 1831 | } 1832 | 1833 | func (m *mock) ExpectZRange(key string, start, stop int64) *ExpectedStringSlice { 1834 | e := &ExpectedStringSlice{} 1835 | e.cmd = m.factory.ZRange(m.ctx, key, start, stop) 1836 | m.pushExpect(e) 1837 | return e 1838 | } 1839 | 1840 | func (m *mock) ExpectZRangeWithScores(key string, start, stop int64) *ExpectedZSlice { 1841 | e := &ExpectedZSlice{} 1842 | e.cmd = m.factory.ZRangeWithScores(m.ctx, key, start, stop) 1843 | m.pushExpect(e) 1844 | return e 1845 | } 1846 | 1847 | func (m *mock) ExpectZRangeByScore(key string, opt *redis.ZRangeBy) *ExpectedStringSlice { 1848 | e := &ExpectedStringSlice{} 1849 | e.cmd = m.factory.ZRangeByScore(m.ctx, key, opt) 1850 | m.pushExpect(e) 1851 | return e 1852 | } 1853 | 1854 | func (m *mock) ExpectZRangeByLex(key string, opt *redis.ZRangeBy) *ExpectedStringSlice { 1855 | e := &ExpectedStringSlice{} 1856 | e.cmd = m.factory.ZRangeByLex(m.ctx, key, opt) 1857 | m.pushExpect(e) 1858 | return e 1859 | } 1860 | 1861 | func (m *mock) ExpectZRangeByScoreWithScores(key string, opt *redis.ZRangeBy) *ExpectedZSlice { 1862 | e := &ExpectedZSlice{} 1863 | e.cmd = m.factory.ZRangeByScoreWithScores(m.ctx, key, opt) 1864 | m.pushExpect(e) 1865 | return e 1866 | } 1867 | 1868 | func (m *mock) ExpectZRangeArgs(z redis.ZRangeArgs) *ExpectedStringSlice { 1869 | e := &ExpectedStringSlice{} 1870 | e.cmd = m.factory.ZRangeArgs(m.ctx, z) 1871 | m.pushExpect(e) 1872 | return e 1873 | } 1874 | 1875 | func (m *mock) ExpectZRangeArgsWithScores(z redis.ZRangeArgs) *ExpectedZSlice { 1876 | e := &ExpectedZSlice{} 1877 | e.cmd = m.factory.ZRangeArgsWithScores(m.ctx, z) 1878 | m.pushExpect(e) 1879 | return e 1880 | } 1881 | 1882 | func (m *mock) ExpectZRangeStore(dst string, z redis.ZRangeArgs) *ExpectedInt { 1883 | e := &ExpectedInt{} 1884 | e.cmd = m.factory.ZRangeStore(m.ctx, dst, z) 1885 | m.pushExpect(e) 1886 | return e 1887 | } 1888 | 1889 | func (m *mock) ExpectZRank(key, member string) *ExpectedInt { 1890 | e := &ExpectedInt{} 1891 | e.cmd = m.factory.ZRank(m.ctx, key, member) 1892 | m.pushExpect(e) 1893 | return e 1894 | } 1895 | 1896 | func (m *mock) ExpectZRem(key string, members ...interface{}) *ExpectedInt { 1897 | e := &ExpectedInt{} 1898 | e.cmd = m.factory.ZRem(m.ctx, key, members...) 1899 | m.pushExpect(e) 1900 | return e 1901 | } 1902 | 1903 | func (m *mock) ExpectZRemRangeByRank(key string, start, stop int64) *ExpectedInt { 1904 | e := &ExpectedInt{} 1905 | e.cmd = m.factory.ZRemRangeByRank(m.ctx, key, start, stop) 1906 | m.pushExpect(e) 1907 | return e 1908 | } 1909 | 1910 | func (m *mock) ExpectZRemRangeByScore(key, min, max string) *ExpectedInt { 1911 | e := &ExpectedInt{} 1912 | e.cmd = m.factory.ZRemRangeByScore(m.ctx, key, min, max) 1913 | m.pushExpect(e) 1914 | return e 1915 | } 1916 | 1917 | func (m *mock) ExpectZRemRangeByLex(key, min, max string) *ExpectedInt { 1918 | e := &ExpectedInt{} 1919 | e.cmd = m.factory.ZRemRangeByLex(m.ctx, key, min, max) 1920 | m.pushExpect(e) 1921 | return e 1922 | } 1923 | 1924 | func (m *mock) ExpectZRevRange(key string, start, stop int64) *ExpectedStringSlice { 1925 | e := &ExpectedStringSlice{} 1926 | e.cmd = m.factory.ZRevRange(m.ctx, key, start, stop) 1927 | m.pushExpect(e) 1928 | return e 1929 | } 1930 | 1931 | func (m *mock) ExpectZRevRangeWithScores(key string, start, stop int64) *ExpectedZSlice { 1932 | e := &ExpectedZSlice{} 1933 | e.cmd = m.factory.ZRevRangeWithScores(m.ctx, key, start, stop) 1934 | m.pushExpect(e) 1935 | return e 1936 | } 1937 | 1938 | func (m *mock) ExpectZRevRangeByScore(key string, opt *redis.ZRangeBy) *ExpectedStringSlice { 1939 | e := &ExpectedStringSlice{} 1940 | e.cmd = m.factory.ZRevRangeByScore(m.ctx, key, opt) 1941 | m.pushExpect(e) 1942 | return e 1943 | } 1944 | 1945 | func (m *mock) ExpectZRevRangeByLex(key string, opt *redis.ZRangeBy) *ExpectedStringSlice { 1946 | e := &ExpectedStringSlice{} 1947 | e.cmd = m.factory.ZRevRangeByLex(m.ctx, key, opt) 1948 | m.pushExpect(e) 1949 | return e 1950 | } 1951 | 1952 | func (m *mock) ExpectZRevRangeByScoreWithScores(key string, opt *redis.ZRangeBy) *ExpectedZSlice { 1953 | e := &ExpectedZSlice{} 1954 | e.cmd = m.factory.ZRevRangeByScoreWithScores(m.ctx, key, opt) 1955 | m.pushExpect(e) 1956 | return e 1957 | } 1958 | 1959 | func (m *mock) ExpectZRevRank(key, member string) *ExpectedInt { 1960 | e := &ExpectedInt{} 1961 | e.cmd = m.factory.ZRevRank(m.ctx, key, member) 1962 | m.pushExpect(e) 1963 | return e 1964 | } 1965 | 1966 | func (m *mock) ExpectZScore(key, member string) *ExpectedFloat { 1967 | e := &ExpectedFloat{} 1968 | e.cmd = m.factory.ZScore(m.ctx, key, member) 1969 | m.pushExpect(e) 1970 | return e 1971 | } 1972 | 1973 | func (m *mock) ExpectZUnionStore(dest string, store *redis.ZStore) *ExpectedInt { 1974 | e := &ExpectedInt{} 1975 | e.cmd = m.factory.ZUnionStore(m.ctx, dest, store) 1976 | m.pushExpect(e) 1977 | return e 1978 | } 1979 | 1980 | func (m *mock) ExpectZRandMember(key string, count int) *ExpectedStringSlice { 1981 | e := &ExpectedStringSlice{} 1982 | e.cmd = m.factory.ZRandMember(m.ctx, key, count) 1983 | m.pushExpect(e) 1984 | return e 1985 | } 1986 | 1987 | func (m *mock) ExpectZRandMemberWithScores(key string, count int) *ExpectedZSlice { 1988 | e := &ExpectedZSlice{} 1989 | e.cmd = m.factory.ZRandMemberWithScores(m.ctx, key, count) 1990 | m.pushExpect(e) 1991 | return e 1992 | } 1993 | 1994 | func (m *mock) ExpectZUnion(store redis.ZStore) *ExpectedStringSlice { 1995 | e := &ExpectedStringSlice{} 1996 | e.cmd = m.factory.ZUnion(m.ctx, store) 1997 | m.pushExpect(e) 1998 | return e 1999 | } 2000 | 2001 | func (m *mock) ExpectZUnionWithScores(store redis.ZStore) *ExpectedZSlice { 2002 | e := &ExpectedZSlice{} 2003 | e.cmd = m.factory.ZUnionWithScores(m.ctx, store) 2004 | m.pushExpect(e) 2005 | return e 2006 | } 2007 | 2008 | func (m *mock) ExpectZDiff(keys ...string) *ExpectedStringSlice { 2009 | e := &ExpectedStringSlice{} 2010 | e.cmd = m.factory.ZDiff(m.ctx, keys...) 2011 | m.pushExpect(e) 2012 | return e 2013 | } 2014 | 2015 | func (m *mock) ExpectZDiffWithScores(keys ...string) *ExpectedZSlice { 2016 | e := &ExpectedZSlice{} 2017 | e.cmd = m.factory.ZDiffWithScores(m.ctx, keys...) 2018 | m.pushExpect(e) 2019 | return e 2020 | } 2021 | 2022 | func (m *mock) ExpectZDiffStore(destination string, keys ...string) *ExpectedInt { 2023 | e := &ExpectedInt{} 2024 | e.cmd = m.factory.ZDiffStore(m.ctx, destination, keys...) 2025 | m.pushExpect(e) 2026 | return e 2027 | } 2028 | 2029 | // ---------------------------------------------------------------------------- 2030 | 2031 | func (m *mock) ExpectPFAdd(key string, els ...interface{}) *ExpectedInt { 2032 | e := &ExpectedInt{} 2033 | e.cmd = m.factory.PFAdd(m.ctx, key, els...) 2034 | m.pushExpect(e) 2035 | return e 2036 | } 2037 | 2038 | func (m *mock) ExpectPFCount(keys ...string) *ExpectedInt { 2039 | e := &ExpectedInt{} 2040 | e.cmd = m.factory.PFCount(m.ctx, keys...) 2041 | m.pushExpect(e) 2042 | return e 2043 | } 2044 | 2045 | func (m *mock) ExpectPFMerge(dest string, keys ...string) *ExpectedStatus { 2046 | e := &ExpectedStatus{} 2047 | e.cmd = m.factory.PFMerge(m.ctx, dest, keys...) 2048 | m.pushExpect(e) 2049 | return e 2050 | } 2051 | 2052 | func (m *mock) ExpectBgRewriteAOF() *ExpectedStatus { 2053 | e := &ExpectedStatus{} 2054 | e.cmd = m.factory.BgRewriteAOF(m.ctx) 2055 | m.pushExpect(e) 2056 | return e 2057 | } 2058 | 2059 | func (m *mock) ExpectBgSave() *ExpectedStatus { 2060 | e := &ExpectedStatus{} 2061 | e.cmd = m.factory.BgSave(m.ctx) 2062 | m.pushExpect(e) 2063 | return e 2064 | } 2065 | 2066 | func (m *mock) ExpectClientKill(ipPort string) *ExpectedStatus { 2067 | e := &ExpectedStatus{} 2068 | e.cmd = m.factory.ClientKill(m.ctx, ipPort) 2069 | m.pushExpect(e) 2070 | return e 2071 | } 2072 | 2073 | func (m *mock) ExpectClientKillByFilter(keys ...string) *ExpectedInt { 2074 | e := &ExpectedInt{} 2075 | e.cmd = m.factory.ClientKillByFilter(m.ctx, keys...) 2076 | m.pushExpect(e) 2077 | return e 2078 | } 2079 | 2080 | func (m *mock) ExpectClientList() *ExpectedString { 2081 | e := &ExpectedString{} 2082 | e.cmd = m.factory.ClientList(m.ctx) 2083 | m.pushExpect(e) 2084 | return e 2085 | } 2086 | 2087 | func (m *mock) ExpectClientPause(dur time.Duration) *ExpectedBool { 2088 | e := &ExpectedBool{} 2089 | e.cmd = m.factory.ClientPause(m.ctx, dur) 2090 | m.pushExpect(e) 2091 | return e 2092 | } 2093 | 2094 | func (m *mock) ExpectClientUnpause() *ExpectedBool { 2095 | e := &ExpectedBool{} 2096 | e.cmd = m.factory.ClientUnpause(m.ctx) 2097 | m.pushExpect(e) 2098 | return e 2099 | } 2100 | 2101 | func (m *mock) ExpectClientID() *ExpectedInt { 2102 | e := &ExpectedInt{} 2103 | e.cmd = m.factory.ClientID(m.ctx) 2104 | m.pushExpect(e) 2105 | return e 2106 | } 2107 | 2108 | func (m *mock) ExpectClientUnblock(id int64) *ExpectedInt { 2109 | e := &ExpectedInt{} 2110 | e.cmd = m.factory.ClientUnblock(m.ctx, id) 2111 | m.pushExpect(e) 2112 | return e 2113 | } 2114 | 2115 | func (m *mock) ExpectClientUnblockWithError(id int64) *ExpectedInt { 2116 | e := &ExpectedInt{} 2117 | e.cmd = m.factory.ClientUnblockWithError(m.ctx, id) 2118 | m.pushExpect(e) 2119 | return e 2120 | } 2121 | 2122 | func (m *mock) ExpectConfigGet(parameter string) *ExpectedMapStringString { 2123 | e := &ExpectedMapStringString{} 2124 | e.cmd = m.factory.ConfigGet(m.ctx, parameter) 2125 | m.pushExpect(e) 2126 | return e 2127 | } 2128 | 2129 | func (m *mock) ExpectConfigResetStat() *ExpectedStatus { 2130 | e := &ExpectedStatus{} 2131 | e.cmd = m.factory.ConfigResetStat(m.ctx) 2132 | m.pushExpect(e) 2133 | return e 2134 | } 2135 | 2136 | func (m *mock) ExpectConfigSet(parameter, value string) *ExpectedStatus { 2137 | e := &ExpectedStatus{} 2138 | e.cmd = m.factory.ConfigSet(m.ctx, parameter, value) 2139 | m.pushExpect(e) 2140 | return e 2141 | } 2142 | 2143 | func (m *mock) ExpectConfigRewrite() *ExpectedStatus { 2144 | e := &ExpectedStatus{} 2145 | e.cmd = m.factory.ConfigRewrite(m.ctx) 2146 | m.pushExpect(e) 2147 | return e 2148 | } 2149 | 2150 | func (m *mock) ExpectDBSize() *ExpectedInt { 2151 | e := &ExpectedInt{} 2152 | e.cmd = m.factory.DBSize(m.ctx) 2153 | m.pushExpect(e) 2154 | return e 2155 | } 2156 | 2157 | func (m *mock) ExpectFlushAll() *ExpectedStatus { 2158 | e := &ExpectedStatus{} 2159 | e.cmd = m.factory.FlushAll(m.ctx) 2160 | m.pushExpect(e) 2161 | return e 2162 | } 2163 | 2164 | func (m *mock) ExpectFlushAllAsync() *ExpectedStatus { 2165 | e := &ExpectedStatus{} 2166 | e.cmd = m.factory.FlushAllAsync(m.ctx) 2167 | m.pushExpect(e) 2168 | return e 2169 | } 2170 | 2171 | func (m *mock) ExpectFlushDB() *ExpectedStatus { 2172 | e := &ExpectedStatus{} 2173 | e.cmd = m.factory.FlushDB(m.ctx) 2174 | m.pushExpect(e) 2175 | return e 2176 | } 2177 | 2178 | func (m *mock) ExpectFlushDBAsync() *ExpectedStatus { 2179 | e := &ExpectedStatus{} 2180 | e.cmd = m.factory.FlushDBAsync(m.ctx) 2181 | m.pushExpect(e) 2182 | return e 2183 | } 2184 | 2185 | func (m *mock) ExpectInfo(section ...string) *ExpectedString { 2186 | e := &ExpectedString{} 2187 | e.cmd = m.factory.Info(m.ctx, section...) 2188 | m.pushExpect(e) 2189 | return e 2190 | } 2191 | 2192 | func (m *mock) ExpectLastSave() *ExpectedInt { 2193 | e := &ExpectedInt{} 2194 | e.cmd = m.factory.LastSave(m.ctx) 2195 | m.pushExpect(e) 2196 | return e 2197 | } 2198 | 2199 | func (m *mock) ExpectSave() *ExpectedStatus { 2200 | e := &ExpectedStatus{} 2201 | e.cmd = m.factory.Save(m.ctx) 2202 | m.pushExpect(e) 2203 | return e 2204 | } 2205 | 2206 | func (m *mock) ExpectShutdown() *ExpectedStatus { 2207 | e := &ExpectedStatus{} 2208 | e.cmd = m.factory.Shutdown(m.ctx) 2209 | m.pushExpect(e) 2210 | return e 2211 | } 2212 | 2213 | func (m *mock) ExpectShutdownSave() *ExpectedStatus { 2214 | e := &ExpectedStatus{} 2215 | e.cmd = m.factory.ShutdownSave(m.ctx) 2216 | m.pushExpect(e) 2217 | return e 2218 | } 2219 | 2220 | func (m *mock) ExpectShutdownNoSave() *ExpectedStatus { 2221 | e := &ExpectedStatus{} 2222 | e.cmd = m.factory.ShutdownNoSave(m.ctx) 2223 | m.pushExpect(e) 2224 | return e 2225 | } 2226 | 2227 | func (m *mock) ExpectSlaveOf(host, port string) *ExpectedStatus { 2228 | e := &ExpectedStatus{} 2229 | e.cmd = m.factory.SlaveOf(m.ctx, host, port) 2230 | m.pushExpect(e) 2231 | return e 2232 | } 2233 | 2234 | func (m *mock) ExpectSlowLogGet(num int64) *ExpectedSlowLog { 2235 | e := &ExpectedSlowLog{} 2236 | e.cmd = m.factory.SlowLogGet(m.ctx, num) 2237 | m.pushExpect(e) 2238 | return e 2239 | } 2240 | 2241 | func (m *mock) ExpectTime() *ExpectedTime { 2242 | e := &ExpectedTime{} 2243 | e.cmd = m.factory.Time(m.ctx) 2244 | m.pushExpect(e) 2245 | return e 2246 | } 2247 | 2248 | func (m *mock) ExpectDebugObject(key string) *ExpectedString { 2249 | e := &ExpectedString{} 2250 | e.cmd = m.factory.DebugObject(m.ctx, key) 2251 | m.pushExpect(e) 2252 | return e 2253 | } 2254 | 2255 | func (m *mock) ExpectReadOnly() *ExpectedStatus { 2256 | e := &ExpectedStatus{} 2257 | e.cmd = m.factory.ReadOnly(m.ctx) 2258 | m.pushExpect(e) 2259 | return e 2260 | } 2261 | 2262 | func (m *mock) ExpectReadWrite() *ExpectedStatus { 2263 | e := &ExpectedStatus{} 2264 | e.cmd = m.factory.ReadWrite(m.ctx) 2265 | m.pushExpect(e) 2266 | return e 2267 | } 2268 | 2269 | func (m *mock) ExpectMemoryUsage(key string, samples ...int) *ExpectedInt { 2270 | e := &ExpectedInt{} 2271 | e.cmd = m.factory.MemoryUsage(m.ctx, key, samples...) 2272 | m.pushExpect(e) 2273 | return e 2274 | } 2275 | 2276 | func (m *mock) ExpectEval(script string, keys []string, args ...interface{}) *ExpectedCmd { 2277 | e := &ExpectedCmd{} 2278 | e.cmd = m.factory.Eval(m.ctx, script, keys, args...) 2279 | m.pushExpect(e) 2280 | return e 2281 | } 2282 | 2283 | func (m *mock) ExpectEvalSha(sha1 string, keys []string, args ...interface{}) *ExpectedCmd { 2284 | e := &ExpectedCmd{} 2285 | e.cmd = m.factory.EvalSha(m.ctx, sha1, keys, args...) 2286 | m.pushExpect(e) 2287 | return e 2288 | } 2289 | 2290 | func (m *mock) ExpectEvalRO(script string, keys []string, args ...interface{}) *ExpectedCmd { 2291 | e := &ExpectedCmd{} 2292 | e.cmd = m.factory.EvalRO(m.ctx, script, keys, args...) 2293 | m.pushExpect(e) 2294 | return e 2295 | } 2296 | 2297 | func (m *mock) ExpectEvalShaRO(sha1 string, keys []string, args ...interface{}) *ExpectedCmd { 2298 | e := &ExpectedCmd{} 2299 | e.cmd = m.factory.EvalShaRO(m.ctx, sha1, keys, args...) 2300 | m.pushExpect(e) 2301 | return e 2302 | } 2303 | 2304 | func (m *mock) ExpectScriptExists(hashes ...string) *ExpectedBoolSlice { 2305 | e := &ExpectedBoolSlice{} 2306 | e.cmd = m.factory.ScriptExists(m.ctx, hashes...) 2307 | m.pushExpect(e) 2308 | return e 2309 | } 2310 | 2311 | func (m *mock) ExpectScriptFlush() *ExpectedStatus { 2312 | e := &ExpectedStatus{} 2313 | e.cmd = m.factory.ScriptFlush(m.ctx) 2314 | m.pushExpect(e) 2315 | return e 2316 | } 2317 | 2318 | func (m *mock) ExpectScriptKill() *ExpectedStatus { 2319 | e := &ExpectedStatus{} 2320 | e.cmd = m.factory.ScriptKill(m.ctx) 2321 | m.pushExpect(e) 2322 | return e 2323 | } 2324 | 2325 | func (m *mock) ExpectScriptLoad(script string) *ExpectedString { 2326 | e := &ExpectedString{} 2327 | e.cmd = m.factory.ScriptLoad(m.ctx, script) 2328 | m.pushExpect(e) 2329 | return e 2330 | } 2331 | 2332 | func (m *mock) ExpectPublish(channel string, message interface{}) *ExpectedInt { 2333 | e := &ExpectedInt{} 2334 | e.cmd = m.factory.Publish(m.ctx, channel, message) 2335 | m.pushExpect(e) 2336 | return e 2337 | } 2338 | 2339 | func (m *mock) ExpectSPublish(channel string, message interface{}) *ExpectedInt { 2340 | e := &ExpectedInt{} 2341 | e.cmd = m.factory.SPublish(m.ctx, channel, message) 2342 | m.pushExpect(e) 2343 | return e 2344 | } 2345 | 2346 | func (m *mock) ExpectPubSubChannels(pattern string) *ExpectedStringSlice { 2347 | e := &ExpectedStringSlice{} 2348 | e.cmd = m.factory.PubSubChannels(m.ctx, pattern) 2349 | m.pushExpect(e) 2350 | return e 2351 | } 2352 | 2353 | func (m *mock) ExpectPubSubNumSub(channels ...string) *ExpectedMapStringInt { 2354 | e := &ExpectedMapStringInt{} 2355 | e.cmd = m.factory.PubSubNumSub(m.ctx, channels...) 2356 | m.pushExpect(e) 2357 | return e 2358 | } 2359 | 2360 | func (m *mock) ExpectPubSubNumPat() *ExpectedInt { 2361 | e := &ExpectedInt{} 2362 | e.cmd = m.factory.PubSubNumPat(m.ctx) 2363 | m.pushExpect(e) 2364 | return e 2365 | } 2366 | 2367 | func (m *mock) ExpectPubSubShardChannels(pattern string) *ExpectedStringSlice { 2368 | e := &ExpectedStringSlice{} 2369 | e.cmd = m.factory.PubSubShardChannels(m.ctx, pattern) 2370 | m.pushExpect(e) 2371 | return e 2372 | } 2373 | 2374 | func (m *mock) ExpectPubSubShardNumSub(channels ...string) *ExpectedMapStringInt { 2375 | e := &ExpectedMapStringInt{} 2376 | e.cmd = m.factory.PubSubShardNumSub(m.ctx, channels...) 2377 | m.pushExpect(e) 2378 | return e 2379 | } 2380 | 2381 | func (m *mock) ExpectClusterSlots() *ExpectedClusterSlots { 2382 | e := &ExpectedClusterSlots{} 2383 | e.cmd = m.factory.ClusterSlots(m.ctx) 2384 | m.pushExpect(e) 2385 | return e 2386 | } 2387 | 2388 | func (m *mock) ExpectClusterShards() *ExpectedClusterShards { 2389 | e := &ExpectedClusterShards{} 2390 | e.cmd = m.factory.ClusterShards(m.ctx) 2391 | m.pushExpect(e) 2392 | return e 2393 | } 2394 | 2395 | func (m *mock) ExpectClusterLinks() *ExpectedClusterLinks { 2396 | e := &ExpectedClusterLinks{} 2397 | e.cmd = m.factory.ClusterLinks(m.ctx) 2398 | m.pushExpect(e) 2399 | return e 2400 | } 2401 | 2402 | func (m *mock) ExpectClusterNodes() *ExpectedString { 2403 | e := &ExpectedString{} 2404 | e.cmd = m.factory.ClusterNodes(m.ctx) 2405 | m.pushExpect(e) 2406 | return e 2407 | } 2408 | 2409 | func (m *mock) ExpectClusterMeet(host, port string) *ExpectedStatus { 2410 | e := &ExpectedStatus{} 2411 | e.cmd = m.factory.ClusterMeet(m.ctx, host, port) 2412 | m.pushExpect(e) 2413 | return e 2414 | } 2415 | 2416 | func (m *mock) ExpectClusterForget(nodeID string) *ExpectedStatus { 2417 | e := &ExpectedStatus{} 2418 | e.cmd = m.factory.ClusterForget(m.ctx, nodeID) 2419 | m.pushExpect(e) 2420 | return e 2421 | } 2422 | 2423 | func (m *mock) ExpectClusterReplicate(nodeID string) *ExpectedStatus { 2424 | e := &ExpectedStatus{} 2425 | e.cmd = m.factory.ClusterReplicate(m.ctx, nodeID) 2426 | m.pushExpect(e) 2427 | return e 2428 | } 2429 | 2430 | func (m *mock) ExpectClusterResetSoft() *ExpectedStatus { 2431 | e := &ExpectedStatus{} 2432 | e.cmd = m.factory.ClusterResetSoft(m.ctx) 2433 | m.pushExpect(e) 2434 | return e 2435 | } 2436 | 2437 | func (m *mock) ExpectClusterResetHard() *ExpectedStatus { 2438 | e := &ExpectedStatus{} 2439 | e.cmd = m.factory.ClusterResetHard(m.ctx) 2440 | m.pushExpect(e) 2441 | return e 2442 | } 2443 | 2444 | func (m *mock) ExpectClusterInfo() *ExpectedString { 2445 | e := &ExpectedString{} 2446 | e.cmd = m.factory.ClusterInfo(m.ctx) 2447 | m.pushExpect(e) 2448 | return e 2449 | } 2450 | 2451 | func (m *mock) ExpectClusterKeySlot(key string) *ExpectedInt { 2452 | e := &ExpectedInt{} 2453 | e.cmd = m.factory.ClusterKeySlot(m.ctx, key) 2454 | m.pushExpect(e) 2455 | return e 2456 | } 2457 | 2458 | func (m *mock) ExpectClusterGetKeysInSlot(slot int, count int) *ExpectedStringSlice { 2459 | e := &ExpectedStringSlice{} 2460 | e.cmd = m.factory.ClusterGetKeysInSlot(m.ctx, slot, count) 2461 | m.pushExpect(e) 2462 | return e 2463 | } 2464 | 2465 | func (m *mock) ExpectClusterCountFailureReports(nodeID string) *ExpectedInt { 2466 | e := &ExpectedInt{} 2467 | e.cmd = m.factory.ClusterCountFailureReports(m.ctx, nodeID) 2468 | m.pushExpect(e) 2469 | return e 2470 | } 2471 | 2472 | func (m *mock) ExpectClusterCountKeysInSlot(slot int) *ExpectedInt { 2473 | e := &ExpectedInt{} 2474 | e.cmd = m.factory.ClusterCountKeysInSlot(m.ctx, slot) 2475 | m.pushExpect(e) 2476 | return e 2477 | } 2478 | 2479 | func (m *mock) ExpectClusterDelSlots(slots ...int) *ExpectedStatus { 2480 | e := &ExpectedStatus{} 2481 | e.cmd = m.factory.ClusterDelSlots(m.ctx, slots...) 2482 | m.pushExpect(e) 2483 | return e 2484 | } 2485 | 2486 | func (m *mock) ExpectClusterDelSlotsRange(min, max int) *ExpectedStatus { 2487 | e := &ExpectedStatus{} 2488 | e.cmd = m.factory.ClusterDelSlotsRange(m.ctx, min, max) 2489 | m.pushExpect(e) 2490 | return e 2491 | } 2492 | 2493 | func (m *mock) ExpectClusterSaveConfig() *ExpectedStatus { 2494 | e := &ExpectedStatus{} 2495 | e.cmd = m.factory.ClusterSaveConfig(m.ctx) 2496 | m.pushExpect(e) 2497 | return e 2498 | } 2499 | 2500 | func (m *mock) ExpectClusterSlaves(nodeID string) *ExpectedStringSlice { 2501 | e := &ExpectedStringSlice{} 2502 | e.cmd = m.factory.ClusterSlaves(m.ctx, nodeID) 2503 | m.pushExpect(e) 2504 | return e 2505 | } 2506 | 2507 | func (m *mock) ExpectClusterFailover() *ExpectedStatus { 2508 | e := &ExpectedStatus{} 2509 | e.cmd = m.factory.ClusterFailover(m.ctx) 2510 | m.pushExpect(e) 2511 | return e 2512 | } 2513 | 2514 | func (m *mock) ExpectClusterAddSlots(slots ...int) *ExpectedStatus { 2515 | e := &ExpectedStatus{} 2516 | e.cmd = m.factory.ClusterAddSlots(m.ctx, slots...) 2517 | m.pushExpect(e) 2518 | return e 2519 | } 2520 | 2521 | func (m *mock) ExpectClusterAddSlotsRange(min, max int) *ExpectedStatus { 2522 | e := &ExpectedStatus{} 2523 | e.cmd = m.factory.ClusterAddSlotsRange(m.ctx, min, max) 2524 | m.pushExpect(e) 2525 | return e 2526 | } 2527 | 2528 | func (m *mock) ExpectGeoAdd(key string, geoLocation ...*redis.GeoLocation) *ExpectedInt { 2529 | e := &ExpectedInt{} 2530 | e.cmd = m.factory.GeoAdd(m.ctx, key, geoLocation...) 2531 | m.pushExpect(e) 2532 | return e 2533 | } 2534 | 2535 | func (m *mock) ExpectGeoPos(key string, members ...string) *ExpectedGeoPos { 2536 | e := &ExpectedGeoPos{} 2537 | e.cmd = m.factory.GeoPos(m.ctx, key, members...) 2538 | m.pushExpect(e) 2539 | return e 2540 | } 2541 | 2542 | func (m *mock) ExpectGeoRadius( 2543 | key string, longitude, latitude float64, query *redis.GeoRadiusQuery, 2544 | ) *ExpectedGeoLocation { 2545 | e := &ExpectedGeoLocation{} 2546 | e.cmd = m.factory.GeoRadius(m.ctx, key, longitude, latitude, query) 2547 | m.pushExpect(e) 2548 | return e 2549 | } 2550 | 2551 | func (m *mock) ExpectGeoRadiusStore( 2552 | key string, longitude, latitude float64, query *redis.GeoRadiusQuery, 2553 | ) *ExpectedInt { 2554 | e := &ExpectedInt{} 2555 | e.cmd = m.factory.GeoRadiusStore(m.ctx, key, longitude, latitude, query) 2556 | m.pushExpect(e) 2557 | return e 2558 | } 2559 | 2560 | func (m *mock) ExpectGeoRadiusByMember(key, member string, query *redis.GeoRadiusQuery) *ExpectedGeoLocation { 2561 | e := &ExpectedGeoLocation{} 2562 | e.cmd = m.factory.GeoRadiusByMember(m.ctx, key, member, query) 2563 | m.pushExpect(e) 2564 | return e 2565 | } 2566 | 2567 | func (m *mock) ExpectGeoRadiusByMemberStore(key, member string, query *redis.GeoRadiusQuery) *ExpectedInt { 2568 | e := &ExpectedInt{} 2569 | e.cmd = m.factory.GeoRadiusByMemberStore(m.ctx, key, member, query) 2570 | m.pushExpect(e) 2571 | return e 2572 | } 2573 | 2574 | func (m *mock) ExpectGeoSearch(key string, q *redis.GeoSearchQuery) *ExpectedStringSlice { 2575 | e := &ExpectedStringSlice{} 2576 | e.cmd = m.factory.GeoSearch(m.ctx, key, q) 2577 | m.pushExpect(e) 2578 | return e 2579 | } 2580 | 2581 | func (m *mock) ExpectGeoSearchLocation(key string, q *redis.GeoSearchLocationQuery) *ExpectedGeoSearchLocation { 2582 | e := &ExpectedGeoSearchLocation{} 2583 | e.cmd = m.factory.GeoSearchLocation(m.ctx, key, q) 2584 | m.pushExpect(e) 2585 | return e 2586 | } 2587 | 2588 | func (m *mock) ExpectGeoSearchStore(key, store string, q *redis.GeoSearchStoreQuery) *ExpectedInt { 2589 | e := &ExpectedInt{} 2590 | e.cmd = m.factory.GeoSearchStore(m.ctx, key, store, q) 2591 | m.pushExpect(e) 2592 | return e 2593 | } 2594 | 2595 | func (m *mock) ExpectGeoDist(key string, member1, member2, unit string) *ExpectedFloat { 2596 | e := &ExpectedFloat{} 2597 | e.cmd = m.factory.GeoDist(m.ctx, key, member1, member2, unit) 2598 | m.pushExpect(e) 2599 | return e 2600 | } 2601 | 2602 | func (m *mock) ExpectGeoHash(key string, members ...string) *ExpectedStringSlice { 2603 | e := &ExpectedStringSlice{} 2604 | e.cmd = m.factory.GeoHash(m.ctx, key, members...) 2605 | m.pushExpect(e) 2606 | return e 2607 | } 2608 | 2609 | // ---------------------------------------------------------------------------------------------------- 2610 | 2611 | func (m *mock) ExpectFunctionLoad(code string) *ExpectedString { 2612 | e := &ExpectedString{} 2613 | e.cmd = m.factory.FunctionLoad(m.ctx, code) 2614 | m.pushExpect(e) 2615 | return e 2616 | } 2617 | 2618 | func (m *mock) ExpectFunctionLoadReplace(code string) *ExpectedString { 2619 | e := &ExpectedString{} 2620 | e.cmd = m.factory.FunctionLoadReplace(m.ctx, code) 2621 | m.pushExpect(e) 2622 | return e 2623 | } 2624 | 2625 | func (m *mock) ExpectFunctionDelete(libName string) *ExpectedString { 2626 | e := &ExpectedString{} 2627 | e.cmd = m.factory.FunctionDelete(m.ctx, libName) 2628 | m.pushExpect(e) 2629 | return e 2630 | } 2631 | 2632 | func (m *mock) ExpectFunctionFlush() *ExpectedString { 2633 | e := &ExpectedString{} 2634 | e.cmd = m.factory.FunctionFlush(m.ctx) 2635 | m.pushExpect(e) 2636 | return e 2637 | } 2638 | 2639 | func (m *mock) ExpectFunctionFlushAsync() *ExpectedString { 2640 | e := &ExpectedString{} 2641 | e.cmd = m.factory.FunctionFlushAsync(m.ctx) 2642 | m.pushExpect(e) 2643 | return e 2644 | } 2645 | 2646 | func (m *mock) ExpectFunctionList(q redis.FunctionListQuery) *ExpectedFunctionList { 2647 | e := &ExpectedFunctionList{} 2648 | e.cmd = m.factory.FunctionList(m.ctx, q) 2649 | m.pushExpect(e) 2650 | return e 2651 | } 2652 | 2653 | func (m *mock) ExpectFunctionKill() *ExpectedString { 2654 | e := &ExpectedString{} 2655 | e.cmd = m.factory.FunctionKill(m.ctx) 2656 | m.pushExpect(e) 2657 | return e 2658 | } 2659 | 2660 | func (m *mock) ExpectFunctionDump() *ExpectedString { 2661 | e := &ExpectedString{} 2662 | e.cmd = m.factory.FunctionDump(m.ctx) 2663 | m.pushExpect(e) 2664 | return e 2665 | } 2666 | 2667 | func (m *mock) ExpectFunctionRestore(libDump string) *ExpectedString { 2668 | e := &ExpectedString{} 2669 | e.cmd = m.factory.FunctionRestore(m.ctx, libDump) 2670 | m.pushExpect(e) 2671 | return e 2672 | } 2673 | 2674 | func (m *mock) ExpectFCall(function string, keys []string, args ...interface{}) *ExpectedCmd { 2675 | e := &ExpectedCmd{} 2676 | e.cmd = m.factory.FCall(m.ctx, function, keys, args...) 2677 | m.pushExpect(e) 2678 | return e 2679 | } 2680 | 2681 | func (m *mock) ExpectFCallRo(function string, keys []string, args ...interface{}) *ExpectedCmd { 2682 | e := &ExpectedCmd{} 2683 | e.cmd = m.factory.FCallRo(m.ctx, function, keys, args...) 2684 | m.pushExpect(e) 2685 | return e 2686 | } 2687 | 2688 | // ------------------------------------------------------------------------ 2689 | 2690 | func (m *mock) ExpectACLDryRun(username string, command ...interface{}) *ExpectedString { 2691 | e := &ExpectedString{} 2692 | e.cmd = m.factory.ACLDryRun(m.ctx, username, command...) 2693 | m.pushExpect(e) 2694 | return e 2695 | } 2696 | 2697 | // ------------------------------------------------------------------------------------------ 2698 | 2699 | func (m *mock) ExpectTSAdd(key string, timestamp interface{}, value float64) *ExpectedInt { 2700 | e := &ExpectedInt{} 2701 | e.cmd = m.factory.TSAdd(m.ctx, key, timestamp, value) 2702 | m.pushExpect(e) 2703 | return e 2704 | } 2705 | 2706 | func (m *mock) ExpectTSAddWithArgs(key string, timestamp interface{}, value float64, options *redis.TSOptions) *ExpectedInt { 2707 | e := &ExpectedInt{} 2708 | e.cmd = m.factory.TSAddWithArgs(m.ctx, key, timestamp, value, options) 2709 | m.pushExpect(e) 2710 | return e 2711 | } 2712 | 2713 | func (m *mock) ExpectTSCreate(key string) *ExpectedStatus { 2714 | e := &ExpectedStatus{} 2715 | e.cmd = m.factory.TSCreate(m.ctx, key) 2716 | m.pushExpect(e) 2717 | return e 2718 | } 2719 | 2720 | func (m *mock) ExpectTSCreateWithArgs(key string, options *redis.TSOptions) *ExpectedStatus { 2721 | e := &ExpectedStatus{} 2722 | e.cmd = m.factory.TSCreateWithArgs(m.ctx, key, options) 2723 | m.pushExpect(e) 2724 | return e 2725 | } 2726 | 2727 | func (m *mock) ExpectTSAlter(key string, options *redis.TSAlterOptions) *ExpectedStatus { 2728 | e := &ExpectedStatus{} 2729 | e.cmd = m.factory.TSAlter(m.ctx, key, options) 2730 | m.pushExpect(e) 2731 | return e 2732 | } 2733 | 2734 | func (m *mock) ExpectTSCreateRule(sourceKey string, destKey string, aggregator redis.Aggregator, bucketDuration int) *ExpectedStatus { 2735 | e := &ExpectedStatus{} 2736 | e.cmd = m.factory.TSCreateRule(m.ctx, sourceKey, destKey, aggregator, bucketDuration) 2737 | m.pushExpect(e) 2738 | return e 2739 | } 2740 | 2741 | func (m *mock) ExpectTSCreateRuleWithArgs(sourceKey string, destKey string, aggregator redis.Aggregator, bucketDuration int, options *redis.TSCreateRuleOptions) *ExpectedStatus { 2742 | e := &ExpectedStatus{} 2743 | e.cmd = m.factory.TSCreateRuleWithArgs(m.ctx, sourceKey, destKey, aggregator, bucketDuration, options) 2744 | m.pushExpect(e) 2745 | return e 2746 | } 2747 | 2748 | func (m *mock) ExpectTSIncrBy(key string, timestamp float64) *ExpectedInt { 2749 | e := &ExpectedInt{} 2750 | e.cmd = m.factory.TSIncrBy(m.ctx, key, timestamp) 2751 | m.pushExpect(e) 2752 | return e 2753 | } 2754 | 2755 | func (m *mock) ExpectTSIncrByWithArgs(key string, timestamp float64, options *redis.TSIncrDecrOptions) *ExpectedInt { 2756 | e := &ExpectedInt{} 2757 | e.cmd = m.factory.TSIncrByWithArgs(m.ctx, key, timestamp, options) 2758 | m.pushExpect(e) 2759 | return e 2760 | } 2761 | 2762 | func (m *mock) ExpectTSDecrBy(key string, timestamp float64) *ExpectedInt { 2763 | e := &ExpectedInt{} 2764 | e.cmd = m.factory.TSDecrBy(m.ctx, key, timestamp) 2765 | m.pushExpect(e) 2766 | return e 2767 | } 2768 | 2769 | func (m *mock) ExpectTSDecrByWithArgs(key string, timestamp float64, options *redis.TSIncrDecrOptions) *ExpectedInt { 2770 | e := &ExpectedInt{} 2771 | e.cmd = m.factory.TSDecrByWithArgs(m.ctx, key, timestamp, options) 2772 | m.pushExpect(e) 2773 | return e 2774 | } 2775 | 2776 | func (m *mock) ExpectTSDel(key string, fromTimestamp int, toTimestamp int) *ExpectedInt { 2777 | e := &ExpectedInt{} 2778 | e.cmd = m.factory.TSDel(m.ctx, key, fromTimestamp, toTimestamp) 2779 | m.pushExpect(e) 2780 | return e 2781 | } 2782 | 2783 | func (m *mock) ExpectTSDeleteRule(sourceKey string, destKey string) *ExpectedStatus { 2784 | e := &ExpectedStatus{} 2785 | e.cmd = m.factory.TSDeleteRule(m.ctx, sourceKey, destKey) 2786 | m.pushExpect(e) 2787 | return e 2788 | } 2789 | 2790 | func (m *mock) ExpectTSGet(key string) *ExpectedTSTimestampValue { 2791 | e := &ExpectedTSTimestampValue{} 2792 | e.cmd = m.factory.TSGet(m.ctx, key) 2793 | m.pushExpect(e) 2794 | return e 2795 | } 2796 | 2797 | func (m *mock) ExpectTSGetWithArgs(key string, options *redis.TSGetOptions) *ExpectedTSTimestampValue { 2798 | e := &ExpectedTSTimestampValue{} 2799 | e.cmd = m.factory.TSGetWithArgs(m.ctx, key, options) 2800 | m.pushExpect(e) 2801 | return e 2802 | } 2803 | 2804 | func (m *mock) ExpectTSInfo(key string) *ExpectedMapStringInterface { 2805 | e := &ExpectedMapStringInterface{} 2806 | e.cmd = m.factory.TSInfo(m.ctx, key) 2807 | m.pushExpect(e) 2808 | return e 2809 | } 2810 | 2811 | func (m *mock) ExpectTSInfoWithArgs(key string, options *redis.TSInfoOptions) *ExpectedMapStringInterface { 2812 | e := &ExpectedMapStringInterface{} 2813 | e.cmd = m.factory.TSInfoWithArgs(m.ctx, key, options) 2814 | m.pushExpect(e) 2815 | return e 2816 | } 2817 | 2818 | func (m *mock) ExpectTSMAdd(ktvSlices [][]interface{}) *ExpectedIntSlice { 2819 | e := &ExpectedIntSlice{} 2820 | e.cmd = m.factory.TSMAdd(m.ctx, ktvSlices) 2821 | m.pushExpect(e) 2822 | return e 2823 | } 2824 | 2825 | func (m *mock) ExpectTSQueryIndex(filterExpr []string) *ExpectedStringSlice { 2826 | e := &ExpectedStringSlice{} 2827 | e.cmd = m.factory.TSQueryIndex(m.ctx, filterExpr) 2828 | m.pushExpect(e) 2829 | return e 2830 | } 2831 | 2832 | func (m *mock) ExpectTSRevRange(key string, fromTimestamp int, toTimestamp int) *ExpectedTSTimestampValueSlice { 2833 | e := &ExpectedTSTimestampValueSlice{} 2834 | e.cmd = m.factory.TSRevRange(m.ctx, key, fromTimestamp, toTimestamp) 2835 | m.pushExpect(e) 2836 | return e 2837 | } 2838 | 2839 | func (m *mock) ExpectTSRevRangeWithArgs(key string, fromTimestamp int, toTimestamp int, options *redis.TSRevRangeOptions) *ExpectedTSTimestampValueSlice { 2840 | e := &ExpectedTSTimestampValueSlice{} 2841 | e.cmd = m.factory.TSRevRangeWithArgs(m.ctx, key, fromTimestamp, toTimestamp, options) 2842 | m.pushExpect(e) 2843 | return e 2844 | } 2845 | 2846 | func (m *mock) ExpectTSRange(key string, fromTimestamp int, toTimestamp int) *ExpectedTSTimestampValueSlice { 2847 | e := &ExpectedTSTimestampValueSlice{} 2848 | e.cmd = m.factory.TSRange(m.ctx, key, fromTimestamp, toTimestamp) 2849 | m.pushExpect(e) 2850 | return e 2851 | } 2852 | 2853 | func (m *mock) ExpectTSRangeWithArgs(key string, fromTimestamp int, toTimestamp int, options *redis.TSRangeOptions) *ExpectedTSTimestampValueSlice { 2854 | e := &ExpectedTSTimestampValueSlice{} 2855 | e.cmd = m.factory.TSRangeWithArgs(m.ctx, key, fromTimestamp, toTimestamp, options) 2856 | m.pushExpect(e) 2857 | return e 2858 | } 2859 | 2860 | func (m *mock) ExpectTSMRange(fromTimestamp int, toTimestamp int, filterExpr []string) *ExpectedMapStringSliceInterface { 2861 | e := &ExpectedMapStringSliceInterface{} 2862 | e.cmd = m.factory.TSMRange(m.ctx, fromTimestamp, toTimestamp, filterExpr) 2863 | m.pushExpect(e) 2864 | return e 2865 | } 2866 | 2867 | func (m *mock) ExpectTSMRangeWithArgs(fromTimestamp int, toTimestamp int, filterExpr []string, options *redis.TSMRangeOptions) *ExpectedMapStringSliceInterface { 2868 | e := &ExpectedMapStringSliceInterface{} 2869 | e.cmd = m.factory.TSMRangeWithArgs(m.ctx, fromTimestamp, toTimestamp, filterExpr, options) 2870 | m.pushExpect(e) 2871 | return e 2872 | } 2873 | 2874 | func (m *mock) ExpectTSMRevRange(fromTimestamp int, toTimestamp int, filterExpr []string) *ExpectedMapStringSliceInterface { 2875 | e := &ExpectedMapStringSliceInterface{} 2876 | e.cmd = m.factory.TSMRevRange(m.ctx, fromTimestamp, toTimestamp, filterExpr) 2877 | m.pushExpect(e) 2878 | return e 2879 | } 2880 | 2881 | func (m *mock) ExpectTSMRevRangeWithArgs(fromTimestamp int, toTimestamp int, filterExpr []string, options *redis.TSMRevRangeOptions) *ExpectedMapStringSliceInterface { 2882 | e := &ExpectedMapStringSliceInterface{} 2883 | e.cmd = m.factory.TSMRevRangeWithArgs(m.ctx, fromTimestamp, toTimestamp, filterExpr, options) 2884 | m.pushExpect(e) 2885 | return e 2886 | } 2887 | 2888 | func (m *mock) ExpectTSMGet(filters []string) *ExpectedMapStringSliceInterface { 2889 | e := &ExpectedMapStringSliceInterface{} 2890 | e.cmd = m.factory.TSMGet(m.ctx, filters) 2891 | m.pushExpect(e) 2892 | return e 2893 | } 2894 | 2895 | func (m *mock) ExpectTSMGetWithArgs(filters []string, options *redis.TSMGetOptions) *ExpectedMapStringSliceInterface { 2896 | e := &ExpectedMapStringSliceInterface{} 2897 | e.cmd = m.factory.TSMGetWithArgs(m.ctx, filters, options) 2898 | m.pushExpect(e) 2899 | return e 2900 | } 2901 | -------------------------------------------------------------------------------- /mock_test.go: -------------------------------------------------------------------------------- 1 | package redismock 2 | 3 | import ( 4 | "context" 5 | "errors" 6 | "testing" 7 | "time" 8 | 9 | . "github.com/onsi/ginkgo" 10 | . "github.com/onsi/gomega" 11 | "github.com/redis/go-redis/v9" 12 | ) 13 | 14 | var ( 15 | ctx = context.TODO() 16 | ) 17 | 18 | func TestRedisMock(t *testing.T) { 19 | RegisterFailHandler(Fail) 20 | RunSpecs(t, "redis mock") 21 | } 22 | 23 | func operationStringCmd(base baseMock, expected func() *ExpectedString, actual func() *redis.StringCmd) { 24 | var ( 25 | setErr = errors.New("string cmd error") 26 | str string 27 | err error 28 | ) 29 | 30 | base.ClearExpect() 31 | expected().SetErr(setErr) 32 | str, err = actual().Result() 33 | Expect(err).To(Equal(setErr)) 34 | Expect(str).To(Equal("")) 35 | 36 | base.ClearExpect() 37 | expected() 38 | str, err = actual().Result() 39 | Expect(err).To(HaveOccurred()) 40 | Expect(str).To(Equal("")) 41 | 42 | base.ClearExpect() 43 | expected().SetVal("value") 44 | str, err = actual().Result() 45 | Expect(err).NotTo(HaveOccurred()) 46 | Expect(str).To(Equal("value")) 47 | } 48 | 49 | func operationStatusCmd(base baseMock, expected func() *ExpectedStatus, actual func() *redis.StatusCmd) { 50 | var ( 51 | setErr = errors.New("status cmd error") 52 | str string 53 | err error 54 | ) 55 | 56 | base.ClearExpect() 57 | expected().SetErr(setErr) 58 | str, err = actual().Result() 59 | Expect(err).To(Equal(setErr)) 60 | Expect(str).To(Equal("")) 61 | 62 | base.ClearExpect() 63 | expected() 64 | str, err = actual().Result() 65 | Expect(err).To(HaveOccurred()) 66 | Expect(str).To(Equal("")) 67 | 68 | base.ClearExpect() 69 | expected().SetVal("OK") 70 | str, err = actual().Result() 71 | Expect(err).NotTo(HaveOccurred()) 72 | Expect(str).To(Equal("OK")) 73 | } 74 | 75 | func operationIntCmd(base baseMock, expected func() *ExpectedInt, actual func() *redis.IntCmd) { 76 | var ( 77 | setErr = errors.New("int cmd error") 78 | val int64 79 | err error 80 | ) 81 | 82 | base.ClearExpect() 83 | expected().SetErr(setErr) 84 | val, err = actual().Result() 85 | Expect(err).To(Equal(setErr)) 86 | Expect(val).To(Equal(int64(0))) 87 | 88 | base.ClearExpect() 89 | expected() 90 | val, err = actual().Result() 91 | Expect(err).To(HaveOccurred()) 92 | Expect(val).To(Equal(int64(0))) 93 | 94 | base.ClearExpect() 95 | expected().SetVal(1024) 96 | val, err = actual().Result() 97 | Expect(err).NotTo(HaveOccurred()) 98 | Expect(val).To(Equal(int64(1024))) 99 | } 100 | 101 | func operationBoolCmd(base baseMock, expected func() *ExpectedBool, actual func() *redis.BoolCmd) { 102 | var ( 103 | setErr = errors.New("bool cmd error") 104 | val bool 105 | err error 106 | ) 107 | 108 | base.ClearExpect() 109 | expected().SetErr(setErr) 110 | val, err = actual().Result() 111 | Expect(err).To(Equal(setErr)) 112 | Expect(val).To(BeFalse()) 113 | 114 | base.ClearExpect() 115 | expected() 116 | val, err = actual().Result() 117 | Expect(err).To(HaveOccurred()) 118 | Expect(val).To(BeFalse()) 119 | 120 | base.ClearExpect() 121 | expected().SetVal(true) 122 | val, err = actual().Result() 123 | Expect(err).NotTo(HaveOccurred()) 124 | Expect(val).To(BeTrue()) 125 | } 126 | 127 | func operationStringSliceCmd(base baseMock, expected func() *ExpectedStringSlice, actual func() *redis.StringSliceCmd) { 128 | var ( 129 | setErr = errors.New("string slice cmd error") 130 | val []string 131 | err error 132 | ) 133 | 134 | base.ClearExpect() 135 | expected().SetErr(setErr) 136 | val, err = actual().Result() 137 | Expect(err).To(Equal(setErr)) 138 | Expect(val).To(Equal([]string(nil))) 139 | 140 | base.ClearExpect() 141 | expected() 142 | val, err = actual().Result() 143 | Expect(err).To(HaveOccurred()) 144 | Expect(val).To(Equal([]string(nil))) 145 | 146 | base.ClearExpect() 147 | expected().SetVal([]string{"redis", "move"}) 148 | val, err = actual().Result() 149 | Expect(err).NotTo(HaveOccurred()) 150 | Expect(val).To(Equal([]string{"redis", "move"})) 151 | } 152 | 153 | func operationKeyValueSliceCmd(base baseMock, expected func() *ExpectedKeyValueSlice, actual func() *redis.KeyValueSliceCmd) { 154 | var ( 155 | setErr = errors.New("key value slice cmd error") 156 | val []redis.KeyValue 157 | err error 158 | ) 159 | 160 | base.ClearExpect() 161 | expected().SetErr(setErr) 162 | val, err = actual().Result() 163 | Expect(err).To(Equal(setErr)) 164 | Expect(val).To(Equal([]redis.KeyValue(nil))) 165 | 166 | base.ClearExpect() 167 | expected() 168 | val, err = actual().Result() 169 | Expect(err).To(HaveOccurred()) 170 | Expect(val).To(Equal([]redis.KeyValue(nil))) 171 | 172 | base.ClearExpect() 173 | expected().SetVal([]redis.KeyValue{ 174 | {Key: "k1", Value: "v1"}, 175 | {Key: "k2", Value: "v2"}, 176 | }) 177 | val, err = actual().Result() 178 | Expect(err).NotTo(HaveOccurred()) 179 | Expect(val).To(Equal([]redis.KeyValue{ 180 | {Key: "k1", Value: "v1"}, 181 | {Key: "k2", Value: "v2"}, 182 | })) 183 | } 184 | 185 | func operationDurationCmd(base baseMock, expected func() *ExpectedDuration, actual func() *redis.DurationCmd) { 186 | var ( 187 | setErr = errors.New("duration cmd error") 188 | val time.Duration 189 | err error 190 | ) 191 | 192 | base.ClearExpect() 193 | expected().SetErr(setErr) 194 | val, err = actual().Result() 195 | Expect(err).To(Equal(setErr)) 196 | Expect(val).To(Equal(time.Duration(0))) 197 | 198 | base.ClearExpect() 199 | expected() 200 | val, err = actual().Result() 201 | Expect(err).To(HaveOccurred()) 202 | Expect(val).To(Equal(time.Duration(0))) 203 | 204 | base.ClearExpect() 205 | expected().SetVal(2 * time.Hour) 206 | val, err = actual().Result() 207 | Expect(err).NotTo(HaveOccurred()) 208 | Expect(val).To(Equal(2 * time.Hour)) 209 | } 210 | 211 | func operationSliceCmd(base baseMock, expected func() *ExpectedSlice, actual func() *redis.SliceCmd) { 212 | var ( 213 | setErr = errors.New("slice cmd error") 214 | val []interface{} 215 | err error 216 | ) 217 | 218 | base.ClearExpect() 219 | expected().SetErr(setErr) 220 | val, err = actual().Result() 221 | Expect(err).To(Equal(setErr)) 222 | Expect(val).To(Equal([]interface{}(nil))) 223 | 224 | base.ClearExpect() 225 | expected() 226 | val, err = actual().Result() 227 | Expect(err).To(HaveOccurred()) 228 | Expect(val).To(Equal([]interface{}(nil))) 229 | 230 | base.ClearExpect() 231 | expected().SetVal([]interface{}{"mock", "slice"}) 232 | val, err = actual().Result() 233 | Expect(err).NotTo(HaveOccurred()) 234 | Expect(val).To(Equal([]interface{}{"mock", "slice"})) 235 | } 236 | 237 | func operationFloatCmd(base baseMock, expected func() *ExpectedFloat, actual func() *redis.FloatCmd) { 238 | var ( 239 | setErr = errors.New("float cmd error") 240 | val float64 241 | err error 242 | ) 243 | 244 | base.ClearExpect() 245 | expected().SetErr(setErr) 246 | val, err = actual().Result() 247 | Expect(err).To(Equal(setErr)) 248 | Expect(val).To(Equal(float64(0))) 249 | 250 | base.ClearExpect() 251 | expected() 252 | val, err = actual().Result() 253 | Expect(err).To(HaveOccurred()) 254 | Expect(val).To(Equal(float64(0))) 255 | 256 | base.ClearExpect() 257 | expected().SetVal(1) 258 | val, err = actual().Result() 259 | Expect(err).NotTo(HaveOccurred()) 260 | Expect(val).To(Equal(float64(1))) 261 | } 262 | 263 | func operationFloatSliceCmd(base baseMock, expected func() *ExpectedFloatSlice, actual func() *redis.FloatSliceCmd) { 264 | var ( 265 | setErr = errors.New("float slice cmd error") 266 | val []float64 267 | err error 268 | ) 269 | 270 | base.ClearExpect() 271 | expected().SetErr(setErr) 272 | val, err = actual().Result() 273 | Expect(err).To(Equal(setErr)) 274 | Expect(val).To(Equal([]float64(nil))) 275 | 276 | base.ClearExpect() 277 | expected() 278 | val, err = actual().Result() 279 | Expect(err).To(HaveOccurred()) 280 | Expect(val).To(Equal([]float64(nil))) 281 | 282 | base.ClearExpect() 283 | expected().SetVal([]float64{11.11, 22.22, 99.99999}) 284 | val, err = actual().Result() 285 | Expect(err).NotTo(HaveOccurred()) 286 | Expect(val).To(Equal([]float64{11.11, 22.22, 99.99999})) 287 | } 288 | 289 | func operationIntSliceCmd(base baseMock, expected func() *ExpectedIntSlice, actual func() *redis.IntSliceCmd) { 290 | var ( 291 | setErr = errors.New("int slice cmd error") 292 | val []int64 293 | err error 294 | ) 295 | 296 | base.ClearExpect() 297 | expected().SetErr(setErr) 298 | val, err = actual().Result() 299 | Expect(err).To(Equal(setErr)) 300 | Expect(val).To(Equal([]int64(nil))) 301 | 302 | base.ClearExpect() 303 | expected() 304 | val, err = actual().Result() 305 | Expect(err).To(HaveOccurred()) 306 | Expect(val).To(Equal([]int64(nil))) 307 | 308 | base.ClearExpect() 309 | expected().SetVal([]int64{1, 2, 3, 4}) 310 | val, err = actual().Result() 311 | Expect(err).NotTo(HaveOccurred()) 312 | Expect(val).To(Equal([]int64{1, 2, 3, 4})) 313 | } 314 | 315 | func operationScanCmd(base baseMock, expected func() *ExpectedScan, actual func() *redis.ScanCmd) { 316 | var ( 317 | setErr = errors.New("scan cmd error") 318 | page []string 319 | cursor uint64 320 | err error 321 | ) 322 | 323 | base.ClearExpect() 324 | expected().SetErr(setErr) 325 | page, cursor, err = actual().Result() 326 | Expect(err).To(Equal(setErr)) 327 | Expect(page).To(Equal([]string(nil))) 328 | Expect(cursor).To(Equal(uint64(0))) 329 | 330 | base.ClearExpect() 331 | expected() 332 | page, cursor, err = actual().Result() 333 | Expect(err).To(HaveOccurred()) 334 | Expect(page).To(Equal([]string(nil))) 335 | Expect(cursor).To(Equal(uint64(0))) 336 | 337 | base.ClearExpect() 338 | expected().SetVal([]string{"key1", "key2", "key3"}, 5) 339 | page, cursor, err = actual().Result() 340 | Expect(err).NotTo(HaveOccurred()) 341 | Expect(page).To(Equal([]string{"key1", "key2", "key3"})) 342 | Expect(cursor).To(Equal(uint64(5))) 343 | } 344 | 345 | func operationMapStringStringCmd(base baseMock, expected func() *ExpectedMapStringString, actual func() *redis.MapStringStringCmd) { 346 | var ( 347 | setErr = errors.New("map string string cmd error") 348 | val map[string]string 349 | err error 350 | ) 351 | 352 | base.ClearExpect() 353 | expected().SetErr(setErr) 354 | val, err = actual().Result() 355 | Expect(err).To(Equal(setErr)) 356 | Expect(val).To(Equal(map[string]string(nil))) 357 | 358 | base.ClearExpect() 359 | expected() 360 | val, err = actual().Result() 361 | Expect(err).To(HaveOccurred()) 362 | Expect(val).To(Equal(map[string]string(nil))) 363 | 364 | base.ClearExpect() 365 | expected().SetVal(map[string]string{"key": "value", "key2": "value2"}) 366 | val, err = actual().Result() 367 | Expect(err).NotTo(HaveOccurred()) 368 | Expect(val).To(Equal(map[string]string{"key": "value", "key2": "value2"})) 369 | } 370 | 371 | func operationStringStructMapCmd(base baseMock, expected func() *ExpectedStringStructMap, actual func() *redis.StringStructMapCmd) { 372 | var ( 373 | setErr = errors.New("string struct map cmd error") 374 | val map[string]struct{} 375 | err error 376 | ) 377 | 378 | base.ClearExpect() 379 | expected().SetErr(setErr) 380 | val, err = actual().Result() 381 | Expect(err).To(Equal(setErr)) 382 | Expect(val).To(Equal(map[string]struct{}(nil))) 383 | 384 | base.ClearExpect() 385 | expected() 386 | val, err = actual().Result() 387 | Expect(err).To(HaveOccurred()) 388 | Expect(val).To(Equal(map[string]struct{}(nil))) 389 | 390 | base.ClearExpect() 391 | expected().SetVal([]string{"key1", "key2"}) 392 | val, err = actual().Result() 393 | Expect(err).NotTo(HaveOccurred()) 394 | Expect(val).To(Equal(map[string]struct{}{"key1": {}, "key2": {}})) 395 | } 396 | 397 | func operationXMessageSliceCmd(base baseMock, expected func() *ExpectedXMessageSlice, actual func() *redis.XMessageSliceCmd) { 398 | var ( 399 | setErr = errors.New("x message slice cmd error") 400 | val []redis.XMessage 401 | err error 402 | ) 403 | 404 | base.ClearExpect() 405 | expected().SetErr(setErr) 406 | val, err = actual().Result() 407 | Expect(err).To(Equal(setErr)) 408 | Expect(val).To(Equal([]redis.XMessage(nil))) 409 | 410 | base.ClearExpect() 411 | expected() 412 | val, err = actual().Result() 413 | Expect(err).To(HaveOccurred()) 414 | Expect(val).To(Equal([]redis.XMessage(nil))) 415 | 416 | base.ClearExpect() 417 | expected().SetVal([]redis.XMessage{ 418 | {ID: "1-0", Values: map[string]interface{}{"uno": "un"}}, 419 | {ID: "2-0", Values: map[string]interface{}{"dos": "deux"}}, 420 | {ID: "3-0", Values: map[string]interface{}{"tres": "troix"}}, 421 | }) 422 | val, err = actual().Result() 423 | Expect(err).NotTo(HaveOccurred()) 424 | Expect(val).To(Equal([]redis.XMessage{ 425 | {ID: "1-0", Values: map[string]interface{}{"uno": "un"}}, 426 | {ID: "2-0", Values: map[string]interface{}{"dos": "deux"}}, 427 | {ID: "3-0", Values: map[string]interface{}{"tres": "troix"}}, 428 | })) 429 | } 430 | 431 | func operationXStreamSliceCmd(base baseMock, expected func() *ExpectedXStreamSlice, actual func() *redis.XStreamSliceCmd) { 432 | var ( 433 | setErr = errors.New("x stream slice cmd error") 434 | val []redis.XStream 435 | err error 436 | ) 437 | 438 | base.ClearExpect() 439 | expected().SetErr(setErr) 440 | val, err = actual().Result() 441 | Expect(err).To(Equal(setErr)) 442 | Expect(val).To(Equal([]redis.XStream(nil))) 443 | 444 | base.ClearExpect() 445 | expected() 446 | val, err = actual().Result() 447 | Expect(err).To(HaveOccurred()) 448 | Expect(val).To(Equal([]redis.XStream(nil))) 449 | 450 | base.ClearExpect() 451 | expected().SetVal([]redis.XStream{{ 452 | Stream: "stream", 453 | Messages: []redis.XMessage{ 454 | {ID: "1-0", Values: map[string]interface{}{"uno": "un"}}, 455 | {ID: "2-0", Values: map[string]interface{}{"dos": "deux"}}, 456 | }}, 457 | }) 458 | val, err = actual().Result() 459 | Expect(err).NotTo(HaveOccurred()) 460 | Expect(val).To(Equal([]redis.XStream{{ 461 | Stream: "stream", 462 | Messages: []redis.XMessage{ 463 | {ID: "1-0", Values: map[string]interface{}{"uno": "un"}}, 464 | {ID: "2-0", Values: map[string]interface{}{"dos": "deux"}}, 465 | }}, 466 | })) 467 | } 468 | 469 | func operationXPendingCmd(base baseMock, expected func() *ExpectedXPending, actual func() *redis.XPendingCmd) { 470 | var ( 471 | setErr = errors.New("x pending cmd error") 472 | val *redis.XPending 473 | valNil *redis.XPending 474 | err error 475 | ) 476 | 477 | base.ClearExpect() 478 | expected().SetErr(setErr) 479 | val, err = actual().Result() 480 | Expect(err).To(Equal(setErr)) 481 | Expect(val).To(Equal(valNil)) 482 | 483 | base.ClearExpect() 484 | expected() 485 | val, err = actual().Result() 486 | Expect(err).To(HaveOccurred()) 487 | Expect(val).To(Equal(valNil)) 488 | 489 | base.ClearExpect() 490 | expected().SetVal(&redis.XPending{ 491 | Count: 3, 492 | Lower: "1-0", 493 | Higher: "3-0", 494 | Consumers: map[string]int64{"consumer": 3}, 495 | }) 496 | val, err = actual().Result() 497 | Expect(err).NotTo(HaveOccurred()) 498 | Expect(val).To(Equal(&redis.XPending{ 499 | Count: 3, 500 | Lower: "1-0", 501 | Higher: "3-0", 502 | Consumers: map[string]int64{"consumer": 3}, 503 | })) 504 | } 505 | 506 | func operationXPendingExtCmd(base baseMock, expected func() *ExpectedXPendingExt, actual func() *redis.XPendingExtCmd) { 507 | var ( 508 | setErr = errors.New("x pending ext cmd error") 509 | val []redis.XPendingExt 510 | err error 511 | ) 512 | 513 | base.ClearExpect() 514 | expected().SetErr(setErr) 515 | val, err = actual().Result() 516 | Expect(err).To(Equal(setErr)) 517 | Expect(val).To(Equal([]redis.XPendingExt(nil))) 518 | 519 | base.ClearExpect() 520 | expected() 521 | val, err = actual().Result() 522 | Expect(err).To(HaveOccurred()) 523 | Expect(val).To(Equal([]redis.XPendingExt(nil))) 524 | 525 | base.ClearExpect() 526 | expected().SetVal([]redis.XPendingExt{ 527 | {ID: "1-0", Consumer: "consumer", Idle: 0, RetryCount: 1}, 528 | {ID: "2-0", Consumer: "consumer", Idle: 0, RetryCount: 1}, 529 | {ID: "3-0", Consumer: "consumer", Idle: 0, RetryCount: 1}, 530 | }) 531 | val, err = actual().Result() 532 | Expect(err).NotTo(HaveOccurred()) 533 | Expect(val).To(Equal([]redis.XPendingExt{ 534 | {ID: "1-0", Consumer: "consumer", Idle: 0, RetryCount: 1}, 535 | {ID: "2-0", Consumer: "consumer", Idle: 0, RetryCount: 1}, 536 | {ID: "3-0", Consumer: "consumer", Idle: 0, RetryCount: 1}, 537 | })) 538 | } 539 | 540 | func operationXAutoClaimCmd(base baseMock, expected func() *ExpectedXAutoClaim, actual func() *redis.XAutoClaimCmd) { 541 | var ( 542 | setErr = errors.New("x auto claim cmd error") 543 | start string 544 | val []redis.XMessage 545 | err error 546 | ) 547 | 548 | base.ClearExpect() 549 | expected().SetErr(setErr) 550 | val, start, err = actual().Result() 551 | Expect(err).To(Equal(setErr)) 552 | Expect(start).To(Equal("")) 553 | Expect(val).To(Equal([]redis.XMessage(nil))) 554 | 555 | base.ClearExpect() 556 | expected() 557 | val, start, err = actual().Result() 558 | Expect(err).To(HaveOccurred()) 559 | Expect(start).To(Equal("")) 560 | Expect(val).To(Equal([]redis.XMessage(nil))) 561 | 562 | base.ClearExpect() 563 | expected().SetVal([]redis.XMessage{ 564 | {ID: "1-0", Values: map[string]interface{}{"uno": "un"}}, 565 | {ID: "2-0", Values: map[string]interface{}{"dos": "deux"}}, 566 | {ID: "3-0", Values: map[string]interface{}{"tres": "troix"}}, 567 | }, "3-0") 568 | val, start, err = actual().Result() 569 | Expect(err).NotTo(HaveOccurred()) 570 | Expect(start).To(Equal("3-0")) 571 | Expect(val).To(Equal([]redis.XMessage{ 572 | {ID: "1-0", Values: map[string]interface{}{"uno": "un"}}, 573 | {ID: "2-0", Values: map[string]interface{}{"dos": "deux"}}, 574 | {ID: "3-0", Values: map[string]interface{}{"tres": "troix"}}, 575 | })) 576 | } 577 | 578 | func operationXAutoClaimJustIDCmd(base baseMock, expected func() *ExpectedXAutoClaimJustID, actual func() *redis.XAutoClaimJustIDCmd) { 579 | var ( 580 | setErr = errors.New("x auto claim just id cmd error") 581 | start string 582 | val []string 583 | err error 584 | ) 585 | 586 | base.ClearExpect() 587 | expected().SetErr(setErr) 588 | val, start, err = actual().Result() 589 | Expect(err).To(Equal(setErr)) 590 | Expect(start).To(Equal("")) 591 | Expect(val).To(Equal([]string(nil))) 592 | 593 | base.ClearExpect() 594 | expected() 595 | val, start, err = actual().Result() 596 | Expect(err).To(HaveOccurred()) 597 | Expect(start).To(Equal("")) 598 | Expect(val).To(Equal([]string(nil))) 599 | 600 | base.ClearExpect() 601 | expected().SetVal([]string{"1-0", "2-0", "3-0"}, "3-0") 602 | val, start, err = actual().Result() 603 | Expect(err).NotTo(HaveOccurred()) 604 | Expect(start).To(Equal("3-0")) 605 | Expect(val).To(Equal([]string{"1-0", "2-0", "3-0"})) 606 | } 607 | 608 | func operationXInfoGroupsCmd(base baseMock, expected func() *ExpectedXInfoGroups, actual func() *redis.XInfoGroupsCmd) { 609 | var ( 610 | setErr = errors.New("x info group cmd error") 611 | val []redis.XInfoGroup 612 | err error 613 | ) 614 | 615 | base.ClearExpect() 616 | expected().SetErr(setErr) 617 | val, err = actual().Result() 618 | Expect(err).To(Equal(setErr)) 619 | Expect(val).To(Equal([]redis.XInfoGroup(nil))) 620 | 621 | base.ClearExpect() 622 | expected() 623 | val, err = actual().Result() 624 | Expect(err).To(HaveOccurred()) 625 | Expect(val).To(Equal([]redis.XInfoGroup(nil))) 626 | 627 | base.ClearExpect() 628 | expected().SetVal([]redis.XInfoGroup{ 629 | {Name: "name1", Consumers: 1, Pending: 2, LastDeliveredID: "last1"}, 630 | {Name: "name2", Consumers: 1, Pending: 2, LastDeliveredID: "last2"}, 631 | {Name: "name3", Consumers: 1, Pending: 2, LastDeliveredID: "last2"}, 632 | }) 633 | val, err = actual().Result() 634 | Expect(err).NotTo(HaveOccurred()) 635 | Expect(val).To(Equal([]redis.XInfoGroup{ 636 | {Name: "name1", Consumers: 1, Pending: 2, LastDeliveredID: "last1"}, 637 | {Name: "name2", Consumers: 1, Pending: 2, LastDeliveredID: "last2"}, 638 | {Name: "name3", Consumers: 1, Pending: 2, LastDeliveredID: "last2"}, 639 | })) 640 | } 641 | 642 | func operationXInfoStreamCmd(base baseMock, expected func() *ExpectedXInfoStream, actual func() *redis.XInfoStreamCmd) { 643 | var ( 644 | setErr = errors.New("x info stream cmd error") 645 | val *redis.XInfoStream 646 | nilVal *redis.XInfoStream 647 | err error 648 | ) 649 | 650 | base.ClearExpect() 651 | expected().SetErr(setErr) 652 | val, err = actual().Result() 653 | Expect(err).To(Equal(setErr)) 654 | Expect(val).To(Equal(nilVal)) 655 | 656 | base.ClearExpect() 657 | expected() 658 | val, err = actual().Result() 659 | Expect(err).To(HaveOccurred()) 660 | Expect(val).To(Equal(nilVal)) 661 | 662 | base.ClearExpect() 663 | expected().SetVal(&redis.XInfoStream{ 664 | Length: 1, 665 | RadixTreeKeys: 10, 666 | RadixTreeNodes: 20, 667 | Groups: 30, 668 | LastGeneratedID: "id", 669 | FirstEntry: redis.XMessage{ 670 | ID: "first_id", 671 | Values: map[string]interface{}{ 672 | "first_key": "first_value", 673 | }, 674 | }, 675 | LastEntry: redis.XMessage{ 676 | ID: "last_id", 677 | Values: map[string]interface{}{ 678 | "last_key": "last_value", 679 | }, 680 | }, 681 | }) 682 | val, err = actual().Result() 683 | Expect(err).NotTo(HaveOccurred()) 684 | Expect(val).To(Equal(&redis.XInfoStream{ 685 | Length: 1, 686 | RadixTreeKeys: 10, 687 | RadixTreeNodes: 20, 688 | Groups: 30, 689 | LastGeneratedID: "id", 690 | FirstEntry: redis.XMessage{ 691 | ID: "first_id", 692 | Values: map[string]interface{}{ 693 | "first_key": "first_value", 694 | }, 695 | }, 696 | LastEntry: redis.XMessage{ 697 | ID: "last_id", 698 | Values: map[string]interface{}{ 699 | "last_key": "last_value", 700 | }, 701 | }, 702 | })) 703 | } 704 | 705 | func operationXInfoConsumersCmd(base baseMock, expected func() *ExpectedXInfoConsumers, actual func() *redis.XInfoConsumersCmd) { 706 | var ( 707 | setErr = errors.New("x info consumers cmd error") 708 | val []redis.XInfoConsumer 709 | err error 710 | ) 711 | 712 | base.ClearExpect() 713 | expected().SetErr(setErr) 714 | val, err = actual().Result() 715 | Expect(err).To(Equal(setErr)) 716 | Expect(val).To(Equal([]redis.XInfoConsumer(nil))) 717 | 718 | base.ClearExpect() 719 | expected() 720 | val, err = actual().Result() 721 | Expect(err).To(HaveOccurred()) 722 | Expect(val).To(Equal([]redis.XInfoConsumer(nil))) 723 | 724 | base.ClearExpect() 725 | expected().SetVal([]redis.XInfoConsumer{ 726 | { 727 | Name: "c1", 728 | Pending: 2, 729 | Idle: 1, 730 | }, 731 | { 732 | Name: "c2", 733 | Pending: 1, 734 | Idle: 2, 735 | }, 736 | }) 737 | val, err = actual().Result() 738 | Expect(err).NotTo(HaveOccurred()) 739 | Expect(val).To(Equal([]redis.XInfoConsumer{ 740 | { 741 | Name: "c1", 742 | Pending: 2, 743 | Idle: 1, 744 | }, 745 | { 746 | Name: "c2", 747 | Pending: 1, 748 | Idle: 2, 749 | }, 750 | })) 751 | } 752 | 753 | func operationXInfoStreamFullCmd(base baseMock, expected func() *ExpectedXInfoStreamFull, actual func() *redis.XInfoStreamFullCmd) { 754 | var ( 755 | setErr = errors.New("x info stream full cmd error") 756 | val *redis.XInfoStreamFull 757 | valNil *redis.XInfoStreamFull 758 | err error 759 | ) 760 | 761 | base.ClearExpect() 762 | expected().SetErr(setErr) 763 | val, err = actual().Result() 764 | Expect(err).To(Equal(setErr)) 765 | Expect(val).To(Equal(valNil)) 766 | 767 | base.ClearExpect() 768 | expected() 769 | val, err = actual().Result() 770 | Expect(err).To(HaveOccurred()) 771 | Expect(val).To(Equal(valNil)) 772 | 773 | now := time.Now() 774 | now2 := now.Add(3 * time.Hour) 775 | now3 := now.Add(5 * time.Hour) 776 | now4 := now.Add(6 * time.Hour) 777 | now5 := now.Add(8 * time.Hour) 778 | now6 := now.Add(9 * time.Hour) 779 | base.ClearExpect() 780 | expected().SetVal(&redis.XInfoStreamFull{ 781 | Length: 3, 782 | RadixTreeKeys: 4, 783 | RadixTreeNodes: 5, 784 | LastGeneratedID: "3-3", 785 | Entries: []redis.XMessage{ 786 | { 787 | ID: "1-0", 788 | Values: map[string]interface{}{ 789 | "key1": "val1", 790 | "key2": "val2", 791 | }, 792 | }, 793 | }, 794 | Groups: []redis.XInfoStreamGroup{ 795 | { 796 | Name: "group1", 797 | LastDeliveredID: "10-1", 798 | PelCount: 3, 799 | Pending: []redis.XInfoStreamGroupPending{ 800 | { 801 | ID: "5-1", 802 | Consumer: "consumer1", 803 | DeliveryTime: now, 804 | DeliveryCount: 9, 805 | }, 806 | { 807 | ID: "5-2", 808 | Consumer: "consumer2", 809 | DeliveryTime: now, 810 | DeliveryCount: 8, 811 | }, 812 | }, 813 | Consumers: []redis.XInfoStreamConsumer{ 814 | { 815 | Name: "consumer3", 816 | SeenTime: now2, 817 | PelCount: 7, 818 | Pending: []redis.XInfoStreamConsumerPending{ 819 | { 820 | ID: "6-1", 821 | DeliveryTime: now3, 822 | DeliveryCount: 3, 823 | }, 824 | { 825 | ID: "6-2", 826 | DeliveryTime: now4, 827 | DeliveryCount: 2, 828 | }, 829 | }, 830 | }, 831 | { 832 | Name: "consumer4", 833 | SeenTime: now, 834 | PelCount: 6, 835 | Pending: []redis.XInfoStreamConsumerPending{ 836 | { 837 | ID: "7-1", 838 | DeliveryTime: now5, 839 | DeliveryCount: 5, 840 | }, 841 | { 842 | ID: "8-2", 843 | DeliveryTime: now6, 844 | DeliveryCount: 6, 845 | }, 846 | }, 847 | }, 848 | }, 849 | }, 850 | }, 851 | }) 852 | val, err = actual().Result() 853 | Expect(err).NotTo(HaveOccurred()) 854 | Expect(val).To(Equal(&redis.XInfoStreamFull{ 855 | Length: 3, 856 | RadixTreeKeys: 4, 857 | RadixTreeNodes: 5, 858 | LastGeneratedID: "3-3", 859 | Entries: []redis.XMessage{ 860 | { 861 | ID: "1-0", 862 | Values: map[string]interface{}{ 863 | "key1": "val1", 864 | "key2": "val2", 865 | }, 866 | }, 867 | }, 868 | Groups: []redis.XInfoStreamGroup{ 869 | { 870 | Name: "group1", 871 | LastDeliveredID: "10-1", 872 | PelCount: 3, 873 | Pending: []redis.XInfoStreamGroupPending{ 874 | { 875 | ID: "5-1", 876 | Consumer: "consumer1", 877 | DeliveryTime: now, 878 | DeliveryCount: 9, 879 | }, 880 | { 881 | ID: "5-2", 882 | Consumer: "consumer2", 883 | DeliveryTime: now, 884 | DeliveryCount: 8, 885 | }, 886 | }, 887 | Consumers: []redis.XInfoStreamConsumer{ 888 | { 889 | Name: "consumer3", 890 | SeenTime: now2, 891 | PelCount: 7, 892 | Pending: []redis.XInfoStreamConsumerPending{ 893 | { 894 | ID: "6-1", 895 | DeliveryTime: now3, 896 | DeliveryCount: 3, 897 | }, 898 | { 899 | ID: "6-2", 900 | DeliveryTime: now4, 901 | DeliveryCount: 2, 902 | }, 903 | }, 904 | }, 905 | { 906 | Name: "consumer4", 907 | SeenTime: now, 908 | PelCount: 6, 909 | Pending: []redis.XInfoStreamConsumerPending{ 910 | { 911 | ID: "7-1", 912 | DeliveryTime: now5, 913 | DeliveryCount: 5, 914 | }, 915 | { 916 | ID: "8-2", 917 | DeliveryTime: now6, 918 | DeliveryCount: 6, 919 | }, 920 | }, 921 | }, 922 | }, 923 | }, 924 | }, 925 | })) 926 | } 927 | 928 | func operationZWithKeyCmd(base baseMock, expected func() *ExpectedZWithKey, actual func() *redis.ZWithKeyCmd) { 929 | var ( 930 | setErr = errors.New("z with key cmd error") 931 | val *redis.ZWithKey 932 | valNil *redis.ZWithKey 933 | err error 934 | ) 935 | 936 | base.ClearExpect() 937 | expected().SetErr(setErr) 938 | val, err = actual().Result() 939 | Expect(err).To(Equal(setErr)) 940 | Expect(val).To(Equal(valNil)) 941 | 942 | base.ClearExpect() 943 | expected() 944 | val, err = actual().Result() 945 | Expect(err).To(HaveOccurred()) 946 | Expect(val).To(Equal(valNil)) 947 | 948 | base.ClearExpect() 949 | expected().SetVal(&redis.ZWithKey{ 950 | Z: redis.Z{ 951 | Score: 3, 952 | Member: "three", 953 | }, 954 | Key: "zset1", 955 | }) 956 | val, err = actual().Result() 957 | Expect(err).NotTo(HaveOccurred()) 958 | Expect(val).To(Equal(&redis.ZWithKey{ 959 | Z: redis.Z{ 960 | Score: 3, 961 | Member: "three", 962 | }, 963 | Key: "zset1", 964 | })) 965 | } 966 | 967 | func operationZSliceCmd(base baseMock, expected func() *ExpectedZSlice, actual func() *redis.ZSliceCmd) { 968 | var ( 969 | setErr = errors.New("z slice cmd error") 970 | val []redis.Z 971 | err error 972 | ) 973 | 974 | base.ClearExpect() 975 | expected().SetErr(setErr) 976 | val, err = actual().Result() 977 | Expect(err).To(Equal(setErr)) 978 | Expect(val).To(Equal([]redis.Z(nil))) 979 | 980 | base.ClearExpect() 981 | expected() 982 | val, err = actual().Result() 983 | Expect(err).To(HaveOccurred()) 984 | Expect(val).To(Equal([]redis.Z(nil))) 985 | 986 | base.ClearExpect() 987 | expected().SetVal([]redis.Z{{ 988 | Score: 5, 989 | Member: "one", 990 | }, { 991 | Score: 10, 992 | Member: "two", 993 | }}) 994 | val, err = actual().Result() 995 | Expect(err).NotTo(HaveOccurred()) 996 | Expect(val).To(Equal([]redis.Z{{ 997 | Score: 5, 998 | Member: "one", 999 | }, { 1000 | Score: 10, 1001 | Member: "two", 1002 | }})) 1003 | } 1004 | 1005 | func operationTimeCmd(base baseMock, expected func() *ExpectedTime, actual func() *redis.TimeCmd) { 1006 | var ( 1007 | setErr = errors.New("time cmd error") 1008 | val time.Time 1009 | err error 1010 | ) 1011 | 1012 | base.ClearExpect() 1013 | expected().SetErr(setErr) 1014 | val, err = actual().Result() 1015 | Expect(err).To(Equal(setErr)) 1016 | Expect(val).To(Equal(time.Time{})) 1017 | 1018 | base.ClearExpect() 1019 | expected() 1020 | val, err = actual().Result() 1021 | Expect(err).To(HaveOccurred()) 1022 | Expect(val).To(Equal(time.Time{})) 1023 | 1024 | base.ClearExpect() 1025 | now := time.Now() 1026 | expected().SetVal(now) 1027 | val, err = actual().Result() 1028 | Expect(err).NotTo(HaveOccurred()) 1029 | Expect(val).To(Equal(now)) 1030 | } 1031 | 1032 | func operationCmdCmd(base baseMock, expected func() *ExpectedCmd, actual func() *redis.Cmd) { 1033 | var ( 1034 | setErr = errors.New("cmd error") 1035 | val interface{} 1036 | err error 1037 | ) 1038 | 1039 | base.ClearExpect() 1040 | expected().SetErr(setErr) 1041 | val, err = actual().Result() 1042 | Expect(err).To(Equal(setErr)) 1043 | Expect(val).To(BeNil()) 1044 | 1045 | base.ClearExpect() 1046 | expected() 1047 | val, err = actual().Result() 1048 | Expect(err).To(HaveOccurred()) 1049 | Expect(val).To(BeNil()) 1050 | 1051 | base.ClearExpect() 1052 | expected().SetVal(interface{}(1024)) 1053 | val, err = actual().Result() 1054 | Expect(err).NotTo(HaveOccurred()) 1055 | Expect(val).To(Equal(interface{}(1024))) 1056 | } 1057 | 1058 | func operationBoolSliceCmd(base baseMock, expected func() *ExpectedBoolSlice, actual func() *redis.BoolSliceCmd) { 1059 | var ( 1060 | setErr = errors.New("bool slice cmd error") 1061 | val []bool 1062 | err error 1063 | ) 1064 | 1065 | base.ClearExpect() 1066 | expected().SetErr(setErr) 1067 | val, err = actual().Result() 1068 | Expect(err).To(Equal(setErr)) 1069 | Expect(val).To(Equal([]bool(nil))) 1070 | 1071 | base.ClearExpect() 1072 | expected() 1073 | val, err = actual().Result() 1074 | Expect(err).To(HaveOccurred()) 1075 | Expect(val).To(Equal([]bool(nil))) 1076 | 1077 | base.ClearExpect() 1078 | expected().SetVal([]bool{true, false, true}) 1079 | val, err = actual().Result() 1080 | Expect(err).NotTo(HaveOccurred()) 1081 | Expect(val).To(Equal([]bool{true, false, true})) 1082 | } 1083 | 1084 | func operationMapStringIntCmd(base baseMock, expected func() *ExpectedMapStringInt, actual func() *redis.MapStringIntCmd) { 1085 | var ( 1086 | setErr = errors.New("map string int cmd error") 1087 | val map[string]int64 1088 | err error 1089 | ) 1090 | 1091 | base.ClearExpect() 1092 | expected().SetErr(setErr) 1093 | val, err = actual().Result() 1094 | Expect(err).To(Equal(setErr)) 1095 | Expect(val).To(Equal(map[string]int64(nil))) 1096 | 1097 | base.ClearExpect() 1098 | expected() 1099 | val, err = actual().Result() 1100 | Expect(err).To(HaveOccurred()) 1101 | Expect(val).To(Equal(map[string]int64(nil))) 1102 | 1103 | base.ClearExpect() 1104 | expected().SetVal(map[string]int64{"key": 1, "key2": 2}) 1105 | val, err = actual().Result() 1106 | Expect(err).NotTo(HaveOccurred()) 1107 | Expect(val).To(Equal(map[string]int64{"key": 1, "key2": 2})) 1108 | } 1109 | 1110 | func operationClusterSlotsCmd(base baseMock, expected func() *ExpectedClusterSlots, actual func() *redis.ClusterSlotsCmd) { 1111 | var ( 1112 | setErr = errors.New("cluster slots cmd error") 1113 | val []redis.ClusterSlot 1114 | err error 1115 | ) 1116 | 1117 | base.ClearExpect() 1118 | expected().SetErr(setErr) 1119 | val, err = actual().Result() 1120 | Expect(err).To(Equal(setErr)) 1121 | Expect(val).To(Equal([]redis.ClusterSlot(nil))) 1122 | 1123 | base.ClearExpect() 1124 | expected() 1125 | val, err = actual().Result() 1126 | Expect(err).To(HaveOccurred()) 1127 | Expect(val).To(Equal([]redis.ClusterSlot(nil))) 1128 | 1129 | base.ClearExpect() 1130 | expected().SetVal([]redis.ClusterSlot{ 1131 | {Start: 1, End: 2, Nodes: []redis.ClusterNode{ 1132 | {ID: "1", Addr: "1.1.1.1"}, 1133 | {ID: "2", Addr: "2.2.2.2"}, 1134 | }}, 1135 | }) 1136 | val, err = actual().Result() 1137 | Expect(err).NotTo(HaveOccurred()) 1138 | Expect(val).To(Equal([]redis.ClusterSlot{ 1139 | {Start: 1, End: 2, Nodes: []redis.ClusterNode{ 1140 | {ID: "1", Addr: "1.1.1.1"}, 1141 | {ID: "2", Addr: "2.2.2.2"}, 1142 | }}, 1143 | })) 1144 | } 1145 | 1146 | func operationClusterLinksCmd(base baseMock, expected func() *ExpectedClusterLinks, actual func() *redis.ClusterLinksCmd) { 1147 | var ( 1148 | setErr = errors.New("cluster links cmd error") 1149 | val []redis.ClusterLink 1150 | err error 1151 | ) 1152 | 1153 | base.ClearExpect() 1154 | expected().SetErr(setErr) 1155 | val, err = actual().Result() 1156 | Expect(err).To(Equal(setErr)) 1157 | Expect(val).To(Equal([]redis.ClusterLink(nil))) 1158 | 1159 | base.ClearExpect() 1160 | expected() 1161 | val, err = actual().Result() 1162 | Expect(err).To(HaveOccurred()) 1163 | Expect(val).To(Equal([]redis.ClusterLink(nil))) 1164 | 1165 | links := []redis.ClusterLink{ 1166 | { 1167 | Direction: "to", 1168 | Node: "8149d745fa551e40764fecaf7cab9dbdf6b659ae", 1169 | CreateTime: 1639442739375, 1170 | Events: "rw", 1171 | SendBufferAllocated: 4512, 1172 | SendBufferUsed: 1254, 1173 | }, 1174 | { 1175 | Direction: "from", 1176 | Node: "8149d745fa551e40764fecaf7cab9dbdf6b659ae", 1177 | CreateTime: 1639442739411, 1178 | Events: "r", 1179 | SendBufferAllocated: 0, 1180 | SendBufferUsed: 0, 1181 | }, 1182 | } 1183 | 1184 | base.ClearExpect() 1185 | expected().SetVal(links) 1186 | val, err = actual().Result() 1187 | Expect(err).NotTo(HaveOccurred()) 1188 | Expect(val).To(Equal(links)) 1189 | } 1190 | 1191 | func operationGeoLocationCmd(base baseMock, expected func() *ExpectedGeoLocation, actual func() *redis.GeoLocationCmd) { 1192 | var ( 1193 | setErr = errors.New("geo location cmd error") 1194 | val []redis.GeoLocation 1195 | err error 1196 | ) 1197 | 1198 | base.ClearExpect() 1199 | expected().SetErr(setErr) 1200 | val, err = actual().Result() 1201 | Expect(err).To(Equal(setErr)) 1202 | Expect(val).To(Equal([]redis.GeoLocation(nil))) 1203 | 1204 | base.ClearExpect() 1205 | expected() 1206 | val, err = actual().Result() 1207 | Expect(err).To(HaveOccurred()) 1208 | Expect(val).To(Equal([]redis.GeoLocation(nil))) 1209 | 1210 | base.ClearExpect() 1211 | expected().SetVal([]redis.GeoLocation{ 1212 | {Longitude: 13.361389, Latitude: 38.115556, Name: "Palermo"}, 1213 | {Longitude: 15.087269, Latitude: 37.502669, Name: "Catania"}, 1214 | }) 1215 | val, err = actual().Result() 1216 | Expect(err).NotTo(HaveOccurred()) 1217 | Expect(val).To(Equal([]redis.GeoLocation{ 1218 | {Longitude: 13.361389, Latitude: 38.115556, Name: "Palermo"}, 1219 | {Longitude: 15.087269, Latitude: 37.502669, Name: "Catania"}, 1220 | })) 1221 | } 1222 | 1223 | func operationGeoPosCmd(base baseMock, expected func() *ExpectedGeoPos, actual func() *redis.GeoPosCmd) { 1224 | var ( 1225 | setErr = errors.New("geo pos cmd error") 1226 | val []*redis.GeoPos 1227 | err error 1228 | ) 1229 | 1230 | base.ClearExpect() 1231 | expected().SetErr(setErr) 1232 | val, err = actual().Result() 1233 | Expect(err).To(Equal(setErr)) 1234 | Expect(val).To(Equal([]*redis.GeoPos(nil))) 1235 | 1236 | base.ClearExpect() 1237 | expected() 1238 | val, err = actual().Result() 1239 | Expect(err).To(HaveOccurred()) 1240 | Expect(val).To(Equal([]*redis.GeoPos(nil))) 1241 | 1242 | base.ClearExpect() 1243 | expected().SetVal([]*redis.GeoPos{ 1244 | { 1245 | Longitude: 13.361389338970184, 1246 | Latitude: 38.1155563954963, 1247 | }, 1248 | { 1249 | Longitude: 15.087267458438873, 1250 | Latitude: 37.50266842333162, 1251 | }, 1252 | }) 1253 | val, err = actual().Result() 1254 | Expect(err).NotTo(HaveOccurred()) 1255 | Expect(val).To(Equal([]*redis.GeoPos{ 1256 | { 1257 | Longitude: 13.361389338970184, 1258 | Latitude: 38.1155563954963, 1259 | }, 1260 | { 1261 | Longitude: 15.087267458438873, 1262 | Latitude: 37.50266842333162, 1263 | }, 1264 | })) 1265 | } 1266 | 1267 | func operationGeoSearchLocationCmd(base baseMock, expected func() *ExpectedGeoSearchLocation, actual func() *redis.GeoSearchLocationCmd) { 1268 | var ( 1269 | setErr = errors.New("geo search location cmd error") 1270 | val []redis.GeoLocation 1271 | err error 1272 | ) 1273 | 1274 | base.ClearExpect() 1275 | expected().SetErr(setErr) 1276 | val, err = actual().Result() 1277 | Expect(err).To(Equal(setErr)) 1278 | Expect(val).To(Equal([]redis.GeoLocation(nil))) 1279 | 1280 | base.ClearExpect() 1281 | expected() 1282 | val, err = actual().Result() 1283 | Expect(err).To(HaveOccurred()) 1284 | Expect(val).To(Equal([]redis.GeoLocation(nil))) 1285 | 1286 | base.ClearExpect() 1287 | expected().SetVal([]redis.GeoLocation{ 1288 | { 1289 | Name: "Catania", 1290 | Longitude: 15.08726745843887329, 1291 | Latitude: 37.50266842333162032, 1292 | Dist: 56.4413, 1293 | GeoHash: 3479447370796909, 1294 | }, 1295 | { 1296 | Name: "Palermo", 1297 | Longitude: 13.36138933897018433, 1298 | Latitude: 38.11555639549629859, 1299 | Dist: 190.4424, 1300 | GeoHash: 3479099956230698, 1301 | }, 1302 | }) 1303 | val, err = actual().Result() 1304 | Expect(err).NotTo(HaveOccurred()) 1305 | Expect(val).To(Equal([]redis.GeoLocation{ 1306 | { 1307 | Name: "Catania", 1308 | Longitude: 15.08726745843887329, 1309 | Latitude: 37.50266842333162032, 1310 | Dist: 56.4413, 1311 | GeoHash: 3479447370796909, 1312 | }, 1313 | { 1314 | Name: "Palermo", 1315 | Longitude: 13.36138933897018433, 1316 | Latitude: 38.11555639549629859, 1317 | Dist: 190.4424, 1318 | GeoHash: 3479099956230698, 1319 | }, 1320 | })) 1321 | } 1322 | 1323 | func operationSlowLogCmd(base baseMock, expected func() *ExpectedSlowLog, actual func() *redis.SlowLogCmd) { 1324 | var ( 1325 | setErr = errors.New("slow log cmd error") 1326 | val []redis.SlowLog 1327 | err error 1328 | ) 1329 | 1330 | base.ClearExpect() 1331 | expected().SetErr(setErr) 1332 | val, err = actual().Result() 1333 | Expect(err).To(Equal(setErr)) 1334 | Expect(val).To(Equal([]redis.SlowLog(nil))) 1335 | 1336 | base.ClearExpect() 1337 | expected() 1338 | val, err = actual().Result() 1339 | Expect(err).To(HaveOccurred()) 1340 | Expect(val).To(Equal([]redis.SlowLog(nil))) 1341 | 1342 | now := time.Now() 1343 | now1 := now.Add(time.Hour) 1344 | base.ClearExpect() 1345 | expected().SetVal([]redis.SlowLog{ 1346 | { 1347 | ID: 1, 1348 | Time: now, 1349 | Duration: 3 * time.Millisecond, 1350 | Args: []string{"a", "b", "c"}, 1351 | ClientAddr: "127.0.0.1:1234", 1352 | ClientName: "client_hi", 1353 | }, 1354 | { 1355 | ID: 2, 1356 | Time: now1, 1357 | Duration: 4 * time.Millisecond, 1358 | Args: []string{"x", "y", "z"}, 1359 | ClientAddr: "127.0.0.1:6379", 1360 | ClientName: "client_hi", 1361 | }, 1362 | }) 1363 | val, err = actual().Result() 1364 | Expect(err).NotTo(HaveOccurred()) 1365 | Expect(val).To(Equal([]redis.SlowLog{ 1366 | { 1367 | ID: 1, 1368 | Time: now, 1369 | Duration: 3 * time.Millisecond, 1370 | Args: []string{"a", "b", "c"}, 1371 | ClientAddr: "127.0.0.1:1234", 1372 | ClientName: "client_hi", 1373 | }, 1374 | { 1375 | ID: 2, 1376 | Time: now1, 1377 | Duration: 4 * time.Millisecond, 1378 | Args: []string{"x", "y", "z"}, 1379 | ClientAddr: "127.0.0.1:6379", 1380 | ClientName: "client_hi", 1381 | }, 1382 | })) 1383 | } 1384 | 1385 | func operationKeyValuesCmd(base baseMock, expected func() *ExpectedKeyValues, actual func() *redis.KeyValuesCmd) { 1386 | var ( 1387 | setErr = errors.New("key values cmd error") 1388 | key string 1389 | val []string 1390 | err error 1391 | ) 1392 | 1393 | base.ClearExpect() 1394 | expected().SetErr(setErr) 1395 | key, val, err = actual().Result() 1396 | Expect(err).To(Equal(setErr)) 1397 | Expect(key).To(Equal("")) 1398 | Expect(val).To(Equal([]string(nil))) 1399 | 1400 | base.ClearExpect() 1401 | expected() 1402 | key, val, err = actual().Result() 1403 | Expect(err).To(HaveOccurred()) 1404 | Expect(key).To(Equal("")) 1405 | Expect(val).To(Equal([]string(nil))) 1406 | 1407 | base.ClearExpect() 1408 | expected().SetVal("key1", []string{"v1", "v2"}) 1409 | key, val, err = actual().Result() 1410 | Expect(err).NotTo(HaveOccurred()) 1411 | Expect(key).To(Equal("key1")) 1412 | Expect(val).To(Equal([]string{"v1", "v2"})) 1413 | } 1414 | 1415 | func operationZSliceWithKeyCmd(base baseMock, expected func() *ExpectedZSliceWithKey, actual func() *redis.ZSliceWithKeyCmd) { 1416 | var ( 1417 | setErr = errors.New("z slice with key cmd error") 1418 | key string 1419 | val []redis.Z 1420 | err error 1421 | ) 1422 | 1423 | base.ClearExpect() 1424 | expected().SetErr(setErr) 1425 | key, val, err = actual().Result() 1426 | Expect(err).To(Equal(setErr)) 1427 | Expect(key).To(Equal("")) 1428 | Expect(val).To(Equal([]redis.Z(nil))) 1429 | 1430 | base.ClearExpect() 1431 | expected() 1432 | key, val, err = actual().Result() 1433 | Expect(err).To(HaveOccurred()) 1434 | Expect(key).To(Equal("")) 1435 | Expect(val).To(Equal([]redis.Z(nil))) 1436 | 1437 | base.ClearExpect() 1438 | expected().SetVal("key1", []redis.Z{ 1439 | {Score: 100, Member: "one"}, 1440 | {Score: 200, Member: "two"}, 1441 | }) 1442 | key, val, err = actual().Result() 1443 | Expect(err).NotTo(HaveOccurred()) 1444 | Expect(key).To(Equal("key1")) 1445 | Expect(val).To(Equal([]redis.Z{ 1446 | {Score: 100, Member: "one"}, 1447 | {Score: 200, Member: "two"}, 1448 | })) 1449 | } 1450 | 1451 | func operationFunctionListCmd(base baseMock, expected func() *ExpectedFunctionList, actual func() *redis.FunctionListCmd) { 1452 | var ( 1453 | setErr = errors.New("function list cmd error") 1454 | val []redis.Library 1455 | err error 1456 | ) 1457 | 1458 | base.ClearExpect() 1459 | expected().SetErr(setErr) 1460 | val, err = actual().Result() 1461 | Expect(err).To(Equal(setErr)) 1462 | Expect(val).To(Equal([]redis.Library(nil))) 1463 | 1464 | base.ClearExpect() 1465 | expected() 1466 | val, err = actual().Result() 1467 | Expect(err).To(HaveOccurred()) 1468 | Expect(val).To(Equal([]redis.Library(nil))) 1469 | 1470 | libs := []redis.Library{ 1471 | { 1472 | Name: "lib1", 1473 | Engine: "LUA", 1474 | Functions: []redis.Function{ 1475 | { 1476 | Name: "lib1func1", 1477 | Description: "lib1 func1 desc", 1478 | Flags: []string{"no-writes", "allow-stale"}, 1479 | }, 1480 | }, 1481 | Code: "test code 1", 1482 | }, 1483 | { 1484 | Name: "lib2", 1485 | Engine: "LUA", 1486 | Functions: []redis.Function{ 1487 | { 1488 | Name: "lib2func1", 1489 | Description: "lib1 func1 desc", 1490 | Flags: []string{"no-writes", "allow-stale"}, 1491 | }, 1492 | { 1493 | Name: "lib2func2", 1494 | Description: "lib2 func2 desc", 1495 | Flags: []string{"no-writes"}, 1496 | }, 1497 | }, 1498 | Code: "test code 2", 1499 | }, 1500 | } 1501 | 1502 | base.ClearExpect() 1503 | expected().SetVal(libs) 1504 | val, err = actual().Result() 1505 | Expect(err).NotTo(HaveOccurred()) 1506 | Expect(val).To(Equal(libs)) 1507 | } 1508 | 1509 | func operationLCSCmd(base baseMock, expected func() *ExpectedLCS, actual func() *redis.LCSCmd) { 1510 | var ( 1511 | setErr = errors.New("lcs cmd error") 1512 | val *redis.LCSMatch 1513 | err error 1514 | ) 1515 | 1516 | base.ClearExpect() 1517 | expected().SetErr(setErr) 1518 | val, err = actual().Result() 1519 | Expect(err).To(Equal(setErr)) 1520 | Expect(val).To(BeNil()) 1521 | 1522 | base.ClearExpect() 1523 | expected() 1524 | val, err = actual().Result() 1525 | Expect(err).To(HaveOccurred()) 1526 | Expect(val).To(BeNil()) 1527 | 1528 | lcs := &redis.LCSMatch{ 1529 | MatchString: "match string", 1530 | } 1531 | 1532 | base.ClearExpect() 1533 | expected().SetVal(lcs) 1534 | val, err = actual().Result() 1535 | Expect(err).NotTo(HaveOccurred()) 1536 | Expect(val).To(Equal(lcs)) 1537 | 1538 | lcs = &redis.LCSMatch{ 1539 | MatchString: "", 1540 | Matches: []redis.LCSMatchedPosition{ 1541 | { 1542 | Key1: redis.LCSPosition{Start: 3, End: 5}, 1543 | Key2: redis.LCSPosition{Start: 1, End: 3}, 1544 | MatchLen: 2, 1545 | }, 1546 | { 1547 | Key1: redis.LCSPosition{Start: 5, End: 8}, 1548 | Key2: redis.LCSPosition{Start: 2, End: 5}, 1549 | MatchLen: 3, 1550 | }, 1551 | }, 1552 | Len: 3, 1553 | } 1554 | base.ClearExpect() 1555 | expected().SetVal(lcs) 1556 | val, err = actual().Result() 1557 | Expect(err).NotTo(HaveOccurred()) 1558 | Expect(val).To(Equal(lcs)) 1559 | } 1560 | 1561 | func operationKeyFlagsCmd(base baseMock, expected func() *ExpectedKeyFlags, actual func() *redis.KeyFlagsCmd) { 1562 | var ( 1563 | setErr = errors.New("key flags cmd error") 1564 | val []redis.KeyFlags 1565 | err error 1566 | ) 1567 | 1568 | base.ClearExpect() 1569 | expected().SetErr(setErr) 1570 | val, err = actual().Result() 1571 | Expect(err).To(Equal(setErr)) 1572 | Expect(val).To(Equal([]redis.KeyFlags(nil))) 1573 | 1574 | base.ClearExpect() 1575 | expected() 1576 | val, err = actual().Result() 1577 | Expect(err).To(HaveOccurred()) 1578 | Expect(val).To(Equal([]redis.KeyFlags(nil))) 1579 | 1580 | kfs := []redis.KeyFlags{ 1581 | { 1582 | Key: "test1", 1583 | Flags: []string{"flag1", "flag2"}, 1584 | }, 1585 | { 1586 | Key: "test2", 1587 | Flags: []string{"flag3", "flag4"}, 1588 | }, 1589 | } 1590 | 1591 | base.ClearExpect() 1592 | expected().SetVal(kfs) 1593 | val, err = actual().Result() 1594 | Expect(err).NotTo(HaveOccurred()) 1595 | Expect(val).To(Equal(kfs)) 1596 | } 1597 | 1598 | func operationClusterShardsCmd(base baseMock, expected func() *ExpectedClusterShards, actual func() *redis.ClusterShardsCmd) { 1599 | var ( 1600 | setErr = errors.New("cluster shareds cmd error") 1601 | val []redis.ClusterShard 1602 | err error 1603 | ) 1604 | 1605 | base.ClearExpect() 1606 | expected().SetErr(setErr) 1607 | val, err = actual().Result() 1608 | Expect(err).To(Equal(setErr)) 1609 | Expect(val).To(Equal([]redis.ClusterShard(nil))) 1610 | 1611 | base.ClearExpect() 1612 | expected() 1613 | val, err = actual().Result() 1614 | Expect(err).To(HaveOccurred()) 1615 | Expect(val).To(Equal([]redis.ClusterShard(nil))) 1616 | 1617 | cs := []redis.ClusterShard{ 1618 | { 1619 | Slots: []redis.SlotRange{ 1620 | {Start: 0, End: 1999}, 1621 | {Start: 4000, End: 5999}, 1622 | }, 1623 | Nodes: []redis.Node{ 1624 | { 1625 | ID: "e10b7051d6bf2d5febd39a2be297bbaea6084111", 1626 | Endpoint: "127.0.0.1", 1627 | IP: "127.0.0.1", 1628 | Hostname: "host", 1629 | Port: 30001, 1630 | TLSPort: 1999, 1631 | Role: "master", 1632 | ReplicationOffset: 72156, 1633 | Health: "online", 1634 | }, 1635 | { 1636 | ID: "fd20502fe1b32fc32c15b69b0a9537551f162f1f", 1637 | Endpoint: "127.0.0.1", 1638 | IP: "127.0.0.1", 1639 | Hostname: "host", 1640 | Port: 30002, 1641 | TLSPort: 1999, 1642 | Role: "replica", 1643 | ReplicationOffset: 72156, 1644 | Health: "online", 1645 | }, 1646 | }, 1647 | }, 1648 | } 1649 | 1650 | base.ClearExpect() 1651 | expected().SetVal(cs) 1652 | val, err = actual().Result() 1653 | Expect(err).NotTo(HaveOccurred()) 1654 | Expect(val).To(Equal(cs)) 1655 | } 1656 | 1657 | func operationTSTimestampValueCmd(base baseMock, expected func() *ExpectedTSTimestampValue, actual func() *redis.TSTimestampValueCmd) { 1658 | var ( 1659 | setErr = errors.New("ts timestamp value cmd error") 1660 | val redis.TSTimestampValue 1661 | err error 1662 | ) 1663 | 1664 | base.ClearExpect() 1665 | expected().SetErr(setErr) 1666 | val, err = actual().Result() 1667 | Expect(err).To(Equal(setErr)) 1668 | Expect(val).To(Equal(redis.TSTimestampValue{})) 1669 | 1670 | base.ClearExpect() 1671 | expected() 1672 | val, err = actual().Result() 1673 | Expect(err).To(HaveOccurred()) 1674 | Expect(val).To(Equal(redis.TSTimestampValue{})) 1675 | 1676 | tsv := redis.TSTimestampValue{ 1677 | Timestamp: 1000, 1678 | Value: 1, 1679 | } 1680 | 1681 | base.ClearExpect() 1682 | expected().SetVal(tsv) 1683 | val, err = actual().Result() 1684 | Expect(err).NotTo(HaveOccurred()) 1685 | Expect(val).To(Equal(tsv)) 1686 | } 1687 | 1688 | func operationMapStringInterfaceCmd(base baseMock, expected func() *ExpectedMapStringInterface, actual func() *redis.MapStringInterfaceCmd) { 1689 | var ( 1690 | setErr = errors.New("map string interface cmd error") 1691 | val map[string]interface{} 1692 | err error 1693 | ) 1694 | 1695 | base.ClearExpect() 1696 | expected().SetErr(setErr) 1697 | val, err = actual().Result() 1698 | Expect(err).To(Equal(setErr)) 1699 | Expect(val).To(Equal(map[string]interface{}(nil))) 1700 | 1701 | base.ClearExpect() 1702 | expected() 1703 | val, err = actual().Result() 1704 | Expect(err).To(HaveOccurred()) 1705 | Expect(val).To(Equal(map[string]interface{}(nil))) 1706 | 1707 | base.ClearExpect() 1708 | expected().SetVal(map[string]interface{}{ 1709 | "key1": "val1", 1710 | "key2": 2, 1711 | }) 1712 | val, err = actual().Result() 1713 | Expect(err).NotTo(HaveOccurred()) 1714 | Expect(val).To(Equal(map[string]interface{}{ 1715 | "key1": "val1", 1716 | "key2": 2, 1717 | })) 1718 | } 1719 | 1720 | func operationTSTimestampValueSliceCmd(base baseMock, expected func() *ExpectedTSTimestampValueSlice, actual func() *redis.TSTimestampValueSliceCmd) { 1721 | var ( 1722 | setErr = errors.New("ts timestamp value slice cmd error") 1723 | val []redis.TSTimestampValue 1724 | err error 1725 | ) 1726 | 1727 | base.ClearExpect() 1728 | expected().SetErr(setErr) 1729 | val, err = actual().Result() 1730 | Expect(err).To(Equal(setErr)) 1731 | Expect(val).To(Equal([]redis.TSTimestampValue(nil))) 1732 | 1733 | base.ClearExpect() 1734 | expected() 1735 | val, err = actual().Result() 1736 | Expect(err).To(HaveOccurred()) 1737 | Expect(val).To(Equal([]redis.TSTimestampValue(nil))) 1738 | 1739 | tsv := []redis.TSTimestampValue{ 1740 | { 1741 | Timestamp: 1000, 1742 | Value: 1, 1743 | }, 1744 | { 1745 | Timestamp: 2000, 1746 | Value: 2, 1747 | }, 1748 | } 1749 | 1750 | base.ClearExpect() 1751 | expected().SetVal(tsv) 1752 | val, err = actual().Result() 1753 | Expect(err).NotTo(HaveOccurred()) 1754 | Expect(val).To(Equal(tsv)) 1755 | } 1756 | 1757 | func operationMapStringSliceInterfaceCmd(base baseMock, expected func() *ExpectedMapStringSliceInterface, actual func() *redis.MapStringSliceInterfaceCmd) { 1758 | var ( 1759 | setErr = errors.New("map string slice interface cmd error") 1760 | val map[string][]interface{} 1761 | err error 1762 | ) 1763 | 1764 | base.ClearExpect() 1765 | expected().SetErr(setErr) 1766 | val, err = actual().Result() 1767 | Expect(err).To(Equal(setErr)) 1768 | Expect(val).To(Equal(map[string][]interface{}(nil))) 1769 | 1770 | base.ClearExpect() 1771 | expected() 1772 | val, err = actual().Result() 1773 | Expect(err).To(HaveOccurred()) 1774 | Expect(val).To(Equal(map[string][]interface{}(nil))) 1775 | 1776 | base.ClearExpect() 1777 | expected().SetVal(map[string][]interface{}{ 1778 | "key1": {"val1", 1}, 1779 | "key2": {"val2", 2}, 1780 | }) 1781 | val, err = actual().Result() 1782 | Expect(err).NotTo(HaveOccurred()) 1783 | Expect(val).To(Equal(map[string][]interface{}{ 1784 | "key1": {"val1", 1}, 1785 | "key2": {"val2", 2}, 1786 | })) 1787 | } 1788 | --------------------------------------------------------------------------------