2015-01-15 18:51:22 +03:00
|
|
|
package redis_test
|
|
|
|
|
|
|
|
import (
|
2015-05-28 15:51:19 +03:00
|
|
|
"encoding/json"
|
2015-01-15 18:51:22 +03:00
|
|
|
"fmt"
|
2015-05-28 15:51:19 +03:00
|
|
|
"reflect"
|
2015-01-15 18:51:22 +03:00
|
|
|
"time"
|
|
|
|
|
|
|
|
. "github.com/onsi/ginkgo"
|
|
|
|
. "github.com/onsi/gomega"
|
2015-05-14 15:19:29 +03:00
|
|
|
|
2017-02-18 17:42:34 +03:00
|
|
|
"github.com/go-redis/redis"
|
2018-02-22 15:14:30 +03:00
|
|
|
"github.com/go-redis/redis/internal/proto"
|
2015-01-15 18:51:22 +03:00
|
|
|
)
|
|
|
|
|
|
|
|
var _ = Describe("Commands", func() {
|
|
|
|
var client *redis.Client
|
|
|
|
|
|
|
|
BeforeEach(func() {
|
2016-03-16 17:57:24 +03:00
|
|
|
client = redis.NewClient(redisOptions())
|
2017-06-17 12:53:16 +03:00
|
|
|
Expect(client.FlushDB().Err()).NotTo(HaveOccurred())
|
2015-01-15 18:51:22 +03:00
|
|
|
})
|
|
|
|
|
|
|
|
AfterEach(func() {
|
|
|
|
Expect(client.Close()).NotTo(HaveOccurred())
|
|
|
|
})
|
|
|
|
|
|
|
|
Describe("server", func() {
|
|
|
|
|
2016-11-30 13:39:14 +03:00
|
|
|
It("should Auth", func() {
|
2017-08-31 15:22:47 +03:00
|
|
|
cmds, err := client.Pipelined(func(pipe redis.Pipeliner) error {
|
2016-11-30 13:39:14 +03:00
|
|
|
pipe.Auth("password")
|
2017-08-31 15:22:47 +03:00
|
|
|
pipe.Auth("")
|
2016-11-30 13:39:14 +03:00
|
|
|
return nil
|
|
|
|
})
|
|
|
|
Expect(err).To(MatchError("ERR Client sent AUTH, but no password is set"))
|
2017-08-31 15:22:47 +03:00
|
|
|
Expect(cmds[0].Err()).To(MatchError("ERR Client sent AUTH, but no password is set"))
|
|
|
|
Expect(cmds[1].Err()).To(MatchError("ERR Client sent AUTH, but no password is set"))
|
|
|
|
|
2017-09-22 12:23:46 +03:00
|
|
|
stats := client.PoolStats()
|
2017-08-31 15:22:47 +03:00
|
|
|
Expect(stats.Hits).To(Equal(uint32(1)))
|
2017-09-22 12:23:46 +03:00
|
|
|
Expect(stats.Misses).To(Equal(uint32(1)))
|
2017-08-31 15:22:47 +03:00
|
|
|
Expect(stats.Timeouts).To(Equal(uint32(0)))
|
|
|
|
Expect(stats.TotalConns).To(Equal(uint32(1)))
|
2018-08-12 10:08:21 +03:00
|
|
|
Expect(stats.IdleConns).To(Equal(uint32(1)))
|
2016-11-30 13:39:14 +03:00
|
|
|
})
|
2015-01-15 18:51:22 +03:00
|
|
|
|
|
|
|
It("should Echo", func() {
|
2016-11-30 13:39:14 +03:00
|
|
|
pipe := client.Pipeline()
|
|
|
|
echo := pipe.Echo("hello")
|
|
|
|
_, err := pipe.Exec()
|
|
|
|
Expect(err).NotTo(HaveOccurred())
|
|
|
|
|
2015-01-15 18:51:22 +03:00
|
|
|
Expect(echo.Err()).NotTo(HaveOccurred())
|
|
|
|
Expect(echo.Val()).To(Equal("hello"))
|
|
|
|
})
|
|
|
|
|
|
|
|
It("should Ping", func() {
|
|
|
|
ping := client.Ping()
|
|
|
|
Expect(ping.Err()).NotTo(HaveOccurred())
|
|
|
|
Expect(ping.Val()).To(Equal("PONG"))
|
|
|
|
})
|
|
|
|
|
2017-02-16 19:15:34 +03:00
|
|
|
It("should Wait", func() {
|
2018-02-22 16:01:48 +03:00
|
|
|
const wait = 3 * time.Second
|
|
|
|
|
2017-02-16 19:15:34 +03:00
|
|
|
// assume testing on single redis instance
|
2017-02-24 12:03:21 +03:00
|
|
|
start := time.Now()
|
2018-02-22 16:01:48 +03:00
|
|
|
val, err := client.Wait(1, wait).Result()
|
|
|
|
Expect(err).NotTo(HaveOccurred())
|
|
|
|
Expect(val).To(Equal(int64(0)))
|
2018-11-21 12:09:21 +03:00
|
|
|
Expect(time.Now()).To(BeTemporally("~", start.Add(wait), 3*time.Second))
|
2017-02-16 19:15:34 +03:00
|
|
|
})
|
|
|
|
|
2016-11-30 13:39:14 +03:00
|
|
|
It("should Select", func() {
|
|
|
|
pipe := client.Pipeline()
|
|
|
|
sel := pipe.Select(1)
|
|
|
|
_, err := pipe.Exec()
|
|
|
|
Expect(err).NotTo(HaveOccurred())
|
|
|
|
|
|
|
|
Expect(sel.Err()).NotTo(HaveOccurred())
|
|
|
|
Expect(sel.Val()).To(Equal("OK"))
|
|
|
|
})
|
2015-01-15 18:51:22 +03:00
|
|
|
|
2018-02-14 07:42:19 +03:00
|
|
|
It("should SwapDB", func() {
|
|
|
|
pipe := client.Pipeline()
|
|
|
|
sel := pipe.SwapDB(1, 2)
|
|
|
|
_, err := pipe.Exec()
|
|
|
|
Expect(err).NotTo(HaveOccurred())
|
|
|
|
|
|
|
|
Expect(sel.Err()).NotTo(HaveOccurred())
|
|
|
|
Expect(sel.Val()).To(Equal("OK"))
|
|
|
|
})
|
|
|
|
|
2015-01-15 18:51:22 +03:00
|
|
|
It("should BgRewriteAOF", func() {
|
2016-03-14 17:51:46 +03:00
|
|
|
Skip("flaky test")
|
|
|
|
|
|
|
|
val, err := client.BgRewriteAOF().Result()
|
|
|
|
Expect(err).NotTo(HaveOccurred())
|
|
|
|
Expect(val).To(ContainSubstring("Background append only file rewriting"))
|
2015-01-15 18:51:22 +03:00
|
|
|
})
|
|
|
|
|
|
|
|
It("should BgSave", func() {
|
2016-03-14 17:51:46 +03:00
|
|
|
Skip("flaky test")
|
|
|
|
|
2015-01-15 18:51:22 +03:00
|
|
|
// workaround for "ERR Can't BGSAVE while AOF log rewriting is in progress"
|
|
|
|
Eventually(func() string {
|
|
|
|
return client.BgSave().Val()
|
2016-03-14 17:51:46 +03:00
|
|
|
}, "30s").Should(Equal("Background saving started"))
|
2015-01-15 18:51:22 +03:00
|
|
|
})
|
|
|
|
|
|
|
|
It("should ClientKill", func() {
|
|
|
|
r := client.ClientKill("1.1.1.1:1111")
|
|
|
|
Expect(r.Err()).To(MatchError("ERR No such client"))
|
|
|
|
Expect(r.Val()).To(Equal(""))
|
|
|
|
})
|
|
|
|
|
2018-07-23 14:12:20 +03:00
|
|
|
It("should ClientKillByFilter", func() {
|
|
|
|
r := client.ClientKillByFilter("TYPE", "test")
|
|
|
|
Expect(r.Err()).To(MatchError("ERR Unknown client type 'test'"))
|
|
|
|
Expect(r.Val()).To(Equal(int64(0)))
|
|
|
|
})
|
|
|
|
|
2018-12-11 14:17:41 +03:00
|
|
|
It("should ClientID", func() {
|
|
|
|
err := client.ClientID().Err()
|
2018-12-11 13:43:54 +03:00
|
|
|
Expect(err).NotTo(HaveOccurred())
|
2018-12-11 14:17:41 +03:00
|
|
|
Expect(client.ClientID().Val()).To(BeNumerically(">=", 0))
|
2018-12-11 13:43:54 +03:00
|
|
|
})
|
|
|
|
|
2018-12-11 23:26:48 +03:00
|
|
|
It("should ClientUnblock", func() {
|
|
|
|
id := client.ClientID().Val()
|
2018-12-14 17:46:15 +03:00
|
|
|
r, err := client.ClientUnblock(id).Result()
|
|
|
|
Expect(err).NotTo(HaveOccurred())
|
|
|
|
Expect(r).To(Equal(int64(0)))
|
|
|
|
})
|
|
|
|
|
|
|
|
It("should ClientUnblockWithError", func() {
|
|
|
|
id := client.ClientID().Val()
|
|
|
|
r, err := client.ClientUnblockWithError(id).Result()
|
2018-12-11 23:26:48 +03:00
|
|
|
Expect(err).NotTo(HaveOccurred())
|
|
|
|
Expect(r).To(Equal(int64(0)))
|
|
|
|
})
|
|
|
|
|
2015-05-15 15:11:22 +03:00
|
|
|
It("should ClientPause", func() {
|
|
|
|
err := client.ClientPause(time.Second).Err()
|
|
|
|
Expect(err).NotTo(HaveOccurred())
|
|
|
|
|
2015-11-22 15:44:38 +03:00
|
|
|
start := time.Now()
|
|
|
|
err = client.Ping().Err()
|
|
|
|
Expect(err).NotTo(HaveOccurred())
|
|
|
|
Expect(time.Now()).To(BeTemporally("~", start.Add(time.Second), 800*time.Millisecond))
|
2015-05-15 15:11:22 +03:00
|
|
|
})
|
|
|
|
|
2015-10-22 14:15:47 +03:00
|
|
|
It("should ClientSetName and ClientGetName", func() {
|
2016-11-30 13:39:14 +03:00
|
|
|
pipe := client.Pipeline()
|
|
|
|
set := pipe.ClientSetName("theclientname")
|
|
|
|
get := pipe.ClientGetName()
|
|
|
|
_, err := pipe.Exec()
|
2015-10-20 22:21:58 +03:00
|
|
|
Expect(err).NotTo(HaveOccurred())
|
|
|
|
|
2016-11-30 13:39:14 +03:00
|
|
|
Expect(set.Err()).NotTo(HaveOccurred())
|
|
|
|
Expect(set.Val()).To(BeTrue())
|
|
|
|
|
|
|
|
Expect(get.Err()).NotTo(HaveOccurred())
|
|
|
|
Expect(get.Val()).To(Equal("theclientname"))
|
2015-10-20 22:21:58 +03:00
|
|
|
})
|
|
|
|
|
2015-01-15 18:51:22 +03:00
|
|
|
It("should ConfigGet", func() {
|
2017-05-24 15:53:41 +03:00
|
|
|
val, err := client.ConfigGet("*").Result()
|
|
|
|
Expect(err).NotTo(HaveOccurred())
|
|
|
|
Expect(val).NotTo(BeEmpty())
|
2015-01-15 18:51:22 +03:00
|
|
|
})
|
|
|
|
|
|
|
|
It("should ConfigResetStat", func() {
|
|
|
|
r := client.ConfigResetStat()
|
|
|
|
Expect(r.Err()).NotTo(HaveOccurred())
|
|
|
|
Expect(r.Val()).To(Equal("OK"))
|
|
|
|
})
|
|
|
|
|
|
|
|
It("should ConfigSet", func() {
|
|
|
|
configGet := client.ConfigGet("maxmemory")
|
|
|
|
Expect(configGet.Err()).NotTo(HaveOccurred())
|
|
|
|
Expect(configGet.Val()).To(HaveLen(2))
|
|
|
|
Expect(configGet.Val()[0]).To(Equal("maxmemory"))
|
|
|
|
|
|
|
|
configSet := client.ConfigSet("maxmemory", configGet.Val()[1].(string))
|
|
|
|
Expect(configSet.Err()).NotTo(HaveOccurred())
|
|
|
|
Expect(configSet.Val()).To(Equal("OK"))
|
|
|
|
})
|
|
|
|
|
2018-03-01 11:37:51 +03:00
|
|
|
It("should ConfigRewrite", func() {
|
|
|
|
configRewrite := client.ConfigRewrite()
|
|
|
|
Expect(configRewrite.Err()).NotTo(HaveOccurred())
|
|
|
|
Expect(configRewrite.Val()).To(Equal("OK"))
|
|
|
|
})
|
|
|
|
|
2017-08-15 10:34:05 +03:00
|
|
|
It("should DBSize", func() {
|
|
|
|
size, err := client.DBSize().Result()
|
|
|
|
Expect(err).NotTo(HaveOccurred())
|
|
|
|
Expect(size).To(Equal(int64(0)))
|
2015-01-15 18:51:22 +03:00
|
|
|
})
|
|
|
|
|
|
|
|
It("should Info", func() {
|
|
|
|
info := client.Info()
|
|
|
|
Expect(info.Err()).NotTo(HaveOccurred())
|
|
|
|
Expect(info.Val()).NotTo(Equal(""))
|
|
|
|
})
|
|
|
|
|
2016-01-08 16:03:34 +03:00
|
|
|
It("should Info cpu", func() {
|
|
|
|
info := client.Info("cpu")
|
|
|
|
Expect(info.Err()).NotTo(HaveOccurred())
|
|
|
|
Expect(info.Val()).NotTo(Equal(""))
|
|
|
|
Expect(info.Val()).To(ContainSubstring(`used_cpu_sys`))
|
|
|
|
})
|
|
|
|
|
2015-01-15 18:51:22 +03:00
|
|
|
It("should LastSave", func() {
|
|
|
|
lastSave := client.LastSave()
|
|
|
|
Expect(lastSave.Err()).NotTo(HaveOccurred())
|
|
|
|
Expect(lastSave.Val()).NotTo(Equal(0))
|
|
|
|
})
|
|
|
|
|
|
|
|
It("should Save", func() {
|
|
|
|
// workaround for "ERR Background save already in progress"
|
|
|
|
Eventually(func() string {
|
|
|
|
return client.Save().Val()
|
2015-01-24 15:12:48 +03:00
|
|
|
}, "10s").Should(Equal("OK"))
|
2015-01-15 18:51:22 +03:00
|
|
|
})
|
|
|
|
|
|
|
|
It("should SlaveOf", func() {
|
|
|
|
slaveOf := client.SlaveOf("localhost", "8888")
|
|
|
|
Expect(slaveOf.Err()).NotTo(HaveOccurred())
|
|
|
|
Expect(slaveOf.Val()).To(Equal("OK"))
|
|
|
|
|
|
|
|
slaveOf = client.SlaveOf("NO", "ONE")
|
|
|
|
Expect(slaveOf.Err()).NotTo(HaveOccurred())
|
|
|
|
Expect(slaveOf.Val()).To(Equal("OK"))
|
|
|
|
})
|
|
|
|
|
|
|
|
It("should Time", func() {
|
2016-10-14 14:39:02 +03:00
|
|
|
tm, err := client.Time().Result()
|
|
|
|
Expect(err).NotTo(HaveOccurred())
|
|
|
|
Expect(tm).To(BeTemporally("~", time.Now(), 3*time.Second))
|
2015-01-15 18:51:22 +03:00
|
|
|
})
|
|
|
|
|
2018-12-11 13:43:54 +03:00
|
|
|
It("should Command", func() {
|
2017-08-31 15:22:47 +03:00
|
|
|
cmds, err := client.Command().Result()
|
|
|
|
Expect(err).NotTo(HaveOccurred())
|
2018-05-17 14:36:51 +03:00
|
|
|
Expect(len(cmds)).To(BeNumerically("~", 200, 20))
|
2017-08-31 15:22:47 +03:00
|
|
|
|
|
|
|
cmd := cmds["mget"]
|
|
|
|
Expect(cmd.Name).To(Equal("mget"))
|
|
|
|
Expect(cmd.Arity).To(Equal(int8(-2)))
|
|
|
|
Expect(cmd.Flags).To(ContainElement("readonly"))
|
|
|
|
Expect(cmd.FirstKeyPos).To(Equal(int8(1)))
|
|
|
|
Expect(cmd.LastKeyPos).To(Equal(int8(-1)))
|
|
|
|
Expect(cmd.StepCount).To(Equal(int8(1)))
|
|
|
|
|
|
|
|
cmd = cmds["ping"]
|
|
|
|
Expect(cmd.Name).To(Equal("ping"))
|
|
|
|
Expect(cmd.Arity).To(Equal(int8(-1)))
|
|
|
|
Expect(cmd.Flags).To(ContainElement("stale"))
|
|
|
|
Expect(cmd.Flags).To(ContainElement("fast"))
|
|
|
|
Expect(cmd.FirstKeyPos).To(Equal(int8(0)))
|
|
|
|
Expect(cmd.LastKeyPos).To(Equal(int8(0)))
|
|
|
|
Expect(cmd.StepCount).To(Equal(int8(0)))
|
|
|
|
})
|
|
|
|
|
2015-01-15 18:51:22 +03:00
|
|
|
})
|
|
|
|
|
|
|
|
Describe("debugging", func() {
|
|
|
|
|
|
|
|
It("should DebugObject", func() {
|
2018-07-22 09:46:29 +03:00
|
|
|
err := client.DebugObject("foo").Err()
|
|
|
|
Expect(err).To(MatchError("ERR no such key"))
|
|
|
|
|
|
|
|
err = client.Set("foo", "bar", 0).Err()
|
|
|
|
Expect(err).NotTo(HaveOccurred())
|
|
|
|
|
|
|
|
s, err := client.DebugObject("foo").Result()
|
|
|
|
Expect(err).NotTo(HaveOccurred())
|
|
|
|
Expect(s).To(ContainSubstring("serializedlength:4"))
|
|
|
|
})
|
|
|
|
|
|
|
|
It("should MemoryUsage", func() {
|
|
|
|
err := client.MemoryUsage("foo").Err()
|
|
|
|
Expect(err).To(Equal(redis.Nil))
|
|
|
|
|
|
|
|
err = client.Set("foo", "bar", 0).Err()
|
|
|
|
Expect(err).NotTo(HaveOccurred())
|
|
|
|
|
|
|
|
n, err := client.MemoryUsage("foo").Result()
|
|
|
|
Expect(err).NotTo(HaveOccurred())
|
2018-11-29 12:09:11 +03:00
|
|
|
Expect(n).To(Equal(int64(50)))
|
2018-07-22 09:46:29 +03:00
|
|
|
|
|
|
|
n, err = client.MemoryUsage("foo", 0).Result()
|
|
|
|
Expect(err).NotTo(HaveOccurred())
|
2018-11-29 12:09:11 +03:00
|
|
|
Expect(n).To(Equal(int64(50)))
|
2015-01-15 18:51:22 +03:00
|
|
|
})
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
Describe("keys", func() {
|
|
|
|
|
|
|
|
It("should Del", func() {
|
2016-12-22 14:42:05 +03:00
|
|
|
err := client.Set("key1", "Hello", 0).Err()
|
|
|
|
Expect(err).NotTo(HaveOccurred())
|
|
|
|
err = client.Set("key2", "World", 0).Err()
|
|
|
|
Expect(err).NotTo(HaveOccurred())
|
2015-01-15 18:51:22 +03:00
|
|
|
|
2016-12-22 14:42:05 +03:00
|
|
|
n, err := client.Del("key1", "key2", "key3").Result()
|
|
|
|
Expect(err).NotTo(HaveOccurred())
|
|
|
|
Expect(n).To(Equal(int64(2)))
|
|
|
|
})
|
|
|
|
|
|
|
|
It("should Unlink", func() {
|
|
|
|
err := client.Set("key1", "Hello", 0).Err()
|
|
|
|
Expect(err).NotTo(HaveOccurred())
|
|
|
|
err = client.Set("key2", "World", 0).Err()
|
|
|
|
Expect(err).NotTo(HaveOccurred())
|
|
|
|
|
|
|
|
n, err := client.Unlink("key1", "key2", "key3").Result()
|
|
|
|
Expect(err).NotTo(HaveOccurred())
|
|
|
|
Expect(n).To(Equal(int64(2)))
|
2015-01-15 18:51:22 +03:00
|
|
|
})
|
|
|
|
|
|
|
|
It("should Dump", func() {
|
2015-01-31 12:08:56 +03:00
|
|
|
set := client.Set("key", "hello", 0)
|
2015-01-15 18:51:22 +03:00
|
|
|
Expect(set.Err()).NotTo(HaveOccurred())
|
|
|
|
Expect(set.Val()).To(Equal("OK"))
|
|
|
|
|
|
|
|
dump := client.Dump("key")
|
|
|
|
Expect(dump.Err()).NotTo(HaveOccurred())
|
2015-09-28 11:13:32 +03:00
|
|
|
Expect(dump.Val()).NotTo(BeEmpty())
|
2015-01-15 18:51:22 +03:00
|
|
|
})
|
|
|
|
|
|
|
|
It("should Exists", func() {
|
2015-01-31 12:08:56 +03:00
|
|
|
set := client.Set("key1", "Hello", 0)
|
2015-01-15 18:51:22 +03:00
|
|
|
Expect(set.Err()).NotTo(HaveOccurred())
|
|
|
|
Expect(set.Val()).To(Equal("OK"))
|
|
|
|
|
2017-02-18 17:32:39 +03:00
|
|
|
n, err := client.Exists("key1").Result()
|
|
|
|
Expect(err).NotTo(HaveOccurred())
|
|
|
|
Expect(n).To(Equal(int64(1)))
|
2015-01-15 18:51:22 +03:00
|
|
|
|
2017-02-18 17:32:39 +03:00
|
|
|
n, err = client.Exists("key2").Result()
|
|
|
|
Expect(err).NotTo(HaveOccurred())
|
|
|
|
Expect(n).To(Equal(int64(0)))
|
2017-02-10 13:15:25 +03:00
|
|
|
|
2017-02-18 17:32:39 +03:00
|
|
|
n, err = client.Exists("key1", "key2").Result()
|
|
|
|
Expect(err).NotTo(HaveOccurred())
|
|
|
|
Expect(n).To(Equal(int64(1)))
|
2017-02-10 13:15:25 +03:00
|
|
|
|
2017-02-18 17:32:39 +03:00
|
|
|
n, err = client.Exists("key1", "key1").Result()
|
|
|
|
Expect(err).NotTo(HaveOccurred())
|
|
|
|
Expect(n).To(Equal(int64(2)))
|
2015-01-15 18:51:22 +03:00
|
|
|
})
|
|
|
|
|
|
|
|
It("should Expire", func() {
|
2015-01-31 12:08:56 +03:00
|
|
|
set := client.Set("key", "Hello", 0)
|
2015-01-15 18:51:22 +03:00
|
|
|
Expect(set.Err()).NotTo(HaveOccurred())
|
|
|
|
Expect(set.Val()).To(Equal("OK"))
|
|
|
|
|
|
|
|
expire := client.Expire("key", 10*time.Second)
|
|
|
|
Expect(expire.Err()).NotTo(HaveOccurred())
|
|
|
|
Expect(expire.Val()).To(Equal(true))
|
|
|
|
|
|
|
|
ttl := client.TTL("key")
|
|
|
|
Expect(ttl.Err()).NotTo(HaveOccurred())
|
|
|
|
Expect(ttl.Val()).To(Equal(10 * time.Second))
|
|
|
|
|
2015-01-31 12:08:56 +03:00
|
|
|
set = client.Set("key", "Hello World", 0)
|
2015-01-15 18:51:22 +03:00
|
|
|
Expect(set.Err()).NotTo(HaveOccurred())
|
|
|
|
Expect(set.Val()).To(Equal("OK"))
|
|
|
|
|
|
|
|
ttl = client.TTL("key")
|
|
|
|
Expect(ttl.Err()).NotTo(HaveOccurred())
|
|
|
|
Expect(ttl.Val() < 0).To(Equal(true))
|
|
|
|
})
|
|
|
|
|
|
|
|
It("should ExpireAt", func() {
|
2015-01-31 12:08:56 +03:00
|
|
|
set := client.Set("key", "Hello", 0)
|
2015-01-15 18:51:22 +03:00
|
|
|
Expect(set.Err()).NotTo(HaveOccurred())
|
|
|
|
Expect(set.Val()).To(Equal("OK"))
|
|
|
|
|
2017-02-18 17:32:39 +03:00
|
|
|
n, err := client.Exists("key").Result()
|
|
|
|
Expect(err).NotTo(HaveOccurred())
|
|
|
|
Expect(n).To(Equal(int64(1)))
|
2015-01-15 18:51:22 +03:00
|
|
|
|
|
|
|
expireAt := client.ExpireAt("key", time.Now().Add(-time.Hour))
|
|
|
|
Expect(expireAt.Err()).NotTo(HaveOccurred())
|
|
|
|
Expect(expireAt.Val()).To(Equal(true))
|
|
|
|
|
2017-02-18 17:32:39 +03:00
|
|
|
n, err = client.Exists("key").Result()
|
|
|
|
Expect(err).NotTo(HaveOccurred())
|
|
|
|
Expect(n).To(Equal(int64(0)))
|
2015-01-15 18:51:22 +03:00
|
|
|
})
|
|
|
|
|
|
|
|
It("should Keys", func() {
|
|
|
|
mset := client.MSet("one", "1", "two", "2", "three", "3", "four", "4")
|
|
|
|
Expect(mset.Err()).NotTo(HaveOccurred())
|
|
|
|
Expect(mset.Val()).To(Equal("OK"))
|
|
|
|
|
|
|
|
keys := client.Keys("*o*")
|
|
|
|
Expect(keys.Err()).NotTo(HaveOccurred())
|
2015-02-09 11:14:41 +03:00
|
|
|
Expect(keys.Val()).To(ConsistOf([]string{"four", "one", "two"}))
|
2015-01-15 18:51:22 +03:00
|
|
|
|
|
|
|
keys = client.Keys("t??")
|
|
|
|
Expect(keys.Err()).NotTo(HaveOccurred())
|
|
|
|
Expect(keys.Val()).To(Equal([]string{"two"}))
|
|
|
|
|
|
|
|
keys = client.Keys("*")
|
|
|
|
Expect(keys.Err()).NotTo(HaveOccurred())
|
2015-02-09 11:14:41 +03:00
|
|
|
Expect(keys.Val()).To(ConsistOf([]string{"four", "one", "three", "two"}))
|
2015-01-15 18:51:22 +03:00
|
|
|
})
|
|
|
|
|
|
|
|
It("should Migrate", func() {
|
2015-05-18 14:43:08 +03:00
|
|
|
migrate := client.Migrate("localhost", redisSecondaryPort, "key", 0, 0)
|
2015-01-15 18:51:22 +03:00
|
|
|
Expect(migrate.Err()).NotTo(HaveOccurred())
|
|
|
|
Expect(migrate.Val()).To(Equal("NOKEY"))
|
|
|
|
|
2015-01-31 12:08:56 +03:00
|
|
|
set := client.Set("key", "hello", 0)
|
2015-01-15 18:51:22 +03:00
|
|
|
Expect(set.Err()).NotTo(HaveOccurred())
|
|
|
|
Expect(set.Val()).To(Equal("OK"))
|
|
|
|
|
2015-05-18 14:43:08 +03:00
|
|
|
migrate = client.Migrate("localhost", redisSecondaryPort, "key", 0, 0)
|
2015-01-15 18:51:22 +03:00
|
|
|
Expect(migrate.Err()).To(MatchError("IOERR error or timeout writing to target instance"))
|
|
|
|
Expect(migrate.Val()).To(Equal(""))
|
|
|
|
})
|
|
|
|
|
|
|
|
It("should Move", func() {
|
2016-03-16 17:57:24 +03:00
|
|
|
move := client.Move("key", 2)
|
2015-01-15 18:51:22 +03:00
|
|
|
Expect(move.Err()).NotTo(HaveOccurred())
|
|
|
|
Expect(move.Val()).To(Equal(false))
|
|
|
|
|
2015-01-31 12:08:56 +03:00
|
|
|
set := client.Set("key", "hello", 0)
|
2015-01-15 18:51:22 +03:00
|
|
|
Expect(set.Err()).NotTo(HaveOccurred())
|
|
|
|
Expect(set.Val()).To(Equal("OK"))
|
|
|
|
|
2016-03-16 17:57:24 +03:00
|
|
|
move = client.Move("key", 2)
|
2015-01-15 18:51:22 +03:00
|
|
|
Expect(move.Err()).NotTo(HaveOccurred())
|
|
|
|
Expect(move.Val()).To(Equal(true))
|
|
|
|
|
|
|
|
get := client.Get("key")
|
|
|
|
Expect(get.Err()).To(Equal(redis.Nil))
|
|
|
|
Expect(get.Val()).To(Equal(""))
|
|
|
|
|
2016-06-05 12:45:39 +03:00
|
|
|
pipe := client.Pipeline()
|
|
|
|
pipe.Select(2)
|
|
|
|
get = pipe.Get("key")
|
2017-06-17 12:53:16 +03:00
|
|
|
pipe.FlushDB()
|
2015-01-15 18:51:22 +03:00
|
|
|
|
2016-06-05 12:45:39 +03:00
|
|
|
_, err := pipe.Exec()
|
|
|
|
Expect(err).NotTo(HaveOccurred())
|
2015-01-15 18:51:22 +03:00
|
|
|
Expect(get.Val()).To(Equal("hello"))
|
|
|
|
})
|
|
|
|
|
|
|
|
It("should Object", func() {
|
2015-01-31 12:08:56 +03:00
|
|
|
set := client.Set("key", "hello", 0)
|
2015-01-15 18:51:22 +03:00
|
|
|
Expect(set.Err()).NotTo(HaveOccurred())
|
|
|
|
Expect(set.Val()).To(Equal("OK"))
|
|
|
|
|
|
|
|
refCount := client.ObjectRefCount("key")
|
|
|
|
Expect(refCount.Err()).NotTo(HaveOccurred())
|
|
|
|
Expect(refCount.Val()).To(Equal(int64(1)))
|
|
|
|
|
2015-05-14 16:13:45 +03:00
|
|
|
err := client.ObjectEncoding("key").Err()
|
|
|
|
Expect(err).NotTo(HaveOccurred())
|
2015-01-15 18:51:22 +03:00
|
|
|
|
|
|
|
idleTime := client.ObjectIdleTime("key")
|
|
|
|
Expect(idleTime.Err()).NotTo(HaveOccurred())
|
|
|
|
Expect(idleTime.Val()).To(Equal(time.Duration(0)))
|
|
|
|
})
|
|
|
|
|
|
|
|
It("should Persist", func() {
|
2015-01-31 12:08:56 +03:00
|
|
|
set := client.Set("key", "Hello", 0)
|
2015-01-15 18:51:22 +03:00
|
|
|
Expect(set.Err()).NotTo(HaveOccurred())
|
|
|
|
Expect(set.Val()).To(Equal("OK"))
|
|
|
|
|
|
|
|
expire := client.Expire("key", 10*time.Second)
|
|
|
|
Expect(expire.Err()).NotTo(HaveOccurred())
|
|
|
|
Expect(expire.Val()).To(Equal(true))
|
|
|
|
|
|
|
|
ttl := client.TTL("key")
|
|
|
|
Expect(ttl.Err()).NotTo(HaveOccurred())
|
|
|
|
Expect(ttl.Val()).To(Equal(10 * time.Second))
|
|
|
|
|
|
|
|
persist := client.Persist("key")
|
|
|
|
Expect(persist.Err()).NotTo(HaveOccurred())
|
|
|
|
Expect(persist.Val()).To(Equal(true))
|
|
|
|
|
|
|
|
ttl = client.TTL("key")
|
|
|
|
Expect(ttl.Err()).NotTo(HaveOccurred())
|
|
|
|
Expect(ttl.Val() < 0).To(Equal(true))
|
|
|
|
})
|
|
|
|
|
|
|
|
It("should PExpire", func() {
|
2015-01-31 12:08:56 +03:00
|
|
|
set := client.Set("key", "Hello", 0)
|
2015-01-15 18:51:22 +03:00
|
|
|
Expect(set.Err()).NotTo(HaveOccurred())
|
|
|
|
Expect(set.Val()).To(Equal("OK"))
|
|
|
|
|
|
|
|
expiration := 900 * time.Millisecond
|
|
|
|
pexpire := client.PExpire("key", expiration)
|
|
|
|
Expect(pexpire.Err()).NotTo(HaveOccurred())
|
|
|
|
Expect(pexpire.Val()).To(Equal(true))
|
|
|
|
|
|
|
|
ttl := client.TTL("key")
|
|
|
|
Expect(ttl.Err()).NotTo(HaveOccurred())
|
|
|
|
Expect(ttl.Val()).To(Equal(time.Second))
|
|
|
|
|
|
|
|
pttl := client.PTTL("key")
|
|
|
|
Expect(pttl.Err()).NotTo(HaveOccurred())
|
2018-02-12 17:15:40 +03:00
|
|
|
Expect(pttl.Val()).To(BeNumerically("~", expiration, 100*time.Millisecond))
|
2015-01-15 18:51:22 +03:00
|
|
|
})
|
|
|
|
|
|
|
|
It("should PExpireAt", func() {
|
2015-01-31 12:08:56 +03:00
|
|
|
set := client.Set("key", "Hello", 0)
|
2015-01-15 18:51:22 +03:00
|
|
|
Expect(set.Err()).NotTo(HaveOccurred())
|
|
|
|
Expect(set.Val()).To(Equal("OK"))
|
|
|
|
|
|
|
|
expiration := 900 * time.Millisecond
|
|
|
|
pexpireat := client.PExpireAt("key", time.Now().Add(expiration))
|
|
|
|
Expect(pexpireat.Err()).NotTo(HaveOccurred())
|
|
|
|
Expect(pexpireat.Val()).To(Equal(true))
|
|
|
|
|
|
|
|
ttl := client.TTL("key")
|
|
|
|
Expect(ttl.Err()).NotTo(HaveOccurred())
|
|
|
|
Expect(ttl.Val()).To(Equal(time.Second))
|
|
|
|
|
|
|
|
pttl := client.PTTL("key")
|
|
|
|
Expect(pttl.Err()).NotTo(HaveOccurred())
|
2018-02-12 17:15:40 +03:00
|
|
|
Expect(pttl.Val()).To(BeNumerically("~", expiration, 100*time.Millisecond))
|
2015-01-15 18:51:22 +03:00
|
|
|
})
|
|
|
|
|
|
|
|
It("should PTTL", func() {
|
2015-01-31 12:08:56 +03:00
|
|
|
set := client.Set("key", "Hello", 0)
|
2015-01-15 18:51:22 +03:00
|
|
|
Expect(set.Err()).NotTo(HaveOccurred())
|
|
|
|
Expect(set.Val()).To(Equal("OK"))
|
|
|
|
|
|
|
|
expiration := time.Second
|
|
|
|
expire := client.Expire("key", expiration)
|
|
|
|
Expect(expire.Err()).NotTo(HaveOccurred())
|
|
|
|
Expect(set.Val()).To(Equal("OK"))
|
|
|
|
|
|
|
|
pttl := client.PTTL("key")
|
|
|
|
Expect(pttl.Err()).NotTo(HaveOccurred())
|
2018-02-12 17:15:40 +03:00
|
|
|
Expect(pttl.Val()).To(BeNumerically("~", expiration, 100*time.Millisecond))
|
2015-01-15 18:51:22 +03:00
|
|
|
})
|
|
|
|
|
|
|
|
It("should RandomKey", func() {
|
|
|
|
randomKey := client.RandomKey()
|
|
|
|
Expect(randomKey.Err()).To(Equal(redis.Nil))
|
|
|
|
Expect(randomKey.Val()).To(Equal(""))
|
|
|
|
|
2015-01-31 12:08:56 +03:00
|
|
|
set := client.Set("key", "hello", 0)
|
2015-01-15 18:51:22 +03:00
|
|
|
Expect(set.Err()).NotTo(HaveOccurred())
|
|
|
|
Expect(set.Val()).To(Equal("OK"))
|
|
|
|
|
|
|
|
randomKey = client.RandomKey()
|
|
|
|
Expect(randomKey.Err()).NotTo(HaveOccurred())
|
|
|
|
Expect(randomKey.Val()).To(Equal("key"))
|
|
|
|
})
|
|
|
|
|
|
|
|
It("should Rename", func() {
|
2015-01-31 12:08:56 +03:00
|
|
|
set := client.Set("key", "hello", 0)
|
2015-01-15 18:51:22 +03:00
|
|
|
Expect(set.Err()).NotTo(HaveOccurred())
|
|
|
|
Expect(set.Val()).To(Equal("OK"))
|
|
|
|
|
|
|
|
status := client.Rename("key", "key1")
|
|
|
|
Expect(status.Err()).NotTo(HaveOccurred())
|
|
|
|
Expect(status.Val()).To(Equal("OK"))
|
|
|
|
|
|
|
|
get := client.Get("key1")
|
|
|
|
Expect(get.Err()).NotTo(HaveOccurred())
|
|
|
|
Expect(get.Val()).To(Equal("hello"))
|
|
|
|
})
|
|
|
|
|
|
|
|
It("should RenameNX", func() {
|
2015-01-31 12:08:56 +03:00
|
|
|
set := client.Set("key", "hello", 0)
|
2015-01-15 18:51:22 +03:00
|
|
|
Expect(set.Err()).NotTo(HaveOccurred())
|
|
|
|
Expect(set.Val()).To(Equal("OK"))
|
|
|
|
|
|
|
|
renameNX := client.RenameNX("key", "key1")
|
|
|
|
Expect(renameNX.Err()).NotTo(HaveOccurred())
|
|
|
|
Expect(renameNX.Val()).To(Equal(true))
|
|
|
|
|
|
|
|
get := client.Get("key1")
|
|
|
|
Expect(get.Err()).NotTo(HaveOccurred())
|
|
|
|
Expect(get.Val()).To(Equal("hello"))
|
|
|
|
})
|
|
|
|
|
|
|
|
It("should Restore", func() {
|
2015-07-11 12:23:04 +03:00
|
|
|
err := client.Set("key", "hello", 0).Err()
|
|
|
|
Expect(err).NotTo(HaveOccurred())
|
2015-01-15 18:51:22 +03:00
|
|
|
|
|
|
|
dump := client.Dump("key")
|
|
|
|
Expect(dump.Err()).NotTo(HaveOccurred())
|
|
|
|
|
2015-07-11 12:23:04 +03:00
|
|
|
err = client.Del("key").Err()
|
|
|
|
Expect(err).NotTo(HaveOccurred())
|
2015-01-15 18:51:22 +03:00
|
|
|
|
2015-07-11 12:23:04 +03:00
|
|
|
restore, err := client.Restore("key", 0, dump.Val()).Result()
|
|
|
|
Expect(err).NotTo(HaveOccurred())
|
|
|
|
Expect(restore).To(Equal("OK"))
|
|
|
|
|
|
|
|
type_, err := client.Type("key").Result()
|
|
|
|
Expect(err).NotTo(HaveOccurred())
|
|
|
|
Expect(type_).To(Equal("string"))
|
2015-01-15 18:51:22 +03:00
|
|
|
|
2015-07-11 12:23:04 +03:00
|
|
|
val, err := client.Get("key").Result()
|
|
|
|
Expect(err).NotTo(HaveOccurred())
|
|
|
|
Expect(val).To(Equal("hello"))
|
|
|
|
})
|
2015-01-15 18:51:22 +03:00
|
|
|
|
2015-07-11 12:23:04 +03:00
|
|
|
It("should RestoreReplace", func() {
|
|
|
|
err := client.Set("key", "hello", 0).Err()
|
|
|
|
Expect(err).NotTo(HaveOccurred())
|
|
|
|
|
|
|
|
dump := client.Dump("key")
|
|
|
|
Expect(dump.Err()).NotTo(HaveOccurred())
|
|
|
|
|
|
|
|
restore, err := client.RestoreReplace("key", 0, dump.Val()).Result()
|
|
|
|
Expect(err).NotTo(HaveOccurred())
|
|
|
|
Expect(restore).To(Equal("OK"))
|
|
|
|
|
|
|
|
type_, err := client.Type("key").Result()
|
|
|
|
Expect(err).NotTo(HaveOccurred())
|
|
|
|
Expect(type_).To(Equal("string"))
|
|
|
|
|
|
|
|
val, err := client.Get("key").Result()
|
|
|
|
Expect(err).NotTo(HaveOccurred())
|
|
|
|
Expect(val).To(Equal("hello"))
|
2015-01-15 18:51:22 +03:00
|
|
|
})
|
|
|
|
|
|
|
|
It("should Sort", func() {
|
2016-01-22 13:29:23 +03:00
|
|
|
size, err := client.LPush("list", "1").Result()
|
|
|
|
Expect(err).NotTo(HaveOccurred())
|
|
|
|
Expect(size).To(Equal(int64(1)))
|
|
|
|
|
|
|
|
size, err = client.LPush("list", "3").Result()
|
|
|
|
Expect(err).NotTo(HaveOccurred())
|
|
|
|
Expect(size).To(Equal(int64(2)))
|
|
|
|
|
|
|
|
size, err = client.LPush("list", "2").Result()
|
|
|
|
Expect(err).NotTo(HaveOccurred())
|
|
|
|
Expect(size).To(Equal(int64(3)))
|
|
|
|
|
2018-02-13 17:08:11 +03:00
|
|
|
els, err := client.Sort("list", &redis.Sort{
|
2016-01-22 13:29:23 +03:00
|
|
|
Offset: 0,
|
|
|
|
Count: 2,
|
|
|
|
Order: "ASC",
|
|
|
|
}).Result()
|
|
|
|
Expect(err).NotTo(HaveOccurred())
|
|
|
|
Expect(els).To(Equal([]string{"1", "2"}))
|
|
|
|
})
|
|
|
|
|
|
|
|
It("should Sort and Get", func() {
|
|
|
|
size, err := client.LPush("list", "1").Result()
|
|
|
|
Expect(err).NotTo(HaveOccurred())
|
|
|
|
Expect(size).To(Equal(int64(1)))
|
|
|
|
|
|
|
|
size, err = client.LPush("list", "3").Result()
|
|
|
|
Expect(err).NotTo(HaveOccurred())
|
|
|
|
Expect(size).To(Equal(int64(2)))
|
|
|
|
|
|
|
|
size, err = client.LPush("list", "2").Result()
|
|
|
|
Expect(err).NotTo(HaveOccurred())
|
|
|
|
Expect(size).To(Equal(int64(3)))
|
|
|
|
|
|
|
|
err = client.Set("object_2", "value2", 0).Err()
|
|
|
|
Expect(err).NotTo(HaveOccurred())
|
|
|
|
|
|
|
|
{
|
2018-02-13 17:08:11 +03:00
|
|
|
els, err := client.Sort("list", &redis.Sort{
|
2016-01-22 13:29:23 +03:00
|
|
|
Get: []string{"object_*"},
|
|
|
|
}).Result()
|
|
|
|
Expect(err).NotTo(HaveOccurred())
|
|
|
|
Expect(els).To(Equal([]string{"", "value2", ""}))
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
2018-02-13 17:08:11 +03:00
|
|
|
els, err := client.SortInterfaces("list", &redis.Sort{
|
2016-01-22 13:29:23 +03:00
|
|
|
Get: []string{"object_*"},
|
|
|
|
}).Result()
|
|
|
|
Expect(err).NotTo(HaveOccurred())
|
|
|
|
Expect(els).To(Equal([]interface{}{nil, "value2", nil}))
|
|
|
|
}
|
2015-01-15 18:51:22 +03:00
|
|
|
})
|
|
|
|
|
2018-02-13 17:08:11 +03:00
|
|
|
It("should Sort and Store", func() {
|
|
|
|
size, err := client.LPush("list", "1").Result()
|
|
|
|
Expect(err).NotTo(HaveOccurred())
|
|
|
|
Expect(size).To(Equal(int64(1)))
|
|
|
|
|
|
|
|
size, err = client.LPush("list", "3").Result()
|
|
|
|
Expect(err).NotTo(HaveOccurred())
|
|
|
|
Expect(size).To(Equal(int64(2)))
|
|
|
|
|
|
|
|
size, err = client.LPush("list", "2").Result()
|
|
|
|
Expect(err).NotTo(HaveOccurred())
|
|
|
|
Expect(size).To(Equal(int64(3)))
|
|
|
|
|
|
|
|
n, err := client.SortStore("list", "list2", &redis.Sort{
|
|
|
|
Offset: 0,
|
|
|
|
Count: 2,
|
|
|
|
Order: "ASC",
|
|
|
|
}).Result()
|
|
|
|
Expect(err).NotTo(HaveOccurred())
|
|
|
|
Expect(n).To(Equal(int64(2)))
|
|
|
|
|
|
|
|
els, err := client.LRange("list2", 0, -1).Result()
|
|
|
|
Expect(err).NotTo(HaveOccurred())
|
|
|
|
Expect(els).To(Equal([]string{"1", "2"}))
|
|
|
|
})
|
|
|
|
|
2018-02-14 07:42:19 +03:00
|
|
|
It("should Touch", func() {
|
|
|
|
set1 := client.Set("touch1", "hello", 0)
|
|
|
|
Expect(set1.Err()).NotTo(HaveOccurred())
|
|
|
|
Expect(set1.Val()).To(Equal("OK"))
|
|
|
|
|
|
|
|
set2 := client.Set("touch2", "hello", 0)
|
|
|
|
Expect(set2.Err()).NotTo(HaveOccurred())
|
|
|
|
Expect(set2.Val()).To(Equal("OK"))
|
|
|
|
|
|
|
|
touch := client.Touch("touch1", "touch2", "touch3")
|
|
|
|
Expect(touch.Err()).NotTo(HaveOccurred())
|
|
|
|
Expect(touch.Val()).To(Equal(int64(2)))
|
|
|
|
})
|
|
|
|
|
2015-01-15 18:51:22 +03:00
|
|
|
It("should TTL", func() {
|
|
|
|
ttl := client.TTL("key")
|
|
|
|
Expect(ttl.Err()).NotTo(HaveOccurred())
|
|
|
|
Expect(ttl.Val() < 0).To(Equal(true))
|
|
|
|
|
2015-01-31 12:08:56 +03:00
|
|
|
set := client.Set("key", "hello", 0)
|
2015-01-15 18:51:22 +03:00
|
|
|
Expect(set.Err()).NotTo(HaveOccurred())
|
|
|
|
Expect(set.Val()).To(Equal("OK"))
|
|
|
|
|
|
|
|
expire := client.Expire("key", 60*time.Second)
|
|
|
|
Expect(expire.Err()).NotTo(HaveOccurred())
|
|
|
|
Expect(expire.Val()).To(Equal(true))
|
|
|
|
|
|
|
|
ttl = client.TTL("key")
|
|
|
|
Expect(ttl.Err()).NotTo(HaveOccurred())
|
|
|
|
Expect(ttl.Val()).To(Equal(60 * time.Second))
|
|
|
|
})
|
|
|
|
|
|
|
|
It("should Type", func() {
|
2015-01-31 12:08:56 +03:00
|
|
|
set := client.Set("key", "hello", 0)
|
2015-01-15 18:51:22 +03:00
|
|
|
Expect(set.Err()).NotTo(HaveOccurred())
|
|
|
|
Expect(set.Val()).To(Equal("OK"))
|
|
|
|
|
|
|
|
type_ := client.Type("key")
|
|
|
|
Expect(type_.Err()).NotTo(HaveOccurred())
|
|
|
|
Expect(type_.Val()).To(Equal("string"))
|
|
|
|
})
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
Describe("scanning", func() {
|
|
|
|
|
|
|
|
It("should Scan", func() {
|
|
|
|
for i := 0; i < 1000; i++ {
|
2015-01-31 12:08:56 +03:00
|
|
|
set := client.Set(fmt.Sprintf("key%d", i), "hello", 0)
|
2015-01-15 18:51:22 +03:00
|
|
|
Expect(set.Err()).NotTo(HaveOccurred())
|
|
|
|
}
|
|
|
|
|
2016-04-09 13:07:42 +03:00
|
|
|
keys, cursor, err := client.Scan(0, "", 0).Result()
|
2015-01-15 18:51:22 +03:00
|
|
|
Expect(err).NotTo(HaveOccurred())
|
2016-04-09 13:07:42 +03:00
|
|
|
Expect(keys).NotTo(BeEmpty())
|
|
|
|
Expect(cursor).NotTo(BeZero())
|
2015-01-15 18:51:22 +03:00
|
|
|
})
|
|
|
|
|
|
|
|
It("should SScan", func() {
|
|
|
|
for i := 0; i < 1000; i++ {
|
|
|
|
sadd := client.SAdd("myset", fmt.Sprintf("member%d", i))
|
|
|
|
Expect(sadd.Err()).NotTo(HaveOccurred())
|
|
|
|
}
|
|
|
|
|
2016-04-09 13:07:42 +03:00
|
|
|
keys, cursor, err := client.SScan("myset", 0, "", 0).Result()
|
2015-01-15 18:51:22 +03:00
|
|
|
Expect(err).NotTo(HaveOccurred())
|
2016-04-09 13:07:42 +03:00
|
|
|
Expect(keys).NotTo(BeEmpty())
|
|
|
|
Expect(cursor).NotTo(BeZero())
|
2015-01-15 18:51:22 +03:00
|
|
|
})
|
|
|
|
|
|
|
|
It("should HScan", func() {
|
|
|
|
for i := 0; i < 1000; i++ {
|
|
|
|
sadd := client.HSet("myhash", fmt.Sprintf("key%d", i), "hello")
|
|
|
|
Expect(sadd.Err()).NotTo(HaveOccurred())
|
|
|
|
}
|
|
|
|
|
2016-04-09 13:07:42 +03:00
|
|
|
keys, cursor, err := client.HScan("myhash", 0, "", 0).Result()
|
2015-01-15 18:51:22 +03:00
|
|
|
Expect(err).NotTo(HaveOccurred())
|
2016-04-09 13:07:42 +03:00
|
|
|
Expect(keys).NotTo(BeEmpty())
|
|
|
|
Expect(cursor).NotTo(BeZero())
|
2015-01-15 18:51:22 +03:00
|
|
|
})
|
|
|
|
|
|
|
|
It("should ZScan", func() {
|
|
|
|
for i := 0; i < 1000; i++ {
|
2018-03-07 12:56:24 +03:00
|
|
|
err := client.ZAdd("myset", redis.Z{
|
|
|
|
Score: float64(i),
|
|
|
|
Member: fmt.Sprintf("member%d", i),
|
|
|
|
}).Err()
|
|
|
|
Expect(err).NotTo(HaveOccurred())
|
2015-01-15 18:51:22 +03:00
|
|
|
}
|
|
|
|
|
2016-04-09 13:07:42 +03:00
|
|
|
keys, cursor, err := client.ZScan("myset", 0, "", 0).Result()
|
2015-01-15 18:51:22 +03:00
|
|
|
Expect(err).NotTo(HaveOccurred())
|
2016-04-09 13:07:42 +03:00
|
|
|
Expect(keys).NotTo(BeEmpty())
|
|
|
|
Expect(cursor).NotTo(BeZero())
|
2015-01-15 18:51:22 +03:00
|
|
|
})
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
Describe("strings", func() {
|
|
|
|
|
|
|
|
It("should Append", func() {
|
2017-02-18 17:32:39 +03:00
|
|
|
n, err := client.Exists("key").Result()
|
|
|
|
Expect(err).NotTo(HaveOccurred())
|
|
|
|
Expect(n).To(Equal(int64(0)))
|
2015-01-15 18:51:22 +03:00
|
|
|
|
|
|
|
append := client.Append("key", "Hello")
|
|
|
|
Expect(append.Err()).NotTo(HaveOccurred())
|
|
|
|
Expect(append.Val()).To(Equal(int64(5)))
|
|
|
|
|
|
|
|
append = client.Append("key", " World")
|
|
|
|
Expect(append.Err()).NotTo(HaveOccurred())
|
|
|
|
Expect(append.Val()).To(Equal(int64(11)))
|
|
|
|
|
|
|
|
get := client.Get("key")
|
|
|
|
Expect(get.Err()).NotTo(HaveOccurred())
|
|
|
|
Expect(get.Val()).To(Equal("Hello World"))
|
|
|
|
})
|
|
|
|
|
|
|
|
It("should BitCount", func() {
|
2015-01-31 12:08:56 +03:00
|
|
|
set := client.Set("key", "foobar", 0)
|
2015-01-15 18:51:22 +03:00
|
|
|
Expect(set.Err()).NotTo(HaveOccurred())
|
|
|
|
Expect(set.Val()).To(Equal("OK"))
|
|
|
|
|
|
|
|
bitCount := client.BitCount("key", nil)
|
|
|
|
Expect(bitCount.Err()).NotTo(HaveOccurred())
|
|
|
|
Expect(bitCount.Val()).To(Equal(int64(26)))
|
|
|
|
|
2018-03-07 12:56:24 +03:00
|
|
|
bitCount = client.BitCount("key", &redis.BitCount{
|
|
|
|
Start: 0,
|
|
|
|
End: 0,
|
|
|
|
})
|
2015-01-15 18:51:22 +03:00
|
|
|
Expect(bitCount.Err()).NotTo(HaveOccurred())
|
|
|
|
Expect(bitCount.Val()).To(Equal(int64(4)))
|
|
|
|
|
2018-03-07 12:56:24 +03:00
|
|
|
bitCount = client.BitCount("key", &redis.BitCount{
|
|
|
|
Start: 1,
|
|
|
|
End: 1,
|
|
|
|
})
|
2015-01-15 18:51:22 +03:00
|
|
|
Expect(bitCount.Err()).NotTo(HaveOccurred())
|
|
|
|
Expect(bitCount.Val()).To(Equal(int64(6)))
|
|
|
|
})
|
|
|
|
|
|
|
|
It("should BitOpAnd", func() {
|
2015-01-31 12:08:56 +03:00
|
|
|
set := client.Set("key1", "1", 0)
|
2015-01-15 18:51:22 +03:00
|
|
|
Expect(set.Err()).NotTo(HaveOccurred())
|
|
|
|
Expect(set.Val()).To(Equal("OK"))
|
|
|
|
|
2015-01-31 12:08:56 +03:00
|
|
|
set = client.Set("key2", "0", 0)
|
2015-01-15 18:51:22 +03:00
|
|
|
Expect(set.Err()).NotTo(HaveOccurred())
|
|
|
|
Expect(set.Val()).To(Equal("OK"))
|
|
|
|
|
|
|
|
bitOpAnd := client.BitOpAnd("dest", "key1", "key2")
|
|
|
|
Expect(bitOpAnd.Err()).NotTo(HaveOccurred())
|
|
|
|
Expect(bitOpAnd.Val()).To(Equal(int64(1)))
|
|
|
|
|
|
|
|
get := client.Get("dest")
|
|
|
|
Expect(get.Err()).NotTo(HaveOccurred())
|
|
|
|
Expect(get.Val()).To(Equal("0"))
|
|
|
|
})
|
|
|
|
|
|
|
|
It("should BitOpOr", func() {
|
2015-01-31 12:08:56 +03:00
|
|
|
set := client.Set("key1", "1", 0)
|
2015-01-15 18:51:22 +03:00
|
|
|
Expect(set.Err()).NotTo(HaveOccurred())
|
|
|
|
Expect(set.Val()).To(Equal("OK"))
|
|
|
|
|
2015-01-31 12:08:56 +03:00
|
|
|
set = client.Set("key2", "0", 0)
|
2015-01-15 18:51:22 +03:00
|
|
|
Expect(set.Err()).NotTo(HaveOccurred())
|
|
|
|
Expect(set.Val()).To(Equal("OK"))
|
|
|
|
|
|
|
|
bitOpOr := client.BitOpOr("dest", "key1", "key2")
|
|
|
|
Expect(bitOpOr.Err()).NotTo(HaveOccurred())
|
|
|
|
Expect(bitOpOr.Val()).To(Equal(int64(1)))
|
|
|
|
|
|
|
|
get := client.Get("dest")
|
|
|
|
Expect(get.Err()).NotTo(HaveOccurred())
|
|
|
|
Expect(get.Val()).To(Equal("1"))
|
|
|
|
})
|
|
|
|
|
|
|
|
It("should BitOpXor", func() {
|
2015-01-31 12:08:56 +03:00
|
|
|
set := client.Set("key1", "\xff", 0)
|
2015-01-15 18:51:22 +03:00
|
|
|
Expect(set.Err()).NotTo(HaveOccurred())
|
|
|
|
Expect(set.Val()).To(Equal("OK"))
|
|
|
|
|
2015-01-31 12:08:56 +03:00
|
|
|
set = client.Set("key2", "\x0f", 0)
|
2015-01-15 18:51:22 +03:00
|
|
|
Expect(set.Err()).NotTo(HaveOccurred())
|
|
|
|
Expect(set.Val()).To(Equal("OK"))
|
|
|
|
|
|
|
|
bitOpXor := client.BitOpXor("dest", "key1", "key2")
|
|
|
|
Expect(bitOpXor.Err()).NotTo(HaveOccurred())
|
|
|
|
Expect(bitOpXor.Val()).To(Equal(int64(1)))
|
|
|
|
|
|
|
|
get := client.Get("dest")
|
|
|
|
Expect(get.Err()).NotTo(HaveOccurred())
|
|
|
|
Expect(get.Val()).To(Equal("\xf0"))
|
|
|
|
})
|
|
|
|
|
|
|
|
It("should BitOpNot", func() {
|
2015-01-31 12:08:56 +03:00
|
|
|
set := client.Set("key1", "\x00", 0)
|
2015-01-15 18:51:22 +03:00
|
|
|
Expect(set.Err()).NotTo(HaveOccurred())
|
|
|
|
Expect(set.Val()).To(Equal("OK"))
|
|
|
|
|
|
|
|
bitOpNot := client.BitOpNot("dest", "key1")
|
|
|
|
Expect(bitOpNot.Err()).NotTo(HaveOccurred())
|
|
|
|
Expect(bitOpNot.Val()).To(Equal(int64(1)))
|
|
|
|
|
|
|
|
get := client.Get("dest")
|
|
|
|
Expect(get.Err()).NotTo(HaveOccurred())
|
|
|
|
Expect(get.Val()).To(Equal("\xff"))
|
|
|
|
})
|
|
|
|
|
2014-10-07 14:54:43 +04:00
|
|
|
It("should BitPos", func() {
|
|
|
|
err := client.Set("mykey", "\xff\xf0\x00", 0).Err()
|
|
|
|
Expect(err).NotTo(HaveOccurred())
|
|
|
|
|
|
|
|
pos, err := client.BitPos("mykey", 0).Result()
|
|
|
|
Expect(err).NotTo(HaveOccurred())
|
|
|
|
Expect(pos).To(Equal(int64(12)))
|
|
|
|
|
|
|
|
pos, err = client.BitPos("mykey", 1).Result()
|
|
|
|
Expect(err).NotTo(HaveOccurred())
|
|
|
|
Expect(pos).To(Equal(int64(0)))
|
|
|
|
|
|
|
|
pos, err = client.BitPos("mykey", 0, 2).Result()
|
|
|
|
Expect(err).NotTo(HaveOccurred())
|
|
|
|
Expect(pos).To(Equal(int64(16)))
|
|
|
|
|
|
|
|
pos, err = client.BitPos("mykey", 1, 2).Result()
|
|
|
|
Expect(err).NotTo(HaveOccurred())
|
|
|
|
Expect(pos).To(Equal(int64(-1)))
|
|
|
|
|
|
|
|
pos, err = client.BitPos("mykey", 0, -1).Result()
|
|
|
|
Expect(err).NotTo(HaveOccurred())
|
|
|
|
Expect(pos).To(Equal(int64(16)))
|
|
|
|
|
|
|
|
pos, err = client.BitPos("mykey", 1, -1).Result()
|
|
|
|
Expect(err).NotTo(HaveOccurred())
|
|
|
|
Expect(pos).To(Equal(int64(-1)))
|
|
|
|
|
|
|
|
pos, err = client.BitPos("mykey", 0, 2, 1).Result()
|
|
|
|
Expect(err).NotTo(HaveOccurred())
|
|
|
|
Expect(pos).To(Equal(int64(-1)))
|
|
|
|
|
|
|
|
pos, err = client.BitPos("mykey", 0, 0, -3).Result()
|
|
|
|
Expect(err).NotTo(HaveOccurred())
|
|
|
|
Expect(pos).To(Equal(int64(-1)))
|
|
|
|
|
|
|
|
pos, err = client.BitPos("mykey", 0, 0, 0).Result()
|
|
|
|
Expect(err).NotTo(HaveOccurred())
|
|
|
|
Expect(pos).To(Equal(int64(-1)))
|
|
|
|
})
|
|
|
|
|
2015-01-15 18:51:22 +03:00
|
|
|
It("should Decr", func() {
|
2015-01-31 12:08:56 +03:00
|
|
|
set := client.Set("key", "10", 0)
|
2015-01-15 18:51:22 +03:00
|
|
|
Expect(set.Err()).NotTo(HaveOccurred())
|
|
|
|
Expect(set.Val()).To(Equal("OK"))
|
|
|
|
|
|
|
|
decr := client.Decr("key")
|
|
|
|
Expect(decr.Err()).NotTo(HaveOccurred())
|
|
|
|
Expect(decr.Val()).To(Equal(int64(9)))
|
|
|
|
|
2015-01-31 12:08:56 +03:00
|
|
|
set = client.Set("key", "234293482390480948029348230948", 0)
|
2015-01-15 18:51:22 +03:00
|
|
|
Expect(set.Err()).NotTo(HaveOccurred())
|
|
|
|
Expect(set.Val()).To(Equal("OK"))
|
|
|
|
|
|
|
|
decr = client.Decr("key")
|
|
|
|
Expect(decr.Err()).To(MatchError("ERR value is not an integer or out of range"))
|
|
|
|
Expect(decr.Val()).To(Equal(int64(0)))
|
|
|
|
})
|
|
|
|
|
|
|
|
It("should DecrBy", func() {
|
2015-01-31 12:08:56 +03:00
|
|
|
set := client.Set("key", "10", 0)
|
2015-01-15 18:51:22 +03:00
|
|
|
Expect(set.Err()).NotTo(HaveOccurred())
|
|
|
|
Expect(set.Val()).To(Equal("OK"))
|
|
|
|
|
|
|
|
decrBy := client.DecrBy("key", 5)
|
|
|
|
Expect(decrBy.Err()).NotTo(HaveOccurred())
|
|
|
|
Expect(decrBy.Val()).To(Equal(int64(5)))
|
|
|
|
})
|
|
|
|
|
|
|
|
It("should Get", func() {
|
|
|
|
get := client.Get("_")
|
|
|
|
Expect(get.Err()).To(Equal(redis.Nil))
|
|
|
|
Expect(get.Val()).To(Equal(""))
|
|
|
|
|
2015-01-31 12:08:56 +03:00
|
|
|
set := client.Set("key", "hello", 0)
|
2015-01-15 18:51:22 +03:00
|
|
|
Expect(set.Err()).NotTo(HaveOccurred())
|
|
|
|
Expect(set.Val()).To(Equal("OK"))
|
|
|
|
|
|
|
|
get = client.Get("key")
|
|
|
|
Expect(get.Err()).NotTo(HaveOccurred())
|
|
|
|
Expect(get.Val()).To(Equal("hello"))
|
|
|
|
})
|
|
|
|
|
|
|
|
It("should GetBit", func() {
|
|
|
|
setBit := client.SetBit("key", 7, 1)
|
|
|
|
Expect(setBit.Err()).NotTo(HaveOccurred())
|
|
|
|
Expect(setBit.Val()).To(Equal(int64(0)))
|
|
|
|
|
|
|
|
getBit := client.GetBit("key", 0)
|
|
|
|
Expect(getBit.Err()).NotTo(HaveOccurred())
|
|
|
|
Expect(getBit.Val()).To(Equal(int64(0)))
|
|
|
|
|
|
|
|
getBit = client.GetBit("key", 7)
|
|
|
|
Expect(getBit.Err()).NotTo(HaveOccurred())
|
|
|
|
Expect(getBit.Val()).To(Equal(int64(1)))
|
|
|
|
|
|
|
|
getBit = client.GetBit("key", 100)
|
|
|
|
Expect(getBit.Err()).NotTo(HaveOccurred())
|
|
|
|
Expect(getBit.Val()).To(Equal(int64(0)))
|
|
|
|
})
|
|
|
|
|
|
|
|
It("should GetRange", func() {
|
2015-01-31 12:08:56 +03:00
|
|
|
set := client.Set("key", "This is a string", 0)
|
2015-01-15 18:51:22 +03:00
|
|
|
Expect(set.Err()).NotTo(HaveOccurred())
|
|
|
|
Expect(set.Val()).To(Equal("OK"))
|
|
|
|
|
|
|
|
getRange := client.GetRange("key", 0, 3)
|
|
|
|
Expect(getRange.Err()).NotTo(HaveOccurred())
|
|
|
|
Expect(getRange.Val()).To(Equal("This"))
|
|
|
|
|
|
|
|
getRange = client.GetRange("key", -3, -1)
|
|
|
|
Expect(getRange.Err()).NotTo(HaveOccurred())
|
|
|
|
Expect(getRange.Val()).To(Equal("ing"))
|
|
|
|
|
|
|
|
getRange = client.GetRange("key", 0, -1)
|
|
|
|
Expect(getRange.Err()).NotTo(HaveOccurred())
|
|
|
|
Expect(getRange.Val()).To(Equal("This is a string"))
|
|
|
|
|
|
|
|
getRange = client.GetRange("key", 10, 100)
|
|
|
|
Expect(getRange.Err()).NotTo(HaveOccurred())
|
|
|
|
Expect(getRange.Val()).To(Equal("string"))
|
|
|
|
})
|
|
|
|
|
|
|
|
It("should GetSet", func() {
|
|
|
|
incr := client.Incr("key")
|
|
|
|
Expect(incr.Err()).NotTo(HaveOccurred())
|
|
|
|
Expect(incr.Val()).To(Equal(int64(1)))
|
|
|
|
|
|
|
|
getSet := client.GetSet("key", "0")
|
|
|
|
Expect(getSet.Err()).NotTo(HaveOccurred())
|
|
|
|
Expect(getSet.Val()).To(Equal("1"))
|
|
|
|
|
|
|
|
get := client.Get("key")
|
|
|
|
Expect(get.Err()).NotTo(HaveOccurred())
|
|
|
|
Expect(get.Val()).To(Equal("0"))
|
|
|
|
})
|
|
|
|
|
|
|
|
It("should Incr", func() {
|
2015-01-31 12:08:56 +03:00
|
|
|
set := client.Set("key", "10", 0)
|
2015-01-15 18:51:22 +03:00
|
|
|
Expect(set.Err()).NotTo(HaveOccurred())
|
|
|
|
Expect(set.Val()).To(Equal("OK"))
|
|
|
|
|
|
|
|
incr := client.Incr("key")
|
|
|
|
Expect(incr.Err()).NotTo(HaveOccurred())
|
|
|
|
Expect(incr.Val()).To(Equal(int64(11)))
|
|
|
|
|
|
|
|
get := client.Get("key")
|
|
|
|
Expect(get.Err()).NotTo(HaveOccurred())
|
|
|
|
Expect(get.Val()).To(Equal("11"))
|
|
|
|
})
|
|
|
|
|
|
|
|
It("should IncrBy", func() {
|
2015-01-31 12:08:56 +03:00
|
|
|
set := client.Set("key", "10", 0)
|
2015-01-15 18:51:22 +03:00
|
|
|
Expect(set.Err()).NotTo(HaveOccurred())
|
|
|
|
Expect(set.Val()).To(Equal("OK"))
|
|
|
|
|
|
|
|
incrBy := client.IncrBy("key", 5)
|
|
|
|
Expect(incrBy.Err()).NotTo(HaveOccurred())
|
|
|
|
Expect(incrBy.Val()).To(Equal(int64(15)))
|
|
|
|
})
|
|
|
|
|
|
|
|
It("should IncrByFloat", func() {
|
2015-01-31 12:08:56 +03:00
|
|
|
set := client.Set("key", "10.50", 0)
|
2015-01-15 18:51:22 +03:00
|
|
|
Expect(set.Err()).NotTo(HaveOccurred())
|
|
|
|
Expect(set.Val()).To(Equal("OK"))
|
|
|
|
|
|
|
|
incrByFloat := client.IncrByFloat("key", 0.1)
|
|
|
|
Expect(incrByFloat.Err()).NotTo(HaveOccurred())
|
|
|
|
Expect(incrByFloat.Val()).To(Equal(10.6))
|
|
|
|
|
2015-01-31 12:08:56 +03:00
|
|
|
set = client.Set("key", "5.0e3", 0)
|
2015-01-15 18:51:22 +03:00
|
|
|
Expect(set.Err()).NotTo(HaveOccurred())
|
|
|
|
Expect(set.Val()).To(Equal("OK"))
|
|
|
|
|
|
|
|
incrByFloat = client.IncrByFloat("key", 2.0e2)
|
|
|
|
Expect(incrByFloat.Err()).NotTo(HaveOccurred())
|
|
|
|
Expect(incrByFloat.Val()).To(Equal(float64(5200)))
|
|
|
|
})
|
|
|
|
|
|
|
|
It("should IncrByFloatOverflow", func() {
|
|
|
|
incrByFloat := client.IncrByFloat("key", 996945661)
|
|
|
|
Expect(incrByFloat.Err()).NotTo(HaveOccurred())
|
|
|
|
Expect(incrByFloat.Val()).To(Equal(float64(996945661)))
|
|
|
|
})
|
|
|
|
|
|
|
|
It("should MSetMGet", func() {
|
|
|
|
mSet := client.MSet("key1", "hello1", "key2", "hello2")
|
|
|
|
Expect(mSet.Err()).NotTo(HaveOccurred())
|
|
|
|
Expect(mSet.Val()).To(Equal("OK"))
|
|
|
|
|
|
|
|
mGet := client.MGet("key1", "key2", "_")
|
|
|
|
Expect(mGet.Err()).NotTo(HaveOccurred())
|
|
|
|
Expect(mGet.Val()).To(Equal([]interface{}{"hello1", "hello2", nil}))
|
|
|
|
})
|
|
|
|
|
|
|
|
It("should MSetNX", func() {
|
|
|
|
mSetNX := client.MSetNX("key1", "hello1", "key2", "hello2")
|
|
|
|
Expect(mSetNX.Err()).NotTo(HaveOccurred())
|
|
|
|
Expect(mSetNX.Val()).To(Equal(true))
|
|
|
|
|
|
|
|
mSetNX = client.MSetNX("key2", "hello1", "key3", "hello2")
|
|
|
|
Expect(mSetNX.Err()).NotTo(HaveOccurred())
|
|
|
|
Expect(mSetNX.Val()).To(Equal(false))
|
|
|
|
})
|
|
|
|
|
2015-01-31 12:08:56 +03:00
|
|
|
It("should Set with expiration", func() {
|
|
|
|
err := client.Set("key", "hello", 100*time.Millisecond).Err()
|
|
|
|
Expect(err).NotTo(HaveOccurred())
|
|
|
|
|
|
|
|
val, err := client.Get("key").Result()
|
|
|
|
Expect(err).NotTo(HaveOccurred())
|
|
|
|
Expect(val).To(Equal("hello"))
|
|
|
|
|
|
|
|
Eventually(func() error {
|
|
|
|
return client.Get("foo").Err()
|
|
|
|
}, "1s", "100ms").Should(Equal(redis.Nil))
|
|
|
|
})
|
|
|
|
|
2015-01-15 18:51:22 +03:00
|
|
|
It("should SetGet", func() {
|
2015-01-31 12:08:56 +03:00
|
|
|
set := client.Set("key", "hello", 0)
|
2015-01-15 18:51:22 +03:00
|
|
|
Expect(set.Err()).NotTo(HaveOccurred())
|
|
|
|
Expect(set.Val()).To(Equal("OK"))
|
|
|
|
|
|
|
|
get := client.Get("key")
|
|
|
|
Expect(get.Err()).NotTo(HaveOccurred())
|
|
|
|
Expect(get.Val()).To(Equal("hello"))
|
|
|
|
})
|
|
|
|
|
|
|
|
It("should SetNX", func() {
|
2015-01-31 12:08:56 +03:00
|
|
|
setNX := client.SetNX("key", "hello", 0)
|
2015-01-15 18:51:22 +03:00
|
|
|
Expect(setNX.Err()).NotTo(HaveOccurred())
|
|
|
|
Expect(setNX.Val()).To(Equal(true))
|
|
|
|
|
2015-01-31 12:08:56 +03:00
|
|
|
setNX = client.SetNX("key", "hello2", 0)
|
2015-01-15 18:51:22 +03:00
|
|
|
Expect(setNX.Err()).NotTo(HaveOccurred())
|
|
|
|
Expect(setNX.Val()).To(Equal(false))
|
|
|
|
|
|
|
|
get := client.Get("key")
|
|
|
|
Expect(get.Err()).NotTo(HaveOccurred())
|
|
|
|
Expect(get.Val()).To(Equal("hello"))
|
|
|
|
})
|
|
|
|
|
2015-01-31 12:08:56 +03:00
|
|
|
It("should SetNX with expiration", func() {
|
|
|
|
isSet, err := client.SetNX("key", "hello", time.Second).Result()
|
|
|
|
Expect(err).NotTo(HaveOccurred())
|
|
|
|
Expect(isSet).To(Equal(true))
|
|
|
|
|
|
|
|
isSet, err = client.SetNX("key", "hello2", time.Second).Result()
|
|
|
|
Expect(err).NotTo(HaveOccurred())
|
|
|
|
Expect(isSet).To(Equal(false))
|
|
|
|
|
|
|
|
val, err := client.Get("key").Result()
|
|
|
|
Expect(err).NotTo(HaveOccurred())
|
|
|
|
Expect(val).To(Equal("hello"))
|
|
|
|
})
|
|
|
|
|
|
|
|
It("should SetXX", func() {
|
2016-10-21 17:14:51 +03:00
|
|
|
isSet, err := client.SetXX("key", "hello2", 0).Result()
|
|
|
|
Expect(err).NotTo(HaveOccurred())
|
|
|
|
Expect(isSet).To(Equal(false))
|
|
|
|
|
|
|
|
err = client.Set("key", "hello", 0).Err()
|
|
|
|
Expect(err).NotTo(HaveOccurred())
|
|
|
|
|
|
|
|
isSet, err = client.SetXX("key", "hello2", 0).Result()
|
|
|
|
Expect(err).NotTo(HaveOccurred())
|
|
|
|
Expect(isSet).To(Equal(true))
|
|
|
|
|
|
|
|
val, err := client.Get("key").Result()
|
|
|
|
Expect(err).NotTo(HaveOccurred())
|
|
|
|
Expect(val).To(Equal("hello2"))
|
|
|
|
})
|
|
|
|
|
|
|
|
It("should SetXX with expiration", func() {
|
2015-01-31 12:08:56 +03:00
|
|
|
isSet, err := client.SetXX("key", "hello2", time.Second).Result()
|
|
|
|
Expect(err).NotTo(HaveOccurred())
|
|
|
|
Expect(isSet).To(Equal(false))
|
|
|
|
|
|
|
|
err = client.Set("key", "hello", time.Second).Err()
|
|
|
|
Expect(err).NotTo(HaveOccurred())
|
|
|
|
|
|
|
|
isSet, err = client.SetXX("key", "hello2", time.Second).Result()
|
|
|
|
Expect(err).NotTo(HaveOccurred())
|
|
|
|
Expect(isSet).To(Equal(true))
|
|
|
|
|
|
|
|
val, err := client.Get("key").Result()
|
|
|
|
Expect(err).NotTo(HaveOccurred())
|
|
|
|
Expect(val).To(Equal("hello2"))
|
|
|
|
})
|
|
|
|
|
2015-01-15 18:51:22 +03:00
|
|
|
It("should SetRange", func() {
|
2015-01-31 12:08:56 +03:00
|
|
|
set := client.Set("key", "Hello World", 0)
|
2015-01-15 18:51:22 +03:00
|
|
|
Expect(set.Err()).NotTo(HaveOccurred())
|
|
|
|
Expect(set.Val()).To(Equal("OK"))
|
|
|
|
|
|
|
|
range_ := client.SetRange("key", 6, "Redis")
|
|
|
|
Expect(range_.Err()).NotTo(HaveOccurred())
|
|
|
|
Expect(range_.Val()).To(Equal(int64(11)))
|
|
|
|
|
|
|
|
get := client.Get("key")
|
|
|
|
Expect(get.Err()).NotTo(HaveOccurred())
|
|
|
|
Expect(get.Val()).To(Equal("Hello Redis"))
|
|
|
|
})
|
|
|
|
|
|
|
|
It("should StrLen", func() {
|
2015-01-31 12:08:56 +03:00
|
|
|
set := client.Set("key", "hello", 0)
|
2015-01-15 18:51:22 +03:00
|
|
|
Expect(set.Err()).NotTo(HaveOccurred())
|
|
|
|
Expect(set.Val()).To(Equal("OK"))
|
|
|
|
|
|
|
|
strLen := client.StrLen("key")
|
|
|
|
Expect(strLen.Err()).NotTo(HaveOccurred())
|
|
|
|
Expect(strLen.Val()).To(Equal(int64(5)))
|
|
|
|
|
|
|
|
strLen = client.StrLen("_")
|
|
|
|
Expect(strLen.Err()).NotTo(HaveOccurred())
|
|
|
|
Expect(strLen.Val()).To(Equal(int64(0)))
|
|
|
|
})
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
Describe("hashes", func() {
|
|
|
|
|
|
|
|
It("should HDel", func() {
|
|
|
|
hSet := client.HSet("hash", "key", "hello")
|
|
|
|
Expect(hSet.Err()).NotTo(HaveOccurred())
|
|
|
|
|
|
|
|
hDel := client.HDel("hash", "key")
|
|
|
|
Expect(hDel.Err()).NotTo(HaveOccurred())
|
|
|
|
Expect(hDel.Val()).To(Equal(int64(1)))
|
|
|
|
|
|
|
|
hDel = client.HDel("hash", "key")
|
|
|
|
Expect(hDel.Err()).NotTo(HaveOccurred())
|
|
|
|
Expect(hDel.Val()).To(Equal(int64(0)))
|
|
|
|
})
|
|
|
|
|
|
|
|
It("should HExists", func() {
|
|
|
|
hSet := client.HSet("hash", "key", "hello")
|
|
|
|
Expect(hSet.Err()).NotTo(HaveOccurred())
|
|
|
|
|
|
|
|
hExists := client.HExists("hash", "key")
|
|
|
|
Expect(hExists.Err()).NotTo(HaveOccurred())
|
|
|
|
Expect(hExists.Val()).To(Equal(true))
|
|
|
|
|
|
|
|
hExists = client.HExists("hash", "key1")
|
|
|
|
Expect(hExists.Err()).NotTo(HaveOccurred())
|
|
|
|
Expect(hExists.Val()).To(Equal(false))
|
|
|
|
})
|
|
|
|
|
|
|
|
It("should HGet", func() {
|
|
|
|
hSet := client.HSet("hash", "key", "hello")
|
|
|
|
Expect(hSet.Err()).NotTo(HaveOccurred())
|
|
|
|
|
|
|
|
hGet := client.HGet("hash", "key")
|
|
|
|
Expect(hGet.Err()).NotTo(HaveOccurred())
|
|
|
|
Expect(hGet.Val()).To(Equal("hello"))
|
|
|
|
|
|
|
|
hGet = client.HGet("hash", "key1")
|
|
|
|
Expect(hGet.Err()).To(Equal(redis.Nil))
|
|
|
|
Expect(hGet.Val()).To(Equal(""))
|
|
|
|
})
|
|
|
|
|
|
|
|
It("should HGetAll", func() {
|
2016-05-02 14:50:59 +03:00
|
|
|
err := client.HSet("hash", "key1", "hello1").Err()
|
|
|
|
Expect(err).NotTo(HaveOccurred())
|
|
|
|
err = client.HSet("hash", "key2", "hello2").Err()
|
|
|
|
Expect(err).NotTo(HaveOccurred())
|
2015-01-15 18:51:22 +03:00
|
|
|
|
2016-05-02 14:50:59 +03:00
|
|
|
m, err := client.HGetAll("hash").Result()
|
|
|
|
Expect(err).NotTo(HaveOccurred())
|
|
|
|
Expect(m).To(Equal(map[string]string{"key1": "hello1", "key2": "hello2"}))
|
2015-01-15 18:51:22 +03:00
|
|
|
})
|
|
|
|
|
|
|
|
It("should HIncrBy", func() {
|
|
|
|
hSet := client.HSet("hash", "key", "5")
|
|
|
|
Expect(hSet.Err()).NotTo(HaveOccurred())
|
|
|
|
|
|
|
|
hIncrBy := client.HIncrBy("hash", "key", 1)
|
|
|
|
Expect(hIncrBy.Err()).NotTo(HaveOccurred())
|
|
|
|
Expect(hIncrBy.Val()).To(Equal(int64(6)))
|
|
|
|
|
|
|
|
hIncrBy = client.HIncrBy("hash", "key", -1)
|
|
|
|
Expect(hIncrBy.Err()).NotTo(HaveOccurred())
|
|
|
|
Expect(hIncrBy.Val()).To(Equal(int64(5)))
|
|
|
|
|
|
|
|
hIncrBy = client.HIncrBy("hash", "key", -10)
|
|
|
|
Expect(hIncrBy.Err()).NotTo(HaveOccurred())
|
|
|
|
Expect(hIncrBy.Val()).To(Equal(int64(-5)))
|
|
|
|
})
|
|
|
|
|
|
|
|
It("should HIncrByFloat", func() {
|
|
|
|
hSet := client.HSet("hash", "field", "10.50")
|
|
|
|
Expect(hSet.Err()).NotTo(HaveOccurred())
|
|
|
|
Expect(hSet.Val()).To(Equal(true))
|
|
|
|
|
|
|
|
hIncrByFloat := client.HIncrByFloat("hash", "field", 0.1)
|
|
|
|
Expect(hIncrByFloat.Err()).NotTo(HaveOccurred())
|
|
|
|
Expect(hIncrByFloat.Val()).To(Equal(10.6))
|
|
|
|
|
|
|
|
hSet = client.HSet("hash", "field", "5.0e3")
|
|
|
|
Expect(hSet.Err()).NotTo(HaveOccurred())
|
|
|
|
Expect(hSet.Val()).To(Equal(false))
|
|
|
|
|
|
|
|
hIncrByFloat = client.HIncrByFloat("hash", "field", 2.0e2)
|
|
|
|
Expect(hIncrByFloat.Err()).NotTo(HaveOccurred())
|
|
|
|
Expect(hIncrByFloat.Val()).To(Equal(float64(5200)))
|
|
|
|
})
|
|
|
|
|
|
|
|
It("should HKeys", func() {
|
|
|
|
hkeys := client.HKeys("hash")
|
|
|
|
Expect(hkeys.Err()).NotTo(HaveOccurred())
|
|
|
|
Expect(hkeys.Val()).To(Equal([]string{}))
|
|
|
|
|
|
|
|
hset := client.HSet("hash", "key1", "hello1")
|
|
|
|
Expect(hset.Err()).NotTo(HaveOccurred())
|
|
|
|
hset = client.HSet("hash", "key2", "hello2")
|
|
|
|
Expect(hset.Err()).NotTo(HaveOccurred())
|
|
|
|
|
|
|
|
hkeys = client.HKeys("hash")
|
|
|
|
Expect(hkeys.Err()).NotTo(HaveOccurred())
|
|
|
|
Expect(hkeys.Val()).To(Equal([]string{"key1", "key2"}))
|
|
|
|
})
|
|
|
|
|
|
|
|
It("should HLen", func() {
|
|
|
|
hSet := client.HSet("hash", "key1", "hello1")
|
|
|
|
Expect(hSet.Err()).NotTo(HaveOccurred())
|
|
|
|
hSet = client.HSet("hash", "key2", "hello2")
|
|
|
|
Expect(hSet.Err()).NotTo(HaveOccurred())
|
|
|
|
|
|
|
|
hLen := client.HLen("hash")
|
|
|
|
Expect(hLen.Err()).NotTo(HaveOccurred())
|
|
|
|
Expect(hLen.Val()).To(Equal(int64(2)))
|
|
|
|
})
|
|
|
|
|
|
|
|
It("should HMGet", func() {
|
2016-05-02 14:50:59 +03:00
|
|
|
err := client.HSet("hash", "key1", "hello1").Err()
|
|
|
|
Expect(err).NotTo(HaveOccurred())
|
|
|
|
err = client.HSet("hash", "key2", "hello2").Err()
|
|
|
|
Expect(err).NotTo(HaveOccurred())
|
2015-01-15 18:51:22 +03:00
|
|
|
|
2016-05-02 14:50:59 +03:00
|
|
|
vals, err := client.HMGet("hash", "key1", "key2", "_").Result()
|
|
|
|
Expect(err).NotTo(HaveOccurred())
|
|
|
|
Expect(vals).To(Equal([]interface{}{"hello1", "hello2", nil}))
|
2015-01-15 18:51:22 +03:00
|
|
|
})
|
|
|
|
|
|
|
|
It("should HMSet", func() {
|
2017-02-18 16:42:12 +03:00
|
|
|
ok, err := client.HMSet("hash", map[string]interface{}{
|
2016-05-02 14:50:59 +03:00
|
|
|
"key1": "hello1",
|
|
|
|
"key2": "hello2",
|
|
|
|
}).Result()
|
|
|
|
Expect(err).NotTo(HaveOccurred())
|
|
|
|
Expect(ok).To(Equal("OK"))
|
2015-01-15 18:51:22 +03:00
|
|
|
|
2016-05-02 14:50:59 +03:00
|
|
|
v, err := client.HGet("hash", "key1").Result()
|
|
|
|
Expect(err).NotTo(HaveOccurred())
|
|
|
|
Expect(v).To(Equal("hello1"))
|
2015-01-15 18:51:22 +03:00
|
|
|
|
2016-05-02 14:50:59 +03:00
|
|
|
v, err = client.HGet("hash", "key2").Result()
|
|
|
|
Expect(err).NotTo(HaveOccurred())
|
|
|
|
Expect(v).To(Equal("hello2"))
|
2015-01-15 18:51:22 +03:00
|
|
|
})
|
|
|
|
|
|
|
|
It("should HSet", func() {
|
|
|
|
hSet := client.HSet("hash", "key", "hello")
|
|
|
|
Expect(hSet.Err()).NotTo(HaveOccurred())
|
|
|
|
Expect(hSet.Val()).To(Equal(true))
|
|
|
|
|
|
|
|
hGet := client.HGet("hash", "key")
|
|
|
|
Expect(hGet.Err()).NotTo(HaveOccurred())
|
|
|
|
Expect(hGet.Val()).To(Equal("hello"))
|
|
|
|
})
|
|
|
|
|
|
|
|
It("should HSetNX", func() {
|
|
|
|
hSetNX := client.HSetNX("hash", "key", "hello")
|
|
|
|
Expect(hSetNX.Err()).NotTo(HaveOccurred())
|
|
|
|
Expect(hSetNX.Val()).To(Equal(true))
|
|
|
|
|
|
|
|
hSetNX = client.HSetNX("hash", "key", "hello")
|
|
|
|
Expect(hSetNX.Err()).NotTo(HaveOccurred())
|
|
|
|
Expect(hSetNX.Val()).To(Equal(false))
|
|
|
|
|
|
|
|
hGet := client.HGet("hash", "key")
|
|
|
|
Expect(hGet.Err()).NotTo(HaveOccurred())
|
|
|
|
Expect(hGet.Val()).To(Equal("hello"))
|
|
|
|
})
|
|
|
|
|
|
|
|
It("should HVals", func() {
|
2017-02-18 13:10:47 +03:00
|
|
|
err := client.HSet("hash", "key1", "hello1").Err()
|
|
|
|
Expect(err).NotTo(HaveOccurred())
|
|
|
|
err = client.HSet("hash", "key2", "hello2").Err()
|
|
|
|
Expect(err).NotTo(HaveOccurred())
|
2015-01-15 18:51:22 +03:00
|
|
|
|
2017-02-18 13:10:47 +03:00
|
|
|
v, err := client.HVals("hash").Result()
|
|
|
|
Expect(err).NotTo(HaveOccurred())
|
|
|
|
Expect(v).To(Equal([]string{"hello1", "hello2"}))
|
|
|
|
|
|
|
|
var slice []string
|
|
|
|
err = client.HVals("hash").ScanSlice(&slice)
|
|
|
|
Expect(err).NotTo(HaveOccurred())
|
|
|
|
Expect(slice).To(Equal([]string{"hello1", "hello2"}))
|
2015-01-15 18:51:22 +03:00
|
|
|
})
|
|
|
|
|
|
|
|
})
|
|
|
|
|
2015-11-04 10:34:58 +03:00
|
|
|
Describe("hyperloglog", func() {
|
|
|
|
It("should PFMerge", func() {
|
|
|
|
pfAdd := client.PFAdd("hll1", "1", "2", "3", "4", "5")
|
|
|
|
Expect(pfAdd.Err()).NotTo(HaveOccurred())
|
|
|
|
|
|
|
|
pfCount := client.PFCount("hll1")
|
|
|
|
Expect(pfCount.Err()).NotTo(HaveOccurred())
|
|
|
|
Expect(pfCount.Val()).To(Equal(int64(5)))
|
|
|
|
|
|
|
|
pfAdd = client.PFAdd("hll2", "a", "b", "c", "d", "e")
|
|
|
|
Expect(pfAdd.Err()).NotTo(HaveOccurred())
|
|
|
|
|
|
|
|
pfMerge := client.PFMerge("hllMerged", "hll1", "hll2")
|
|
|
|
Expect(pfMerge.Err()).NotTo(HaveOccurred())
|
|
|
|
|
|
|
|
pfCount = client.PFCount("hllMerged")
|
|
|
|
Expect(pfCount.Err()).NotTo(HaveOccurred())
|
|
|
|
Expect(pfCount.Val()).To(Equal(int64(10)))
|
2015-12-24 01:24:42 +03:00
|
|
|
|
|
|
|
pfCount = client.PFCount("hll1", "hll2")
|
|
|
|
Expect(pfCount.Err()).NotTo(HaveOccurred())
|
|
|
|
Expect(pfCount.Val()).To(Equal(int64(10)))
|
2015-11-04 10:34:58 +03:00
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2015-01-15 18:51:22 +03:00
|
|
|
Describe("lists", func() {
|
|
|
|
|
|
|
|
It("should BLPop", func() {
|
|
|
|
rPush := client.RPush("list1", "a", "b", "c")
|
|
|
|
Expect(rPush.Err()).NotTo(HaveOccurred())
|
|
|
|
|
|
|
|
bLPop := client.BLPop(0, "list1", "list2")
|
|
|
|
Expect(bLPop.Err()).NotTo(HaveOccurred())
|
|
|
|
Expect(bLPop.Val()).To(Equal([]string{"list1", "a"}))
|
|
|
|
})
|
|
|
|
|
|
|
|
It("should BLPopBlocks", func() {
|
|
|
|
started := make(chan bool)
|
|
|
|
done := make(chan bool)
|
|
|
|
go func() {
|
2015-01-31 16:20:37 +03:00
|
|
|
defer GinkgoRecover()
|
|
|
|
|
2015-01-15 18:51:22 +03:00
|
|
|
started <- true
|
|
|
|
bLPop := client.BLPop(0, "list")
|
|
|
|
Expect(bLPop.Err()).NotTo(HaveOccurred())
|
|
|
|
Expect(bLPop.Val()).To(Equal([]string{"list", "a"}))
|
|
|
|
done <- true
|
|
|
|
}()
|
|
|
|
<-started
|
|
|
|
|
|
|
|
select {
|
|
|
|
case <-done:
|
|
|
|
Fail("BLPop is not blocked")
|
|
|
|
case <-time.After(time.Second):
|
|
|
|
// ok
|
|
|
|
}
|
|
|
|
|
|
|
|
rPush := client.RPush("list", "a")
|
|
|
|
Expect(rPush.Err()).NotTo(HaveOccurred())
|
|
|
|
|
|
|
|
select {
|
|
|
|
case <-done:
|
|
|
|
// ok
|
|
|
|
case <-time.After(time.Second):
|
|
|
|
Fail("BLPop is still blocked")
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
It("should BLPop timeout", func() {
|
2016-03-17 19:00:47 +03:00
|
|
|
val, err := client.BLPop(time.Second, "list1").Result()
|
|
|
|
Expect(err).To(Equal(redis.Nil))
|
|
|
|
Expect(val).To(BeNil())
|
2016-03-09 14:38:33 +03:00
|
|
|
|
2016-03-17 19:00:47 +03:00
|
|
|
Expect(client.Ping().Err()).NotTo(HaveOccurred())
|
|
|
|
|
|
|
|
stats := client.PoolStats()
|
2016-10-02 15:44:01 +03:00
|
|
|
Expect(stats.Hits).To(Equal(uint32(1)))
|
2017-09-22 12:23:46 +03:00
|
|
|
Expect(stats.Misses).To(Equal(uint32(2)))
|
2016-03-17 19:00:47 +03:00
|
|
|
Expect(stats.Timeouts).To(Equal(uint32(0)))
|
2015-01-15 18:51:22 +03:00
|
|
|
})
|
|
|
|
|
|
|
|
It("should BRPop", func() {
|
|
|
|
rPush := client.RPush("list1", "a", "b", "c")
|
|
|
|
Expect(rPush.Err()).NotTo(HaveOccurred())
|
|
|
|
|
|
|
|
bRPop := client.BRPop(0, "list1", "list2")
|
|
|
|
Expect(bRPop.Err()).NotTo(HaveOccurred())
|
|
|
|
Expect(bRPop.Val()).To(Equal([]string{"list1", "c"}))
|
|
|
|
})
|
|
|
|
|
2015-04-07 12:42:16 +03:00
|
|
|
It("should BRPop blocks", func() {
|
2015-01-15 18:51:22 +03:00
|
|
|
started := make(chan bool)
|
|
|
|
done := make(chan bool)
|
|
|
|
go func() {
|
2015-01-31 16:20:37 +03:00
|
|
|
defer GinkgoRecover()
|
|
|
|
|
2015-01-15 18:51:22 +03:00
|
|
|
started <- true
|
|
|
|
brpop := client.BRPop(0, "list")
|
|
|
|
Expect(brpop.Err()).NotTo(HaveOccurred())
|
|
|
|
Expect(brpop.Val()).To(Equal([]string{"list", "a"}))
|
|
|
|
done <- true
|
|
|
|
}()
|
|
|
|
<-started
|
|
|
|
|
|
|
|
select {
|
|
|
|
case <-done:
|
|
|
|
Fail("BRPop is not blocked")
|
|
|
|
case <-time.After(time.Second):
|
|
|
|
// ok
|
|
|
|
}
|
|
|
|
|
|
|
|
rPush := client.RPush("list", "a")
|
|
|
|
Expect(rPush.Err()).NotTo(HaveOccurred())
|
|
|
|
|
|
|
|
select {
|
|
|
|
case <-done:
|
|
|
|
// ok
|
|
|
|
case <-time.After(time.Second):
|
|
|
|
Fail("BRPop is still blocked")
|
|
|
|
// ok
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
It("should BRPopLPush", func() {
|
2015-12-22 12:02:18 +03:00
|
|
|
_, err := client.BRPopLPush("list1", "list2", time.Second).Result()
|
|
|
|
Expect(err).To(Equal(redis.Nil))
|
2015-01-15 18:51:22 +03:00
|
|
|
|
2015-12-22 12:02:18 +03:00
|
|
|
err = client.RPush("list1", "a", "b", "c").Err()
|
|
|
|
Expect(err).NotTo(HaveOccurred())
|
|
|
|
|
|
|
|
v, err := client.BRPopLPush("list1", "list2", 0).Result()
|
|
|
|
Expect(err).NotTo(HaveOccurred())
|
|
|
|
Expect(v).To(Equal("c"))
|
2015-01-15 18:51:22 +03:00
|
|
|
})
|
|
|
|
|
|
|
|
It("should LIndex", func() {
|
|
|
|
lPush := client.LPush("list", "World")
|
|
|
|
Expect(lPush.Err()).NotTo(HaveOccurred())
|
|
|
|
lPush = client.LPush("list", "Hello")
|
|
|
|
Expect(lPush.Err()).NotTo(HaveOccurred())
|
|
|
|
|
|
|
|
lIndex := client.LIndex("list", 0)
|
|
|
|
Expect(lIndex.Err()).NotTo(HaveOccurred())
|
|
|
|
Expect(lIndex.Val()).To(Equal("Hello"))
|
|
|
|
|
|
|
|
lIndex = client.LIndex("list", -1)
|
|
|
|
Expect(lIndex.Err()).NotTo(HaveOccurred())
|
|
|
|
Expect(lIndex.Val()).To(Equal("World"))
|
|
|
|
|
|
|
|
lIndex = client.LIndex("list", 3)
|
|
|
|
Expect(lIndex.Err()).To(Equal(redis.Nil))
|
|
|
|
Expect(lIndex.Val()).To(Equal(""))
|
|
|
|
})
|
|
|
|
|
|
|
|
It("should LInsert", func() {
|
|
|
|
rPush := client.RPush("list", "Hello")
|
|
|
|
Expect(rPush.Err()).NotTo(HaveOccurred())
|
|
|
|
rPush = client.RPush("list", "World")
|
|
|
|
Expect(rPush.Err()).NotTo(HaveOccurred())
|
|
|
|
|
|
|
|
lInsert := client.LInsert("list", "BEFORE", "World", "There")
|
|
|
|
Expect(lInsert.Err()).NotTo(HaveOccurred())
|
|
|
|
Expect(lInsert.Val()).To(Equal(int64(3)))
|
|
|
|
|
|
|
|
lRange := client.LRange("list", 0, -1)
|
|
|
|
Expect(lRange.Err()).NotTo(HaveOccurred())
|
|
|
|
Expect(lRange.Val()).To(Equal([]string{"Hello", "There", "World"}))
|
|
|
|
})
|
|
|
|
|
|
|
|
It("should LLen", func() {
|
|
|
|
lPush := client.LPush("list", "World")
|
|
|
|
Expect(lPush.Err()).NotTo(HaveOccurred())
|
|
|
|
lPush = client.LPush("list", "Hello")
|
|
|
|
Expect(lPush.Err()).NotTo(HaveOccurred())
|
|
|
|
|
|
|
|
lLen := client.LLen("list")
|
|
|
|
Expect(lLen.Err()).NotTo(HaveOccurred())
|
|
|
|
Expect(lLen.Val()).To(Equal(int64(2)))
|
|
|
|
})
|
|
|
|
|
|
|
|
It("should LPop", func() {
|
|
|
|
rPush := client.RPush("list", "one")
|
|
|
|
Expect(rPush.Err()).NotTo(HaveOccurred())
|
|
|
|
rPush = client.RPush("list", "two")
|
|
|
|
Expect(rPush.Err()).NotTo(HaveOccurred())
|
|
|
|
rPush = client.RPush("list", "three")
|
|
|
|
Expect(rPush.Err()).NotTo(HaveOccurred())
|
|
|
|
|
|
|
|
lPop := client.LPop("list")
|
|
|
|
Expect(lPop.Err()).NotTo(HaveOccurred())
|
|
|
|
Expect(lPop.Val()).To(Equal("one"))
|
|
|
|
|
|
|
|
lRange := client.LRange("list", 0, -1)
|
|
|
|
Expect(lRange.Err()).NotTo(HaveOccurred())
|
|
|
|
Expect(lRange.Val()).To(Equal([]string{"two", "three"}))
|
|
|
|
})
|
|
|
|
|
|
|
|
It("should LPush", func() {
|
|
|
|
lPush := client.LPush("list", "World")
|
|
|
|
Expect(lPush.Err()).NotTo(HaveOccurred())
|
|
|
|
lPush = client.LPush("list", "Hello")
|
|
|
|
Expect(lPush.Err()).NotTo(HaveOccurred())
|
|
|
|
|
|
|
|
lRange := client.LRange("list", 0, -1)
|
|
|
|
Expect(lRange.Err()).NotTo(HaveOccurred())
|
|
|
|
Expect(lRange.Val()).To(Equal([]string{"Hello", "World"}))
|
|
|
|
})
|
|
|
|
|
|
|
|
It("should LPushX", func() {
|
|
|
|
lPush := client.LPush("list", "World")
|
|
|
|
Expect(lPush.Err()).NotTo(HaveOccurred())
|
|
|
|
|
|
|
|
lPushX := client.LPushX("list", "Hello")
|
|
|
|
Expect(lPushX.Err()).NotTo(HaveOccurred())
|
|
|
|
Expect(lPushX.Val()).To(Equal(int64(2)))
|
|
|
|
|
|
|
|
lPushX = client.LPushX("list2", "Hello")
|
|
|
|
Expect(lPushX.Err()).NotTo(HaveOccurred())
|
|
|
|
Expect(lPushX.Val()).To(Equal(int64(0)))
|
|
|
|
|
|
|
|
lRange := client.LRange("list", 0, -1)
|
|
|
|
Expect(lRange.Err()).NotTo(HaveOccurred())
|
|
|
|
Expect(lRange.Val()).To(Equal([]string{"Hello", "World"}))
|
|
|
|
|
|
|
|
lRange = client.LRange("list2", 0, -1)
|
|
|
|
Expect(lRange.Err()).NotTo(HaveOccurred())
|
|
|
|
Expect(lRange.Val()).To(Equal([]string{}))
|
|
|
|
})
|
|
|
|
|
|
|
|
It("should LRange", func() {
|
|
|
|
rPush := client.RPush("list", "one")
|
|
|
|
Expect(rPush.Err()).NotTo(HaveOccurred())
|
|
|
|
rPush = client.RPush("list", "two")
|
|
|
|
Expect(rPush.Err()).NotTo(HaveOccurred())
|
|
|
|
rPush = client.RPush("list", "three")
|
|
|
|
Expect(rPush.Err()).NotTo(HaveOccurred())
|
|
|
|
|
|
|
|
lRange := client.LRange("list", 0, 0)
|
|
|
|
Expect(lRange.Err()).NotTo(HaveOccurred())
|
|
|
|
Expect(lRange.Val()).To(Equal([]string{"one"}))
|
|
|
|
|
|
|
|
lRange = client.LRange("list", -3, 2)
|
|
|
|
Expect(lRange.Err()).NotTo(HaveOccurred())
|
|
|
|
Expect(lRange.Val()).To(Equal([]string{"one", "two", "three"}))
|
|
|
|
|
|
|
|
lRange = client.LRange("list", -100, 100)
|
|
|
|
Expect(lRange.Err()).NotTo(HaveOccurred())
|
|
|
|
Expect(lRange.Val()).To(Equal([]string{"one", "two", "three"}))
|
|
|
|
|
|
|
|
lRange = client.LRange("list", 5, 10)
|
|
|
|
Expect(lRange.Err()).NotTo(HaveOccurred())
|
|
|
|
Expect(lRange.Val()).To(Equal([]string{}))
|
|
|
|
})
|
|
|
|
|
|
|
|
It("should LRem", func() {
|
|
|
|
rPush := client.RPush("list", "hello")
|
|
|
|
Expect(rPush.Err()).NotTo(HaveOccurred())
|
|
|
|
rPush = client.RPush("list", "hello")
|
|
|
|
Expect(rPush.Err()).NotTo(HaveOccurred())
|
|
|
|
rPush = client.RPush("list", "key")
|
|
|
|
Expect(rPush.Err()).NotTo(HaveOccurred())
|
|
|
|
rPush = client.RPush("list", "hello")
|
|
|
|
Expect(rPush.Err()).NotTo(HaveOccurred())
|
|
|
|
|
|
|
|
lRem := client.LRem("list", -2, "hello")
|
|
|
|
Expect(lRem.Err()).NotTo(HaveOccurred())
|
|
|
|
Expect(lRem.Val()).To(Equal(int64(2)))
|
|
|
|
|
|
|
|
lRange := client.LRange("list", 0, -1)
|
|
|
|
Expect(lRange.Err()).NotTo(HaveOccurred())
|
|
|
|
Expect(lRange.Val()).To(Equal([]string{"hello", "key"}))
|
|
|
|
})
|
|
|
|
|
|
|
|
It("should LSet", func() {
|
|
|
|
rPush := client.RPush("list", "one")
|
|
|
|
Expect(rPush.Err()).NotTo(HaveOccurred())
|
|
|
|
rPush = client.RPush("list", "two")
|
|
|
|
Expect(rPush.Err()).NotTo(HaveOccurred())
|
|
|
|
rPush = client.RPush("list", "three")
|
|
|
|
Expect(rPush.Err()).NotTo(HaveOccurred())
|
|
|
|
|
|
|
|
lSet := client.LSet("list", 0, "four")
|
|
|
|
Expect(lSet.Err()).NotTo(HaveOccurred())
|
|
|
|
Expect(lSet.Val()).To(Equal("OK"))
|
|
|
|
|
|
|
|
lSet = client.LSet("list", -2, "five")
|
|
|
|
Expect(lSet.Err()).NotTo(HaveOccurred())
|
|
|
|
Expect(lSet.Val()).To(Equal("OK"))
|
|
|
|
|
|
|
|
lRange := client.LRange("list", 0, -1)
|
|
|
|
Expect(lRange.Err()).NotTo(HaveOccurred())
|
|
|
|
Expect(lRange.Val()).To(Equal([]string{"four", "five", "three"}))
|
|
|
|
})
|
|
|
|
|
|
|
|
It("should LTrim", func() {
|
|
|
|
rPush := client.RPush("list", "one")
|
|
|
|
Expect(rPush.Err()).NotTo(HaveOccurred())
|
|
|
|
rPush = client.RPush("list", "two")
|
|
|
|
Expect(rPush.Err()).NotTo(HaveOccurred())
|
|
|
|
rPush = client.RPush("list", "three")
|
|
|
|
Expect(rPush.Err()).NotTo(HaveOccurred())
|
|
|
|
|
|
|
|
lTrim := client.LTrim("list", 1, -1)
|
|
|
|
Expect(lTrim.Err()).NotTo(HaveOccurred())
|
|
|
|
Expect(lTrim.Val()).To(Equal("OK"))
|
|
|
|
|
|
|
|
lRange := client.LRange("list", 0, -1)
|
|
|
|
Expect(lRange.Err()).NotTo(HaveOccurred())
|
|
|
|
Expect(lRange.Val()).To(Equal([]string{"two", "three"}))
|
|
|
|
})
|
|
|
|
|
|
|
|
It("should RPop", func() {
|
|
|
|
rPush := client.RPush("list", "one")
|
|
|
|
Expect(rPush.Err()).NotTo(HaveOccurred())
|
|
|
|
rPush = client.RPush("list", "two")
|
|
|
|
Expect(rPush.Err()).NotTo(HaveOccurred())
|
|
|
|
rPush = client.RPush("list", "three")
|
|
|
|
Expect(rPush.Err()).NotTo(HaveOccurred())
|
|
|
|
|
|
|
|
rPop := client.RPop("list")
|
|
|
|
Expect(rPop.Err()).NotTo(HaveOccurred())
|
|
|
|
Expect(rPop.Val()).To(Equal("three"))
|
|
|
|
|
|
|
|
lRange := client.LRange("list", 0, -1)
|
|
|
|
Expect(lRange.Err()).NotTo(HaveOccurred())
|
|
|
|
Expect(lRange.Val()).To(Equal([]string{"one", "two"}))
|
|
|
|
})
|
|
|
|
|
|
|
|
It("should RPopLPush", func() {
|
|
|
|
rPush := client.RPush("list", "one")
|
|
|
|
Expect(rPush.Err()).NotTo(HaveOccurred())
|
|
|
|
rPush = client.RPush("list", "two")
|
|
|
|
Expect(rPush.Err()).NotTo(HaveOccurred())
|
|
|
|
rPush = client.RPush("list", "three")
|
|
|
|
Expect(rPush.Err()).NotTo(HaveOccurred())
|
|
|
|
|
|
|
|
rPopLPush := client.RPopLPush("list", "list2")
|
|
|
|
Expect(rPopLPush.Err()).NotTo(HaveOccurred())
|
|
|
|
Expect(rPopLPush.Val()).To(Equal("three"))
|
|
|
|
|
|
|
|
lRange := client.LRange("list", 0, -1)
|
|
|
|
Expect(lRange.Err()).NotTo(HaveOccurred())
|
|
|
|
Expect(lRange.Val()).To(Equal([]string{"one", "two"}))
|
|
|
|
|
|
|
|
lRange = client.LRange("list2", 0, -1)
|
|
|
|
Expect(lRange.Err()).NotTo(HaveOccurred())
|
|
|
|
Expect(lRange.Val()).To(Equal([]string{"three"}))
|
|
|
|
})
|
|
|
|
|
|
|
|
It("should RPush", func() {
|
|
|
|
rPush := client.RPush("list", "Hello")
|
|
|
|
Expect(rPush.Err()).NotTo(HaveOccurred())
|
|
|
|
Expect(rPush.Val()).To(Equal(int64(1)))
|
|
|
|
|
|
|
|
rPush = client.RPush("list", "World")
|
|
|
|
Expect(rPush.Err()).NotTo(HaveOccurred())
|
|
|
|
Expect(rPush.Val()).To(Equal(int64(2)))
|
|
|
|
|
|
|
|
lRange := client.LRange("list", 0, -1)
|
|
|
|
Expect(lRange.Err()).NotTo(HaveOccurred())
|
|
|
|
Expect(lRange.Val()).To(Equal([]string{"Hello", "World"}))
|
|
|
|
})
|
|
|
|
|
|
|
|
It("should RPushX", func() {
|
|
|
|
rPush := client.RPush("list", "Hello")
|
|
|
|
Expect(rPush.Err()).NotTo(HaveOccurred())
|
|
|
|
Expect(rPush.Val()).To(Equal(int64(1)))
|
|
|
|
|
|
|
|
rPushX := client.RPushX("list", "World")
|
|
|
|
Expect(rPushX.Err()).NotTo(HaveOccurred())
|
|
|
|
Expect(rPushX.Val()).To(Equal(int64(2)))
|
|
|
|
|
|
|
|
rPushX = client.RPushX("list2", "World")
|
|
|
|
Expect(rPushX.Err()).NotTo(HaveOccurred())
|
|
|
|
Expect(rPushX.Val()).To(Equal(int64(0)))
|
|
|
|
|
|
|
|
lRange := client.LRange("list", 0, -1)
|
|
|
|
Expect(lRange.Err()).NotTo(HaveOccurred())
|
|
|
|
Expect(lRange.Val()).To(Equal([]string{"Hello", "World"}))
|
|
|
|
|
|
|
|
lRange = client.LRange("list2", 0, -1)
|
|
|
|
Expect(lRange.Err()).NotTo(HaveOccurred())
|
|
|
|
Expect(lRange.Val()).To(Equal([]string{}))
|
|
|
|
})
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
Describe("sets", func() {
|
|
|
|
|
|
|
|
It("should SAdd", func() {
|
|
|
|
sAdd := client.SAdd("set", "Hello")
|
|
|
|
Expect(sAdd.Err()).NotTo(HaveOccurred())
|
|
|
|
Expect(sAdd.Val()).To(Equal(int64(1)))
|
|
|
|
|
|
|
|
sAdd = client.SAdd("set", "World")
|
|
|
|
Expect(sAdd.Err()).NotTo(HaveOccurred())
|
|
|
|
Expect(sAdd.Val()).To(Equal(int64(1)))
|
|
|
|
|
|
|
|
sAdd = client.SAdd("set", "World")
|
|
|
|
Expect(sAdd.Err()).NotTo(HaveOccurred())
|
|
|
|
Expect(sAdd.Val()).To(Equal(int64(0)))
|
|
|
|
|
|
|
|
sMembers := client.SMembers("set")
|
2018-03-08 15:30:27 +03:00
|
|
|
Expect(sMembers.Err()).NotTo(HaveOccurred())
|
|
|
|
Expect(sMembers.Val()).To(ConsistOf([]string{"Hello", "World"}))
|
|
|
|
})
|
|
|
|
|
|
|
|
It("should SAdd strings", func() {
|
|
|
|
set := []string{"Hello", "World", "World"}
|
|
|
|
sAdd := client.SAdd("set", set)
|
|
|
|
Expect(sAdd.Err()).NotTo(HaveOccurred())
|
|
|
|
Expect(sAdd.Val()).To(Equal(int64(2)))
|
|
|
|
|
|
|
|
sMembers := client.SMembers("set")
|
2015-01-15 18:51:22 +03:00
|
|
|
Expect(sMembers.Err()).NotTo(HaveOccurred())
|
2015-02-09 11:14:41 +03:00
|
|
|
Expect(sMembers.Val()).To(ConsistOf([]string{"Hello", "World"}))
|
2015-01-15 18:51:22 +03:00
|
|
|
})
|
|
|
|
|
|
|
|
It("should SCard", func() {
|
|
|
|
sAdd := client.SAdd("set", "Hello")
|
|
|
|
Expect(sAdd.Err()).NotTo(HaveOccurred())
|
|
|
|
Expect(sAdd.Val()).To(Equal(int64(1)))
|
|
|
|
|
|
|
|
sAdd = client.SAdd("set", "World")
|
|
|
|
Expect(sAdd.Err()).NotTo(HaveOccurred())
|
|
|
|
Expect(sAdd.Val()).To(Equal(int64(1)))
|
|
|
|
|
|
|
|
sCard := client.SCard("set")
|
|
|
|
Expect(sCard.Err()).NotTo(HaveOccurred())
|
|
|
|
Expect(sCard.Val()).To(Equal(int64(2)))
|
|
|
|
})
|
|
|
|
|
|
|
|
It("should SDiff", func() {
|
|
|
|
sAdd := client.SAdd("set1", "a")
|
|
|
|
Expect(sAdd.Err()).NotTo(HaveOccurred())
|
|
|
|
sAdd = client.SAdd("set1", "b")
|
|
|
|
Expect(sAdd.Err()).NotTo(HaveOccurred())
|
|
|
|
sAdd = client.SAdd("set1", "c")
|
|
|
|
Expect(sAdd.Err()).NotTo(HaveOccurred())
|
|
|
|
|
|
|
|
sAdd = client.SAdd("set2", "c")
|
|
|
|
Expect(sAdd.Err()).NotTo(HaveOccurred())
|
|
|
|
sAdd = client.SAdd("set2", "d")
|
|
|
|
Expect(sAdd.Err()).NotTo(HaveOccurred())
|
|
|
|
sAdd = client.SAdd("set2", "e")
|
|
|
|
Expect(sAdd.Err()).NotTo(HaveOccurred())
|
|
|
|
|
|
|
|
sDiff := client.SDiff("set1", "set2")
|
|
|
|
Expect(sDiff.Err()).NotTo(HaveOccurred())
|
2015-02-09 11:14:41 +03:00
|
|
|
Expect(sDiff.Val()).To(ConsistOf([]string{"a", "b"}))
|
2015-01-15 18:51:22 +03:00
|
|
|
})
|
|
|
|
|
|
|
|
It("should SDiffStore", func() {
|
|
|
|
sAdd := client.SAdd("set1", "a")
|
|
|
|
Expect(sAdd.Err()).NotTo(HaveOccurred())
|
|
|
|
sAdd = client.SAdd("set1", "b")
|
|
|
|
Expect(sAdd.Err()).NotTo(HaveOccurred())
|
|
|
|
sAdd = client.SAdd("set1", "c")
|
|
|
|
Expect(sAdd.Err()).NotTo(HaveOccurred())
|
|
|
|
|
|
|
|
sAdd = client.SAdd("set2", "c")
|
|
|
|
Expect(sAdd.Err()).NotTo(HaveOccurred())
|
|
|
|
sAdd = client.SAdd("set2", "d")
|
|
|
|
Expect(sAdd.Err()).NotTo(HaveOccurred())
|
|
|
|
sAdd = client.SAdd("set2", "e")
|
|
|
|
Expect(sAdd.Err()).NotTo(HaveOccurred())
|
|
|
|
|
|
|
|
sDiffStore := client.SDiffStore("set", "set1", "set2")
|
|
|
|
Expect(sDiffStore.Err()).NotTo(HaveOccurred())
|
|
|
|
Expect(sDiffStore.Val()).To(Equal(int64(2)))
|
|
|
|
|
|
|
|
sMembers := client.SMembers("set")
|
|
|
|
Expect(sMembers.Err()).NotTo(HaveOccurred())
|
2015-02-09 11:14:41 +03:00
|
|
|
Expect(sMembers.Val()).To(ConsistOf([]string{"a", "b"}))
|
2015-01-15 18:51:22 +03:00
|
|
|
})
|
|
|
|
|
|
|
|
It("should SInter", func() {
|
|
|
|
sAdd := client.SAdd("set1", "a")
|
|
|
|
Expect(sAdd.Err()).NotTo(HaveOccurred())
|
|
|
|
sAdd = client.SAdd("set1", "b")
|
|
|
|
Expect(sAdd.Err()).NotTo(HaveOccurred())
|
|
|
|
sAdd = client.SAdd("set1", "c")
|
|
|
|
Expect(sAdd.Err()).NotTo(HaveOccurred())
|
|
|
|
|
|
|
|
sAdd = client.SAdd("set2", "c")
|
|
|
|
Expect(sAdd.Err()).NotTo(HaveOccurred())
|
|
|
|
sAdd = client.SAdd("set2", "d")
|
|
|
|
Expect(sAdd.Err()).NotTo(HaveOccurred())
|
|
|
|
sAdd = client.SAdd("set2", "e")
|
|
|
|
Expect(sAdd.Err()).NotTo(HaveOccurred())
|
|
|
|
|
|
|
|
sInter := client.SInter("set1", "set2")
|
|
|
|
Expect(sInter.Err()).NotTo(HaveOccurred())
|
|
|
|
Expect(sInter.Val()).To(Equal([]string{"c"}))
|
|
|
|
})
|
|
|
|
|
|
|
|
It("should SInterStore", func() {
|
|
|
|
sAdd := client.SAdd("set1", "a")
|
|
|
|
Expect(sAdd.Err()).NotTo(HaveOccurred())
|
|
|
|
sAdd = client.SAdd("set1", "b")
|
|
|
|
Expect(sAdd.Err()).NotTo(HaveOccurred())
|
|
|
|
sAdd = client.SAdd("set1", "c")
|
|
|
|
Expect(sAdd.Err()).NotTo(HaveOccurred())
|
|
|
|
|
|
|
|
sAdd = client.SAdd("set2", "c")
|
|
|
|
Expect(sAdd.Err()).NotTo(HaveOccurred())
|
|
|
|
sAdd = client.SAdd("set2", "d")
|
|
|
|
Expect(sAdd.Err()).NotTo(HaveOccurred())
|
|
|
|
sAdd = client.SAdd("set2", "e")
|
|
|
|
Expect(sAdd.Err()).NotTo(HaveOccurred())
|
|
|
|
|
|
|
|
sInterStore := client.SInterStore("set", "set1", "set2")
|
|
|
|
Expect(sInterStore.Err()).NotTo(HaveOccurred())
|
|
|
|
Expect(sInterStore.Val()).To(Equal(int64(1)))
|
|
|
|
|
|
|
|
sMembers := client.SMembers("set")
|
|
|
|
Expect(sMembers.Err()).NotTo(HaveOccurred())
|
|
|
|
Expect(sMembers.Val()).To(Equal([]string{"c"}))
|
|
|
|
})
|
|
|
|
|
|
|
|
It("should IsMember", func() {
|
|
|
|
sAdd := client.SAdd("set", "one")
|
|
|
|
Expect(sAdd.Err()).NotTo(HaveOccurred())
|
|
|
|
|
|
|
|
sIsMember := client.SIsMember("set", "one")
|
|
|
|
Expect(sIsMember.Err()).NotTo(HaveOccurred())
|
|
|
|
Expect(sIsMember.Val()).To(Equal(true))
|
|
|
|
|
|
|
|
sIsMember = client.SIsMember("set", "two")
|
|
|
|
Expect(sIsMember.Err()).NotTo(HaveOccurred())
|
|
|
|
Expect(sIsMember.Val()).To(Equal(false))
|
|
|
|
})
|
|
|
|
|
|
|
|
It("should SMembers", func() {
|
|
|
|
sAdd := client.SAdd("set", "Hello")
|
|
|
|
Expect(sAdd.Err()).NotTo(HaveOccurred())
|
|
|
|
sAdd = client.SAdd("set", "World")
|
|
|
|
Expect(sAdd.Err()).NotTo(HaveOccurred())
|
|
|
|
|
|
|
|
sMembers := client.SMembers("set")
|
|
|
|
Expect(sMembers.Err()).NotTo(HaveOccurred())
|
2015-02-09 11:14:41 +03:00
|
|
|
Expect(sMembers.Val()).To(ConsistOf([]string{"Hello", "World"}))
|
2015-01-15 18:51:22 +03:00
|
|
|
})
|
|
|
|
|
2017-11-19 19:36:23 +03:00
|
|
|
It("should SMembersMap", func() {
|
|
|
|
sAdd := client.SAdd("set", "Hello")
|
|
|
|
Expect(sAdd.Err()).NotTo(HaveOccurred())
|
|
|
|
sAdd = client.SAdd("set", "World")
|
|
|
|
Expect(sAdd.Err()).NotTo(HaveOccurred())
|
|
|
|
|
|
|
|
sMembersMap := client.SMembersMap("set")
|
|
|
|
Expect(sMembersMap.Err()).NotTo(HaveOccurred())
|
2018-10-11 13:54:30 +03:00
|
|
|
Expect(sMembersMap.Val()).To(Equal(map[string]struct{}{"Hello": {}, "World": {}}))
|
2017-11-19 19:36:23 +03:00
|
|
|
})
|
|
|
|
|
2015-01-15 18:51:22 +03:00
|
|
|
It("should SMove", func() {
|
|
|
|
sAdd := client.SAdd("set1", "one")
|
|
|
|
Expect(sAdd.Err()).NotTo(HaveOccurred())
|
|
|
|
sAdd = client.SAdd("set1", "two")
|
|
|
|
Expect(sAdd.Err()).NotTo(HaveOccurred())
|
|
|
|
|
|
|
|
sAdd = client.SAdd("set2", "three")
|
|
|
|
Expect(sAdd.Err()).NotTo(HaveOccurred())
|
|
|
|
|
|
|
|
sMove := client.SMove("set1", "set2", "two")
|
|
|
|
Expect(sMove.Err()).NotTo(HaveOccurred())
|
|
|
|
Expect(sMove.Val()).To(Equal(true))
|
|
|
|
|
|
|
|
sMembers := client.SMembers("set1")
|
|
|
|
Expect(sMembers.Err()).NotTo(HaveOccurred())
|
|
|
|
Expect(sMembers.Val()).To(Equal([]string{"one"}))
|
|
|
|
|
|
|
|
sMembers = client.SMembers("set2")
|
|
|
|
Expect(sMembers.Err()).NotTo(HaveOccurred())
|
2015-02-09 11:14:41 +03:00
|
|
|
Expect(sMembers.Val()).To(ConsistOf([]string{"three", "two"}))
|
2015-01-15 18:51:22 +03:00
|
|
|
})
|
|
|
|
|
|
|
|
It("should SPop", func() {
|
|
|
|
sAdd := client.SAdd("set", "one")
|
|
|
|
Expect(sAdd.Err()).NotTo(HaveOccurred())
|
|
|
|
sAdd = client.SAdd("set", "two")
|
|
|
|
Expect(sAdd.Err()).NotTo(HaveOccurred())
|
|
|
|
sAdd = client.SAdd("set", "three")
|
|
|
|
Expect(sAdd.Err()).NotTo(HaveOccurred())
|
|
|
|
|
|
|
|
sPop := client.SPop("set")
|
|
|
|
Expect(sPop.Err()).NotTo(HaveOccurred())
|
|
|
|
Expect(sPop.Val()).NotTo(Equal(""))
|
|
|
|
|
|
|
|
sMembers := client.SMembers("set")
|
|
|
|
Expect(sMembers.Err()).NotTo(HaveOccurred())
|
|
|
|
Expect(sMembers.Val()).To(HaveLen(2))
|
2016-06-09 18:39:51 +03:00
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
It("should SPopN", func() {
|
|
|
|
sAdd := client.SAdd("set", "one")
|
|
|
|
Expect(sAdd.Err()).NotTo(HaveOccurred())
|
|
|
|
sAdd = client.SAdd("set", "two")
|
|
|
|
Expect(sAdd.Err()).NotTo(HaveOccurred())
|
|
|
|
sAdd = client.SAdd("set", "three")
|
|
|
|
Expect(sAdd.Err()).NotTo(HaveOccurred())
|
|
|
|
sAdd = client.SAdd("set", "four")
|
|
|
|
Expect(sAdd.Err()).NotTo(HaveOccurred())
|
|
|
|
|
|
|
|
sPopN := client.SPopN("set", 1)
|
|
|
|
Expect(sPopN.Err()).NotTo(HaveOccurred())
|
|
|
|
Expect(sPopN.Val()).NotTo(Equal([]string{""}))
|
|
|
|
|
|
|
|
sMembers := client.SMembers("set")
|
|
|
|
Expect(sMembers.Err()).NotTo(HaveOccurred())
|
|
|
|
Expect(sMembers.Val()).To(HaveLen(3))
|
|
|
|
|
|
|
|
sPopN = client.SPopN("set", 4)
|
|
|
|
Expect(sPopN.Err()).NotTo(HaveOccurred())
|
|
|
|
Expect(sPopN.Val()).To(HaveLen(3))
|
|
|
|
|
|
|
|
sMembers = client.SMembers("set")
|
|
|
|
Expect(sMembers.Err()).NotTo(HaveOccurred())
|
|
|
|
Expect(sMembers.Val()).To(HaveLen(0))
|
2015-01-15 18:51:22 +03:00
|
|
|
})
|
|
|
|
|
2015-08-25 14:02:16 +03:00
|
|
|
It("should SRandMember and SRandMemberN", func() {
|
|
|
|
err := client.SAdd("set", "one").Err()
|
|
|
|
Expect(err).NotTo(HaveOccurred())
|
|
|
|
err = client.SAdd("set", "two").Err()
|
|
|
|
Expect(err).NotTo(HaveOccurred())
|
|
|
|
err = client.SAdd("set", "three").Err()
|
|
|
|
Expect(err).NotTo(HaveOccurred())
|
2015-01-15 18:51:22 +03:00
|
|
|
|
2015-08-25 14:02:16 +03:00
|
|
|
members, err := client.SMembers("set").Result()
|
|
|
|
Expect(err).NotTo(HaveOccurred())
|
|
|
|
Expect(members).To(HaveLen(3))
|
2015-01-15 18:51:22 +03:00
|
|
|
|
2015-08-25 14:02:16 +03:00
|
|
|
member, err := client.SRandMember("set").Result()
|
|
|
|
Expect(err).NotTo(HaveOccurred())
|
|
|
|
Expect(member).NotTo(Equal(""))
|
|
|
|
|
|
|
|
members, err = client.SRandMemberN("set", 2).Result()
|
|
|
|
Expect(err).NotTo(HaveOccurred())
|
|
|
|
Expect(members).To(HaveLen(2))
|
2015-01-15 18:51:22 +03:00
|
|
|
})
|
|
|
|
|
|
|
|
It("should SRem", func() {
|
|
|
|
sAdd := client.SAdd("set", "one")
|
|
|
|
Expect(sAdd.Err()).NotTo(HaveOccurred())
|
|
|
|
sAdd = client.SAdd("set", "two")
|
|
|
|
Expect(sAdd.Err()).NotTo(HaveOccurred())
|
|
|
|
sAdd = client.SAdd("set", "three")
|
|
|
|
Expect(sAdd.Err()).NotTo(HaveOccurred())
|
|
|
|
|
|
|
|
sRem := client.SRem("set", "one")
|
|
|
|
Expect(sRem.Err()).NotTo(HaveOccurred())
|
|
|
|
Expect(sRem.Val()).To(Equal(int64(1)))
|
|
|
|
|
|
|
|
sRem = client.SRem("set", "four")
|
|
|
|
Expect(sRem.Err()).NotTo(HaveOccurred())
|
|
|
|
Expect(sRem.Val()).To(Equal(int64(0)))
|
|
|
|
|
|
|
|
sMembers := client.SMembers("set")
|
|
|
|
Expect(sMembers.Err()).NotTo(HaveOccurred())
|
2015-02-09 11:14:41 +03:00
|
|
|
Expect(sMembers.Val()).To(ConsistOf([]string{"three", "two"}))
|
2015-01-15 18:51:22 +03:00
|
|
|
})
|
|
|
|
|
|
|
|
It("should SUnion", func() {
|
|
|
|
sAdd := client.SAdd("set1", "a")
|
|
|
|
Expect(sAdd.Err()).NotTo(HaveOccurred())
|
|
|
|
sAdd = client.SAdd("set1", "b")
|
|
|
|
Expect(sAdd.Err()).NotTo(HaveOccurred())
|
|
|
|
sAdd = client.SAdd("set1", "c")
|
|
|
|
Expect(sAdd.Err()).NotTo(HaveOccurred())
|
|
|
|
|
|
|
|
sAdd = client.SAdd("set2", "c")
|
|
|
|
Expect(sAdd.Err()).NotTo(HaveOccurred())
|
|
|
|
sAdd = client.SAdd("set2", "d")
|
|
|
|
Expect(sAdd.Err()).NotTo(HaveOccurred())
|
|
|
|
sAdd = client.SAdd("set2", "e")
|
|
|
|
Expect(sAdd.Err()).NotTo(HaveOccurred())
|
|
|
|
|
|
|
|
sUnion := client.SUnion("set1", "set2")
|
|
|
|
Expect(sUnion.Err()).NotTo(HaveOccurred())
|
|
|
|
Expect(sUnion.Val()).To(HaveLen(5))
|
|
|
|
})
|
|
|
|
|
|
|
|
It("should SUnionStore", func() {
|
|
|
|
sAdd := client.SAdd("set1", "a")
|
|
|
|
Expect(sAdd.Err()).NotTo(HaveOccurred())
|
|
|
|
sAdd = client.SAdd("set1", "b")
|
|
|
|
Expect(sAdd.Err()).NotTo(HaveOccurred())
|
|
|
|
sAdd = client.SAdd("set1", "c")
|
|
|
|
Expect(sAdd.Err()).NotTo(HaveOccurred())
|
|
|
|
|
|
|
|
sAdd = client.SAdd("set2", "c")
|
|
|
|
Expect(sAdd.Err()).NotTo(HaveOccurred())
|
|
|
|
sAdd = client.SAdd("set2", "d")
|
|
|
|
Expect(sAdd.Err()).NotTo(HaveOccurred())
|
|
|
|
sAdd = client.SAdd("set2", "e")
|
|
|
|
Expect(sAdd.Err()).NotTo(HaveOccurred())
|
|
|
|
|
|
|
|
sUnionStore := client.SUnionStore("set", "set1", "set2")
|
|
|
|
Expect(sUnionStore.Err()).NotTo(HaveOccurred())
|
|
|
|
Expect(sUnionStore.Val()).To(Equal(int64(5)))
|
|
|
|
|
|
|
|
sMembers := client.SMembers("set")
|
|
|
|
Expect(sMembers.Err()).NotTo(HaveOccurred())
|
|
|
|
Expect(sMembers.Val()).To(HaveLen(5))
|
|
|
|
})
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
Describe("sorted sets", func() {
|
|
|
|
|
2018-10-31 16:35:23 +03:00
|
|
|
It("should BZPopMax", func() {
|
|
|
|
err := client.ZAdd("zset1", redis.Z{
|
|
|
|
Score: 1,
|
|
|
|
Member: "one",
|
|
|
|
}).Err()
|
|
|
|
Expect(err).NotTo(HaveOccurred())
|
|
|
|
err = client.ZAdd("zset1", redis.Z{
|
|
|
|
Score: 2,
|
|
|
|
Member: "two",
|
|
|
|
}).Err()
|
|
|
|
Expect(err).NotTo(HaveOccurred())
|
|
|
|
err = client.ZAdd("zset1", redis.Z{
|
|
|
|
Score: 3,
|
|
|
|
Member: "three",
|
|
|
|
}).Err()
|
|
|
|
Expect(err).NotTo(HaveOccurred())
|
|
|
|
|
|
|
|
member, err := client.BZPopMax(0, "zset1", "zset2").Result()
|
|
|
|
Expect(err).NotTo(HaveOccurred())
|
|
|
|
Expect(member).To(Equal(redis.ZWithKey{
|
2018-11-03 13:07:25 +03:00
|
|
|
Z: redis.Z{
|
|
|
|
Score: 3,
|
|
|
|
Member: "three",
|
|
|
|
},
|
|
|
|
Key: "zset1",
|
2018-10-31 16:35:23 +03:00
|
|
|
}))
|
|
|
|
})
|
|
|
|
|
|
|
|
It("should BZPopMax blocks", func() {
|
|
|
|
started := make(chan bool)
|
|
|
|
done := make(chan bool)
|
|
|
|
go func() {
|
|
|
|
defer GinkgoRecover()
|
|
|
|
|
|
|
|
started <- true
|
|
|
|
bZPopMax := client.BZPopMax(0, "zset")
|
|
|
|
Expect(bZPopMax.Err()).NotTo(HaveOccurred())
|
|
|
|
Expect(bZPopMax.Val()).To(Equal(redis.ZWithKey{
|
2018-11-03 13:07:25 +03:00
|
|
|
Z: redis.Z{
|
|
|
|
Member: "a",
|
|
|
|
Score: 1,
|
|
|
|
},
|
|
|
|
Key: "zset",
|
2018-10-31 16:35:23 +03:00
|
|
|
}))
|
|
|
|
done <- true
|
|
|
|
}()
|
|
|
|
<-started
|
|
|
|
|
|
|
|
select {
|
|
|
|
case <-done:
|
|
|
|
Fail("BZPopMax is not blocked")
|
|
|
|
case <-time.After(time.Second):
|
|
|
|
// ok
|
|
|
|
}
|
|
|
|
|
|
|
|
zAdd := client.ZAdd("zset", redis.Z{
|
|
|
|
Member: "a",
|
|
|
|
Score: 1,
|
|
|
|
})
|
|
|
|
Expect(zAdd.Err()).NotTo(HaveOccurred())
|
|
|
|
|
|
|
|
select {
|
|
|
|
case <-done:
|
|
|
|
// ok
|
|
|
|
case <-time.After(time.Second):
|
|
|
|
Fail("BZPopMax is still blocked")
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
It("should BZPopMax timeout", func() {
|
|
|
|
val, err := client.BZPopMax(time.Second, "zset1").Result()
|
|
|
|
Expect(err).To(Equal(redis.Nil))
|
|
|
|
Expect(val).To(Equal(redis.ZWithKey{}))
|
|
|
|
|
|
|
|
Expect(client.Ping().Err()).NotTo(HaveOccurred())
|
|
|
|
|
|
|
|
stats := client.PoolStats()
|
|
|
|
Expect(stats.Hits).To(Equal(uint32(1)))
|
|
|
|
Expect(stats.Misses).To(Equal(uint32(2)))
|
|
|
|
Expect(stats.Timeouts).To(Equal(uint32(0)))
|
|
|
|
})
|
|
|
|
|
|
|
|
It("should BZPopMin", func() {
|
|
|
|
err := client.ZAdd("zset1", redis.Z{
|
|
|
|
Score: 1,
|
|
|
|
Member: "one",
|
|
|
|
}).Err()
|
|
|
|
Expect(err).NotTo(HaveOccurred())
|
|
|
|
err = client.ZAdd("zset1", redis.Z{
|
|
|
|
Score: 2,
|
|
|
|
Member: "two",
|
|
|
|
}).Err()
|
|
|
|
Expect(err).NotTo(HaveOccurred())
|
|
|
|
err = client.ZAdd("zset1", redis.Z{
|
|
|
|
Score: 3,
|
|
|
|
Member: "three",
|
|
|
|
}).Err()
|
|
|
|
Expect(err).NotTo(HaveOccurred())
|
|
|
|
|
|
|
|
member, err := client.BZPopMin(0, "zset1", "zset2").Result()
|
|
|
|
Expect(err).NotTo(HaveOccurred())
|
|
|
|
Expect(member).To(Equal(redis.ZWithKey{
|
2018-11-03 13:07:25 +03:00
|
|
|
Z: redis.Z{
|
|
|
|
Score: 1,
|
|
|
|
Member: "one",
|
|
|
|
},
|
|
|
|
Key: "zset1",
|
2018-10-31 16:35:23 +03:00
|
|
|
}))
|
|
|
|
})
|
|
|
|
|
|
|
|
It("should BZPopMin blocks", func() {
|
|
|
|
started := make(chan bool)
|
|
|
|
done := make(chan bool)
|
|
|
|
go func() {
|
|
|
|
defer GinkgoRecover()
|
|
|
|
|
|
|
|
started <- true
|
|
|
|
bZPopMin := client.BZPopMin(0, "zset")
|
|
|
|
Expect(bZPopMin.Err()).NotTo(HaveOccurred())
|
|
|
|
Expect(bZPopMin.Val()).To(Equal(redis.ZWithKey{
|
2018-11-03 13:07:25 +03:00
|
|
|
Z: redis.Z{
|
|
|
|
Member: "a",
|
|
|
|
Score: 1,
|
|
|
|
},
|
|
|
|
Key: "zset",
|
2018-10-31 16:35:23 +03:00
|
|
|
}))
|
|
|
|
done <- true
|
|
|
|
}()
|
|
|
|
<-started
|
|
|
|
|
|
|
|
select {
|
|
|
|
case <-done:
|
|
|
|
Fail("BZPopMin is not blocked")
|
|
|
|
case <-time.After(time.Second):
|
|
|
|
// ok
|
|
|
|
}
|
|
|
|
|
|
|
|
zAdd := client.ZAdd("zset", redis.Z{
|
|
|
|
Member: "a",
|
|
|
|
Score: 1,
|
|
|
|
})
|
|
|
|
Expect(zAdd.Err()).NotTo(HaveOccurred())
|
|
|
|
|
|
|
|
select {
|
|
|
|
case <-done:
|
|
|
|
// ok
|
|
|
|
case <-time.After(time.Second):
|
|
|
|
Fail("BZPopMin is still blocked")
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
It("should BZPopMin timeout", func() {
|
|
|
|
val, err := client.BZPopMin(time.Second, "zset1").Result()
|
|
|
|
Expect(err).To(Equal(redis.Nil))
|
|
|
|
Expect(val).To(Equal(redis.ZWithKey{}))
|
|
|
|
|
|
|
|
Expect(client.Ping().Err()).NotTo(HaveOccurred())
|
|
|
|
|
|
|
|
stats := client.PoolStats()
|
|
|
|
Expect(stats.Hits).To(Equal(uint32(1)))
|
|
|
|
Expect(stats.Misses).To(Equal(uint32(2)))
|
|
|
|
Expect(stats.Timeouts).To(Equal(uint32(0)))
|
|
|
|
})
|
|
|
|
|
2015-01-15 18:51:22 +03:00
|
|
|
It("should ZAdd", func() {
|
2018-03-07 12:56:24 +03:00
|
|
|
added, err := client.ZAdd("zset", redis.Z{
|
|
|
|
Score: 1,
|
|
|
|
Member: "one",
|
|
|
|
}).Result()
|
2015-07-16 17:30:16 +03:00
|
|
|
Expect(err).NotTo(HaveOccurred())
|
|
|
|
Expect(added).To(Equal(int64(1)))
|
2015-01-15 18:51:22 +03:00
|
|
|
|
2018-03-07 12:56:24 +03:00
|
|
|
added, err = client.ZAdd("zset", redis.Z{
|
|
|
|
Score: 1,
|
|
|
|
Member: "uno",
|
|
|
|
}).Result()
|
2015-07-16 17:30:16 +03:00
|
|
|
Expect(err).NotTo(HaveOccurred())
|
|
|
|
Expect(added).To(Equal(int64(1)))
|
2015-01-15 18:51:22 +03:00
|
|
|
|
2018-03-07 12:56:24 +03:00
|
|
|
added, err = client.ZAdd("zset", redis.Z{
|
|
|
|
Score: 2,
|
|
|
|
Member: "two",
|
|
|
|
}).Result()
|
2015-07-16 17:30:16 +03:00
|
|
|
Expect(err).NotTo(HaveOccurred())
|
|
|
|
Expect(added).To(Equal(int64(1)))
|
2015-01-15 18:51:22 +03:00
|
|
|
|
2018-03-07 12:56:24 +03:00
|
|
|
added, err = client.ZAdd("zset", redis.Z{
|
|
|
|
Score: 3,
|
|
|
|
Member: "two",
|
|
|
|
}).Result()
|
2015-07-16 17:30:16 +03:00
|
|
|
Expect(err).NotTo(HaveOccurred())
|
|
|
|
Expect(added).To(Equal(int64(0)))
|
|
|
|
|
2015-08-29 13:08:27 +03:00
|
|
|
vals, err := client.ZRangeWithScores("zset", 0, -1).Result()
|
2015-07-16 17:30:16 +03:00
|
|
|
Expect(err).NotTo(HaveOccurred())
|
2018-03-07 12:56:24 +03:00
|
|
|
Expect(vals).To(Equal([]redis.Z{{
|
|
|
|
Score: 1,
|
|
|
|
Member: "one",
|
|
|
|
}, {
|
|
|
|
Score: 1,
|
|
|
|
Member: "uno",
|
|
|
|
}, {
|
|
|
|
Score: 3,
|
|
|
|
Member: "two",
|
|
|
|
}}))
|
2015-07-16 17:30:16 +03:00
|
|
|
})
|
|
|
|
|
|
|
|
It("should ZAdd bytes", func() {
|
2018-03-07 12:56:24 +03:00
|
|
|
added, err := client.ZAdd("zset", redis.Z{
|
|
|
|
Score: 1,
|
|
|
|
Member: []byte("one"),
|
|
|
|
}).Result()
|
2015-07-16 17:30:16 +03:00
|
|
|
Expect(err).NotTo(HaveOccurred())
|
|
|
|
Expect(added).To(Equal(int64(1)))
|
|
|
|
|
2018-03-07 12:56:24 +03:00
|
|
|
added, err = client.ZAdd("zset", redis.Z{
|
|
|
|
Score: 1,
|
|
|
|
Member: []byte("uno"),
|
|
|
|
}).Result()
|
2015-07-16 17:30:16 +03:00
|
|
|
Expect(err).NotTo(HaveOccurred())
|
|
|
|
Expect(added).To(Equal(int64(1)))
|
|
|
|
|
2018-03-07 12:56:24 +03:00
|
|
|
added, err = client.ZAdd("zset", redis.Z{
|
|
|
|
Score: 2,
|
|
|
|
Member: []byte("two"),
|
|
|
|
}).Result()
|
2015-07-16 17:30:16 +03:00
|
|
|
Expect(err).NotTo(HaveOccurred())
|
|
|
|
Expect(added).To(Equal(int64(1)))
|
|
|
|
|
2018-03-07 12:56:24 +03:00
|
|
|
added, err = client.ZAdd("zset", redis.Z{
|
|
|
|
Score: 3,
|
|
|
|
Member: []byte("two"),
|
|
|
|
}).Result()
|
2015-07-16 17:30:16 +03:00
|
|
|
Expect(err).NotTo(HaveOccurred())
|
|
|
|
Expect(added).To(Equal(int64(0)))
|
2015-01-15 18:51:22 +03:00
|
|
|
|
2018-03-07 12:56:24 +03:00
|
|
|
vals, err := client.ZRangeWithScores("zset", 0, -1).Result()
|
2015-01-15 18:51:22 +03:00
|
|
|
Expect(err).NotTo(HaveOccurred())
|
2018-03-07 12:56:24 +03:00
|
|
|
Expect(vals).To(Equal([]redis.Z{{
|
|
|
|
Score: 1,
|
|
|
|
Member: "one",
|
|
|
|
}, {
|
|
|
|
Score: 1,
|
|
|
|
Member: "uno",
|
|
|
|
}, {
|
|
|
|
Score: 3,
|
|
|
|
Member: "two",
|
|
|
|
}}))
|
2015-01-15 18:51:22 +03:00
|
|
|
})
|
|
|
|
|
2015-08-29 13:08:27 +03:00
|
|
|
It("should ZAddNX", func() {
|
2018-03-07 12:56:24 +03:00
|
|
|
added, err := client.ZAddNX("zset", redis.Z{
|
|
|
|
Score: 1,
|
|
|
|
Member: "one",
|
|
|
|
}).Result()
|
2015-08-29 13:08:27 +03:00
|
|
|
Expect(err).NotTo(HaveOccurred())
|
|
|
|
Expect(added).To(Equal(int64(1)))
|
|
|
|
|
|
|
|
vals, err := client.ZRangeWithScores("zset", 0, -1).Result()
|
|
|
|
Expect(err).NotTo(HaveOccurred())
|
2018-03-07 12:56:24 +03:00
|
|
|
Expect(vals).To(Equal([]redis.Z{{Score: 1, Member: "one"}}))
|
2015-08-29 13:08:27 +03:00
|
|
|
|
2018-03-07 12:56:24 +03:00
|
|
|
added, err = client.ZAddNX("zset", redis.Z{
|
|
|
|
Score: 2,
|
|
|
|
Member: "one",
|
|
|
|
}).Result()
|
2015-08-29 13:08:27 +03:00
|
|
|
Expect(err).NotTo(HaveOccurred())
|
|
|
|
Expect(added).To(Equal(int64(0)))
|
|
|
|
|
|
|
|
vals, err = client.ZRangeWithScores("zset", 0, -1).Result()
|
|
|
|
Expect(err).NotTo(HaveOccurred())
|
2018-03-07 12:56:24 +03:00
|
|
|
Expect(vals).To(Equal([]redis.Z{{Score: 1, Member: "one"}}))
|
2015-08-29 13:08:27 +03:00
|
|
|
})
|
|
|
|
|
|
|
|
It("should ZAddXX", func() {
|
2018-03-07 12:56:24 +03:00
|
|
|
added, err := client.ZAddXX("zset", redis.Z{
|
|
|
|
Score: 1,
|
|
|
|
Member: "one",
|
|
|
|
}).Result()
|
2015-08-29 13:08:27 +03:00
|
|
|
Expect(err).NotTo(HaveOccurred())
|
|
|
|
Expect(added).To(Equal(int64(0)))
|
|
|
|
|
|
|
|
vals, err := client.ZRangeWithScores("zset", 0, -1).Result()
|
|
|
|
Expect(err).NotTo(HaveOccurred())
|
|
|
|
Expect(vals).To(BeEmpty())
|
|
|
|
|
2018-03-07 12:56:24 +03:00
|
|
|
added, err = client.ZAdd("zset", redis.Z{
|
|
|
|
Score: 1,
|
|
|
|
Member: "one",
|
|
|
|
}).Result()
|
2015-08-29 13:08:27 +03:00
|
|
|
Expect(err).NotTo(HaveOccurred())
|
|
|
|
Expect(added).To(Equal(int64(1)))
|
|
|
|
|
2018-03-07 12:56:24 +03:00
|
|
|
added, err = client.ZAddXX("zset", redis.Z{
|
|
|
|
Score: 2,
|
|
|
|
Member: "one",
|
|
|
|
}).Result()
|
2015-08-29 13:08:27 +03:00
|
|
|
Expect(err).NotTo(HaveOccurred())
|
|
|
|
Expect(added).To(Equal(int64(0)))
|
|
|
|
|
|
|
|
vals, err = client.ZRangeWithScores("zset", 0, -1).Result()
|
|
|
|
Expect(err).NotTo(HaveOccurred())
|
2018-03-07 12:56:24 +03:00
|
|
|
Expect(vals).To(Equal([]redis.Z{{Score: 2, Member: "one"}}))
|
2015-08-29 13:08:27 +03:00
|
|
|
})
|
|
|
|
|
|
|
|
It("should ZAddCh", func() {
|
2018-03-07 12:56:24 +03:00
|
|
|
changed, err := client.ZAddCh("zset", redis.Z{
|
|
|
|
Score: 1,
|
|
|
|
Member: "one",
|
|
|
|
}).Result()
|
2015-08-29 13:08:27 +03:00
|
|
|
Expect(err).NotTo(HaveOccurred())
|
|
|
|
Expect(changed).To(Equal(int64(1)))
|
|
|
|
|
2018-03-07 12:56:24 +03:00
|
|
|
changed, err = client.ZAddCh("zset", redis.Z{
|
|
|
|
Score: 1,
|
|
|
|
Member: "one",
|
|
|
|
}).Result()
|
2015-08-29 13:08:27 +03:00
|
|
|
Expect(err).NotTo(HaveOccurred())
|
|
|
|
Expect(changed).To(Equal(int64(0)))
|
|
|
|
})
|
|
|
|
|
|
|
|
It("should ZAddNXCh", func() {
|
2018-03-07 12:56:24 +03:00
|
|
|
changed, err := client.ZAddNXCh("zset", redis.Z{
|
|
|
|
Score: 1,
|
|
|
|
Member: "one",
|
|
|
|
}).Result()
|
2015-08-29 13:08:27 +03:00
|
|
|
Expect(err).NotTo(HaveOccurred())
|
|
|
|
Expect(changed).To(Equal(int64(1)))
|
|
|
|
|
|
|
|
vals, err := client.ZRangeWithScores("zset", 0, -1).Result()
|
|
|
|
Expect(err).NotTo(HaveOccurred())
|
2018-03-07 12:56:24 +03:00
|
|
|
Expect(vals).To(Equal([]redis.Z{{Score: 1, Member: "one"}}))
|
2015-08-29 13:08:27 +03:00
|
|
|
|
2018-03-07 12:56:24 +03:00
|
|
|
changed, err = client.ZAddNXCh("zset", redis.Z{
|
|
|
|
Score: 2,
|
|
|
|
Member: "one",
|
|
|
|
}).Result()
|
2015-08-29 13:08:27 +03:00
|
|
|
Expect(err).NotTo(HaveOccurred())
|
|
|
|
Expect(changed).To(Equal(int64(0)))
|
|
|
|
|
|
|
|
vals, err = client.ZRangeWithScores("zset", 0, -1).Result()
|
|
|
|
Expect(err).NotTo(HaveOccurred())
|
2018-03-07 12:56:24 +03:00
|
|
|
Expect(vals).To(Equal([]redis.Z{{
|
|
|
|
Score: 1,
|
|
|
|
Member: "one",
|
|
|
|
}}))
|
2015-08-29 13:08:27 +03:00
|
|
|
})
|
|
|
|
|
|
|
|
It("should ZAddXXCh", func() {
|
2018-03-07 12:56:24 +03:00
|
|
|
changed, err := client.ZAddXXCh("zset", redis.Z{
|
|
|
|
Score: 1,
|
|
|
|
Member: "one",
|
|
|
|
}).Result()
|
2015-08-29 13:08:27 +03:00
|
|
|
Expect(err).NotTo(HaveOccurred())
|
|
|
|
Expect(changed).To(Equal(int64(0)))
|
|
|
|
|
|
|
|
vals, err := client.ZRangeWithScores("zset", 0, -1).Result()
|
|
|
|
Expect(err).NotTo(HaveOccurred())
|
|
|
|
Expect(vals).To(BeEmpty())
|
|
|
|
|
2018-03-07 12:56:24 +03:00
|
|
|
added, err := client.ZAdd("zset", redis.Z{
|
|
|
|
Score: 1,
|
|
|
|
Member: "one",
|
|
|
|
}).Result()
|
2015-08-29 13:08:27 +03:00
|
|
|
Expect(err).NotTo(HaveOccurred())
|
|
|
|
Expect(added).To(Equal(int64(1)))
|
|
|
|
|
2018-03-07 12:56:24 +03:00
|
|
|
changed, err = client.ZAddXXCh("zset", redis.Z{
|
|
|
|
Score: 2,
|
|
|
|
Member: "one",
|
|
|
|
}).Result()
|
2015-08-29 13:08:27 +03:00
|
|
|
Expect(err).NotTo(HaveOccurred())
|
|
|
|
Expect(changed).To(Equal(int64(1)))
|
|
|
|
|
|
|
|
vals, err = client.ZRangeWithScores("zset", 0, -1).Result()
|
|
|
|
Expect(err).NotTo(HaveOccurred())
|
2018-03-07 12:56:24 +03:00
|
|
|
Expect(vals).To(Equal([]redis.Z{{Score: 2, Member: "one"}}))
|
2015-08-29 13:08:27 +03:00
|
|
|
})
|
|
|
|
|
|
|
|
It("should ZIncr", func() {
|
2018-03-07 12:56:24 +03:00
|
|
|
score, err := client.ZIncr("zset", redis.Z{
|
|
|
|
Score: 1,
|
|
|
|
Member: "one",
|
|
|
|
}).Result()
|
2015-08-29 13:08:27 +03:00
|
|
|
Expect(err).NotTo(HaveOccurred())
|
|
|
|
Expect(score).To(Equal(float64(1)))
|
|
|
|
|
|
|
|
vals, err := client.ZRangeWithScores("zset", 0, -1).Result()
|
|
|
|
Expect(err).NotTo(HaveOccurred())
|
2018-03-07 12:56:24 +03:00
|
|
|
Expect(vals).To(Equal([]redis.Z{{Score: 1, Member: "one"}}))
|
2015-08-29 13:08:27 +03:00
|
|
|
|
2018-03-07 12:56:24 +03:00
|
|
|
score, err = client.ZIncr("zset", redis.Z{Score: 1, Member: "one"}).Result()
|
2015-08-29 13:08:27 +03:00
|
|
|
Expect(err).NotTo(HaveOccurred())
|
|
|
|
Expect(score).To(Equal(float64(2)))
|
|
|
|
|
|
|
|
vals, err = client.ZRangeWithScores("zset", 0, -1).Result()
|
|
|
|
Expect(err).NotTo(HaveOccurred())
|
2018-03-07 12:56:24 +03:00
|
|
|
Expect(vals).To(Equal([]redis.Z{{Score: 2, Member: "one"}}))
|
2015-08-29 13:08:27 +03:00
|
|
|
})
|
|
|
|
|
|
|
|
It("should ZIncrNX", func() {
|
2018-03-07 12:56:24 +03:00
|
|
|
score, err := client.ZIncrNX("zset", redis.Z{
|
|
|
|
Score: 1,
|
|
|
|
Member: "one",
|
|
|
|
}).Result()
|
2015-08-29 13:08:27 +03:00
|
|
|
Expect(err).NotTo(HaveOccurred())
|
|
|
|
Expect(score).To(Equal(float64(1)))
|
|
|
|
|
|
|
|
vals, err := client.ZRangeWithScores("zset", 0, -1).Result()
|
|
|
|
Expect(err).NotTo(HaveOccurred())
|
2018-03-07 12:56:24 +03:00
|
|
|
Expect(vals).To(Equal([]redis.Z{{Score: 1, Member: "one"}}))
|
2015-08-29 13:08:27 +03:00
|
|
|
|
2018-03-07 12:56:24 +03:00
|
|
|
score, err = client.ZIncrNX("zset", redis.Z{
|
|
|
|
Score: 1,
|
|
|
|
Member: "one",
|
|
|
|
}).Result()
|
2015-08-29 13:08:27 +03:00
|
|
|
Expect(err).To(Equal(redis.Nil))
|
|
|
|
Expect(score).To(Equal(float64(0)))
|
|
|
|
|
|
|
|
vals, err = client.ZRangeWithScores("zset", 0, -1).Result()
|
|
|
|
Expect(err).NotTo(HaveOccurred())
|
2018-03-07 12:56:24 +03:00
|
|
|
Expect(vals).To(Equal([]redis.Z{{Score: 1, Member: "one"}}))
|
2015-08-29 13:08:27 +03:00
|
|
|
})
|
|
|
|
|
|
|
|
It("should ZIncrXX", func() {
|
2018-03-07 12:56:24 +03:00
|
|
|
score, err := client.ZIncrXX("zset", redis.Z{
|
|
|
|
Score: 1,
|
|
|
|
Member: "one",
|
|
|
|
}).Result()
|
2015-08-29 13:08:27 +03:00
|
|
|
Expect(err).To(Equal(redis.Nil))
|
|
|
|
Expect(score).To(Equal(float64(0)))
|
|
|
|
|
|
|
|
vals, err := client.ZRangeWithScores("zset", 0, -1).Result()
|
|
|
|
Expect(err).NotTo(HaveOccurred())
|
|
|
|
Expect(vals).To(BeEmpty())
|
|
|
|
|
2018-03-07 12:56:24 +03:00
|
|
|
added, err := client.ZAdd("zset", redis.Z{
|
|
|
|
Score: 1,
|
|
|
|
Member: "one",
|
|
|
|
}).Result()
|
2015-08-29 13:08:27 +03:00
|
|
|
Expect(err).NotTo(HaveOccurred())
|
|
|
|
Expect(added).To(Equal(int64(1)))
|
|
|
|
|
2018-03-07 12:56:24 +03:00
|
|
|
score, err = client.ZIncrXX("zset", redis.Z{
|
|
|
|
Score: 1,
|
|
|
|
Member: "one",
|
|
|
|
}).Result()
|
2015-08-29 13:08:27 +03:00
|
|
|
Expect(err).NotTo(HaveOccurred())
|
|
|
|
Expect(score).To(Equal(float64(2)))
|
|
|
|
|
|
|
|
vals, err = client.ZRangeWithScores("zset", 0, -1).Result()
|
|
|
|
Expect(err).NotTo(HaveOccurred())
|
2018-03-07 12:56:24 +03:00
|
|
|
Expect(vals).To(Equal([]redis.Z{{Score: 2, Member: "one"}}))
|
2015-08-29 13:08:27 +03:00
|
|
|
})
|
|
|
|
|
2015-01-15 18:51:22 +03:00
|
|
|
It("should ZCard", func() {
|
2018-03-07 12:56:24 +03:00
|
|
|
err := client.ZAdd("zset", redis.Z{
|
|
|
|
Score: 1,
|
|
|
|
Member: "one",
|
|
|
|
}).Err()
|
|
|
|
Expect(err).NotTo(HaveOccurred())
|
|
|
|
err = client.ZAdd("zset", redis.Z{
|
|
|
|
Score: 2,
|
|
|
|
Member: "two",
|
|
|
|
}).Err()
|
|
|
|
Expect(err).NotTo(HaveOccurred())
|
2015-01-15 18:51:22 +03:00
|
|
|
|
2018-03-07 12:56:24 +03:00
|
|
|
card, err := client.ZCard("zset").Result()
|
|
|
|
Expect(err).NotTo(HaveOccurred())
|
|
|
|
Expect(card).To(Equal(int64(2)))
|
2015-01-15 18:51:22 +03:00
|
|
|
})
|
|
|
|
|
|
|
|
It("should ZCount", func() {
|
2018-03-07 12:56:24 +03:00
|
|
|
err := client.ZAdd("zset", redis.Z{
|
|
|
|
Score: 1,
|
|
|
|
Member: "one",
|
|
|
|
}).Err()
|
2017-08-15 09:49:23 +03:00
|
|
|
Expect(err).NotTo(HaveOccurred())
|
2018-03-07 12:56:24 +03:00
|
|
|
err = client.ZAdd("zset", redis.Z{
|
|
|
|
Score: 2,
|
|
|
|
Member: "two",
|
|
|
|
}).Err()
|
2017-08-15 09:49:23 +03:00
|
|
|
Expect(err).NotTo(HaveOccurred())
|
2018-03-07 12:56:24 +03:00
|
|
|
err = client.ZAdd("zset", redis.Z{
|
|
|
|
Score: 3,
|
|
|
|
Member: "three",
|
|
|
|
}).Err()
|
2017-08-15 09:49:23 +03:00
|
|
|
Expect(err).NotTo(HaveOccurred())
|
|
|
|
|
|
|
|
count, err := client.ZCount("zset", "-inf", "+inf").Result()
|
|
|
|
Expect(err).NotTo(HaveOccurred())
|
|
|
|
Expect(count).To(Equal(int64(3)))
|
2015-01-15 18:51:22 +03:00
|
|
|
|
2017-08-15 09:49:23 +03:00
|
|
|
count, err = client.ZCount("zset", "(1", "3").Result()
|
|
|
|
Expect(err).NotTo(HaveOccurred())
|
|
|
|
Expect(count).To(Equal(int64(2)))
|
2015-01-15 18:51:22 +03:00
|
|
|
|
2017-08-15 09:49:23 +03:00
|
|
|
count, err = client.ZLexCount("zset", "-", "+").Result()
|
|
|
|
Expect(err).NotTo(HaveOccurred())
|
|
|
|
Expect(count).To(Equal(int64(3)))
|
2015-01-15 18:51:22 +03:00
|
|
|
})
|
|
|
|
|
|
|
|
It("should ZIncrBy", func() {
|
2018-03-07 12:56:24 +03:00
|
|
|
err := client.ZAdd("zset", redis.Z{
|
|
|
|
Score: 1,
|
|
|
|
Member: "one",
|
|
|
|
}).Err()
|
|
|
|
Expect(err).NotTo(HaveOccurred())
|
|
|
|
err = client.ZAdd("zset", redis.Z{
|
|
|
|
Score: 2,
|
|
|
|
Member: "two",
|
|
|
|
}).Err()
|
|
|
|
Expect(err).NotTo(HaveOccurred())
|
2015-01-15 18:51:22 +03:00
|
|
|
|
2018-03-07 12:56:24 +03:00
|
|
|
n, err := client.ZIncrBy("zset", 2, "one").Result()
|
|
|
|
Expect(err).NotTo(HaveOccurred())
|
|
|
|
Expect(n).To(Equal(float64(3)))
|
2015-01-15 18:51:22 +03:00
|
|
|
|
|
|
|
val, err := client.ZRangeWithScores("zset", 0, -1).Result()
|
|
|
|
Expect(err).NotTo(HaveOccurred())
|
2018-03-07 12:56:24 +03:00
|
|
|
Expect(val).To(Equal([]redis.Z{{
|
|
|
|
Score: 2,
|
|
|
|
Member: "two",
|
|
|
|
}, {
|
|
|
|
Score: 3,
|
|
|
|
Member: "one",
|
|
|
|
}}))
|
2015-01-15 18:51:22 +03:00
|
|
|
})
|
|
|
|
|
|
|
|
It("should ZInterStore", func() {
|
2018-03-07 12:56:24 +03:00
|
|
|
err := client.ZAdd("zset1", redis.Z{
|
|
|
|
Score: 1,
|
|
|
|
Member: "one",
|
|
|
|
}).Err()
|
|
|
|
Expect(err).NotTo(HaveOccurred())
|
|
|
|
err = client.ZAdd("zset1", redis.Z{
|
|
|
|
Score: 2,
|
|
|
|
Member: "two",
|
|
|
|
}).Err()
|
|
|
|
Expect(err).NotTo(HaveOccurred())
|
2015-01-15 18:51:22 +03:00
|
|
|
|
2018-03-07 12:56:24 +03:00
|
|
|
err = client.ZAdd("zset2", redis.Z{Score: 1, Member: "one"}).Err()
|
|
|
|
Expect(err).NotTo(HaveOccurred())
|
|
|
|
err = client.ZAdd("zset2", redis.Z{Score: 2, Member: "two"}).Err()
|
|
|
|
Expect(err).NotTo(HaveOccurred())
|
|
|
|
err = client.ZAdd("zset3", redis.Z{Score: 3, Member: "two"}).Err()
|
|
|
|
Expect(err).NotTo(HaveOccurred())
|
2015-01-15 18:51:22 +03:00
|
|
|
|
|
|
|
zInterStore := client.ZInterStore(
|
2015-12-01 17:28:41 +03:00
|
|
|
"out", redis.ZStore{Weights: []float64{2, 3}}, "zset1", "zset2")
|
2015-01-15 18:51:22 +03:00
|
|
|
Expect(zInterStore.Err()).NotTo(HaveOccurred())
|
|
|
|
Expect(zInterStore.Val()).To(Equal(int64(2)))
|
|
|
|
|
2018-03-07 12:56:24 +03:00
|
|
|
vals, err := client.ZRangeWithScores("out", 0, -1).Result()
|
2015-01-15 18:51:22 +03:00
|
|
|
Expect(err).NotTo(HaveOccurred())
|
2018-03-07 12:56:24 +03:00
|
|
|
Expect(vals).To(Equal([]redis.Z{{
|
|
|
|
Score: 5,
|
|
|
|
Member: "one",
|
|
|
|
}, {
|
|
|
|
Score: 10,
|
|
|
|
Member: "two",
|
|
|
|
}}))
|
2015-01-15 18:51:22 +03:00
|
|
|
})
|
|
|
|
|
2018-09-03 11:45:32 +03:00
|
|
|
It("should ZPopMax", func() {
|
|
|
|
err := client.ZAdd("zset", redis.Z{
|
|
|
|
Score: 1,
|
|
|
|
Member: "one",
|
|
|
|
}).Err()
|
|
|
|
Expect(err).NotTo(HaveOccurred())
|
|
|
|
err = client.ZAdd("zset", redis.Z{
|
|
|
|
Score: 2,
|
|
|
|
Member: "two",
|
|
|
|
}).Err()
|
|
|
|
Expect(err).NotTo(HaveOccurred())
|
|
|
|
err = client.ZAdd("zset", redis.Z{
|
|
|
|
Score: 3,
|
|
|
|
Member: "three",
|
|
|
|
}).Err()
|
|
|
|
Expect(err).NotTo(HaveOccurred())
|
|
|
|
|
|
|
|
members, err := client.ZPopMax("zset").Result()
|
|
|
|
Expect(err).NotTo(HaveOccurred())
|
|
|
|
Expect(members).To(Equal([]redis.Z{{
|
|
|
|
Score: 3,
|
|
|
|
Member: "three",
|
|
|
|
}}))
|
|
|
|
|
|
|
|
// adding back 3
|
|
|
|
err = client.ZAdd("zset", redis.Z{
|
|
|
|
Score: 3,
|
|
|
|
Member: "three",
|
|
|
|
}).Err()
|
|
|
|
Expect(err).NotTo(HaveOccurred())
|
|
|
|
members, err = client.ZPopMax("zset", 2).Result()
|
|
|
|
Expect(err).NotTo(HaveOccurred())
|
|
|
|
Expect(members).To(Equal([]redis.Z{{
|
|
|
|
Score: 3,
|
|
|
|
Member: "three",
|
|
|
|
}, {
|
|
|
|
Score: 2,
|
|
|
|
Member: "two",
|
|
|
|
}}))
|
|
|
|
|
|
|
|
// adding back 2 & 3
|
|
|
|
err = client.ZAdd("zset", redis.Z{
|
|
|
|
Score: 3,
|
|
|
|
Member: "three",
|
|
|
|
}).Err()
|
|
|
|
Expect(err).NotTo(HaveOccurred())
|
|
|
|
err = client.ZAdd("zset", redis.Z{
|
|
|
|
Score: 2,
|
|
|
|
Member: "two",
|
|
|
|
}).Err()
|
|
|
|
Expect(err).NotTo(HaveOccurred())
|
|
|
|
members, err = client.ZPopMax("zset", 10).Result()
|
|
|
|
Expect(err).NotTo(HaveOccurred())
|
|
|
|
Expect(members).To(Equal([]redis.Z{{
|
|
|
|
Score: 3,
|
|
|
|
Member: "three",
|
|
|
|
}, {
|
|
|
|
Score: 2,
|
|
|
|
Member: "two",
|
|
|
|
}, {
|
|
|
|
Score: 1,
|
|
|
|
Member: "one",
|
|
|
|
}}))
|
|
|
|
})
|
|
|
|
|
|
|
|
It("should ZPopMin", func() {
|
|
|
|
err := client.ZAdd("zset", redis.Z{
|
|
|
|
Score: 1,
|
|
|
|
Member: "one",
|
|
|
|
}).Err()
|
|
|
|
Expect(err).NotTo(HaveOccurred())
|
|
|
|
err = client.ZAdd("zset", redis.Z{
|
|
|
|
Score: 2,
|
|
|
|
Member: "two",
|
|
|
|
}).Err()
|
|
|
|
Expect(err).NotTo(HaveOccurred())
|
|
|
|
err = client.ZAdd("zset", redis.Z{
|
|
|
|
Score: 3,
|
|
|
|
Member: "three",
|
|
|
|
}).Err()
|
|
|
|
Expect(err).NotTo(HaveOccurred())
|
|
|
|
|
|
|
|
members, err := client.ZPopMin("zset").Result()
|
|
|
|
Expect(err).NotTo(HaveOccurred())
|
|
|
|
Expect(members).To(Equal([]redis.Z{{
|
|
|
|
Score: 1,
|
|
|
|
Member: "one",
|
|
|
|
}}))
|
|
|
|
|
|
|
|
// adding back 1
|
|
|
|
err = client.ZAdd("zset", redis.Z{
|
|
|
|
Score: 1,
|
|
|
|
Member: "one",
|
|
|
|
}).Err()
|
|
|
|
Expect(err).NotTo(HaveOccurred())
|
|
|
|
members, err = client.ZPopMin("zset", 2).Result()
|
|
|
|
Expect(err).NotTo(HaveOccurred())
|
|
|
|
Expect(members).To(Equal([]redis.Z{{
|
|
|
|
Score: 1,
|
|
|
|
Member: "one",
|
|
|
|
}, {
|
|
|
|
Score: 2,
|
|
|
|
Member: "two",
|
|
|
|
}}))
|
|
|
|
|
|
|
|
// adding back 1 & 2
|
|
|
|
err = client.ZAdd("zset", redis.Z{
|
|
|
|
Score: 1,
|
|
|
|
Member: "one",
|
|
|
|
}).Err()
|
|
|
|
Expect(err).NotTo(HaveOccurred())
|
2018-11-21 12:09:21 +03:00
|
|
|
|
2018-09-03 11:45:32 +03:00
|
|
|
err = client.ZAdd("zset", redis.Z{
|
|
|
|
Score: 2,
|
|
|
|
Member: "two",
|
|
|
|
}).Err()
|
2018-11-21 12:09:21 +03:00
|
|
|
Expect(err).NotTo(HaveOccurred())
|
|
|
|
|
2018-09-03 11:45:32 +03:00
|
|
|
members, err = client.ZPopMin("zset", 10).Result()
|
|
|
|
Expect(err).NotTo(HaveOccurred())
|
|
|
|
Expect(members).To(Equal([]redis.Z{{
|
|
|
|
Score: 1,
|
|
|
|
Member: "one",
|
|
|
|
}, {
|
|
|
|
Score: 2,
|
|
|
|
Member: "two",
|
|
|
|
}, {
|
|
|
|
Score: 3,
|
|
|
|
Member: "three",
|
|
|
|
}}))
|
|
|
|
})
|
|
|
|
|
2015-01-15 18:51:22 +03:00
|
|
|
It("should ZRange", func() {
|
2018-03-07 12:56:24 +03:00
|
|
|
err := client.ZAdd("zset", redis.Z{Score: 1, Member: "one"}).Err()
|
|
|
|
Expect(err).NotTo(HaveOccurred())
|
|
|
|
err = client.ZAdd("zset", redis.Z{Score: 2, Member: "two"}).Err()
|
|
|
|
Expect(err).NotTo(HaveOccurred())
|
|
|
|
err = client.ZAdd("zset", redis.Z{Score: 3, Member: "three"}).Err()
|
|
|
|
Expect(err).NotTo(HaveOccurred())
|
2015-01-15 18:51:22 +03:00
|
|
|
|
|
|
|
zRange := client.ZRange("zset", 0, -1)
|
|
|
|
Expect(zRange.Err()).NotTo(HaveOccurred())
|
|
|
|
Expect(zRange.Val()).To(Equal([]string{"one", "two", "three"}))
|
|
|
|
|
|
|
|
zRange = client.ZRange("zset", 2, 3)
|
|
|
|
Expect(zRange.Err()).NotTo(HaveOccurred())
|
|
|
|
Expect(zRange.Val()).To(Equal([]string{"three"}))
|
|
|
|
|
|
|
|
zRange = client.ZRange("zset", -2, -1)
|
|
|
|
Expect(zRange.Err()).NotTo(HaveOccurred())
|
|
|
|
Expect(zRange.Val()).To(Equal([]string{"two", "three"}))
|
|
|
|
})
|
|
|
|
|
|
|
|
It("should ZRangeWithScores", func() {
|
2018-03-07 12:56:24 +03:00
|
|
|
err := client.ZAdd("zset", redis.Z{Score: 1, Member: "one"}).Err()
|
|
|
|
Expect(err).NotTo(HaveOccurred())
|
|
|
|
err = client.ZAdd("zset", redis.Z{Score: 2, Member: "two"}).Err()
|
|
|
|
Expect(err).NotTo(HaveOccurred())
|
|
|
|
err = client.ZAdd("zset", redis.Z{Score: 3, Member: "three"}).Err()
|
|
|
|
Expect(err).NotTo(HaveOccurred())
|
2015-01-15 18:51:22 +03:00
|
|
|
|
2018-03-07 12:56:24 +03:00
|
|
|
vals, err := client.ZRangeWithScores("zset", 0, -1).Result()
|
2015-01-15 18:51:22 +03:00
|
|
|
Expect(err).NotTo(HaveOccurred())
|
2018-03-07 12:56:24 +03:00
|
|
|
Expect(vals).To(Equal([]redis.Z{{
|
|
|
|
Score: 1,
|
|
|
|
Member: "one",
|
|
|
|
}, {
|
|
|
|
Score: 2,
|
|
|
|
Member: "two",
|
|
|
|
}, {
|
|
|
|
Score: 3,
|
|
|
|
Member: "three",
|
|
|
|
}}))
|
2015-01-15 18:51:22 +03:00
|
|
|
|
2018-03-07 12:56:24 +03:00
|
|
|
vals, err = client.ZRangeWithScores("zset", 2, 3).Result()
|
2015-01-15 18:51:22 +03:00
|
|
|
Expect(err).NotTo(HaveOccurred())
|
2018-03-07 12:56:24 +03:00
|
|
|
Expect(vals).To(Equal([]redis.Z{{Score: 3, Member: "three"}}))
|
2015-01-15 18:51:22 +03:00
|
|
|
|
2018-03-07 12:56:24 +03:00
|
|
|
vals, err = client.ZRangeWithScores("zset", -2, -1).Result()
|
2015-01-15 18:51:22 +03:00
|
|
|
Expect(err).NotTo(HaveOccurred())
|
2018-03-07 12:56:24 +03:00
|
|
|
Expect(vals).To(Equal([]redis.Z{{
|
|
|
|
Score: 2,
|
|
|
|
Member: "two",
|
|
|
|
}, {
|
|
|
|
Score: 3,
|
|
|
|
Member: "three",
|
|
|
|
}}))
|
2015-01-15 18:51:22 +03:00
|
|
|
})
|
|
|
|
|
|
|
|
It("should ZRangeByScore", func() {
|
2018-03-07 12:56:24 +03:00
|
|
|
err := client.ZAdd("zset", redis.Z{Score: 1, Member: "one"}).Err()
|
|
|
|
Expect(err).NotTo(HaveOccurred())
|
|
|
|
err = client.ZAdd("zset", redis.Z{Score: 2, Member: "two"}).Err()
|
|
|
|
Expect(err).NotTo(HaveOccurred())
|
|
|
|
err = client.ZAdd("zset", redis.Z{Score: 3, Member: "three"}).Err()
|
|
|
|
Expect(err).NotTo(HaveOccurred())
|
2015-01-15 18:51:22 +03:00
|
|
|
|
2016-04-09 13:15:33 +03:00
|
|
|
zRangeByScore := client.ZRangeByScore("zset", redis.ZRangeBy{
|
2015-01-15 18:51:22 +03:00
|
|
|
Min: "-inf",
|
|
|
|
Max: "+inf",
|
|
|
|
})
|
|
|
|
Expect(zRangeByScore.Err()).NotTo(HaveOccurred())
|
|
|
|
Expect(zRangeByScore.Val()).To(Equal([]string{"one", "two", "three"}))
|
|
|
|
|
2016-04-09 13:15:33 +03:00
|
|
|
zRangeByScore = client.ZRangeByScore("zset", redis.ZRangeBy{
|
2015-01-15 18:51:22 +03:00
|
|
|
Min: "1",
|
|
|
|
Max: "2",
|
|
|
|
})
|
|
|
|
Expect(zRangeByScore.Err()).NotTo(HaveOccurred())
|
|
|
|
Expect(zRangeByScore.Val()).To(Equal([]string{"one", "two"}))
|
|
|
|
|
2016-04-09 13:15:33 +03:00
|
|
|
zRangeByScore = client.ZRangeByScore("zset", redis.ZRangeBy{
|
2015-01-15 18:51:22 +03:00
|
|
|
Min: "(1",
|
|
|
|
Max: "2",
|
|
|
|
})
|
|
|
|
Expect(zRangeByScore.Err()).NotTo(HaveOccurred())
|
|
|
|
Expect(zRangeByScore.Val()).To(Equal([]string{"two"}))
|
|
|
|
|
2016-04-09 13:15:33 +03:00
|
|
|
zRangeByScore = client.ZRangeByScore("zset", redis.ZRangeBy{
|
2015-01-15 18:51:22 +03:00
|
|
|
Min: "(1",
|
|
|
|
Max: "(2",
|
|
|
|
})
|
|
|
|
Expect(zRangeByScore.Err()).NotTo(HaveOccurred())
|
|
|
|
Expect(zRangeByScore.Val()).To(Equal([]string{}))
|
|
|
|
})
|
|
|
|
|
2015-08-23 06:38:37 +03:00
|
|
|
It("should ZRangeByLex", func() {
|
2018-03-07 12:56:24 +03:00
|
|
|
err := client.ZAdd("zset", redis.Z{
|
|
|
|
Score: 0,
|
|
|
|
Member: "a",
|
|
|
|
}).Err()
|
|
|
|
Expect(err).NotTo(HaveOccurred())
|
|
|
|
err = client.ZAdd("zset", redis.Z{
|
|
|
|
Score: 0,
|
|
|
|
Member: "b",
|
|
|
|
}).Err()
|
|
|
|
Expect(err).NotTo(HaveOccurred())
|
|
|
|
err = client.ZAdd("zset", redis.Z{
|
|
|
|
Score: 0,
|
|
|
|
Member: "c",
|
|
|
|
}).Err()
|
|
|
|
Expect(err).NotTo(HaveOccurred())
|
2015-08-23 06:38:37 +03:00
|
|
|
|
2016-04-09 13:15:33 +03:00
|
|
|
zRangeByLex := client.ZRangeByLex("zset", redis.ZRangeBy{
|
2015-08-23 06:38:37 +03:00
|
|
|
Min: "-",
|
|
|
|
Max: "+",
|
|
|
|
})
|
|
|
|
Expect(zRangeByLex.Err()).NotTo(HaveOccurred())
|
|
|
|
Expect(zRangeByLex.Val()).To(Equal([]string{"a", "b", "c"}))
|
|
|
|
|
2016-04-09 13:15:33 +03:00
|
|
|
zRangeByLex = client.ZRangeByLex("zset", redis.ZRangeBy{
|
2015-08-23 06:38:37 +03:00
|
|
|
Min: "[a",
|
|
|
|
Max: "[b",
|
|
|
|
})
|
|
|
|
Expect(zRangeByLex.Err()).NotTo(HaveOccurred())
|
|
|
|
Expect(zRangeByLex.Val()).To(Equal([]string{"a", "b"}))
|
|
|
|
|
2016-04-09 13:15:33 +03:00
|
|
|
zRangeByLex = client.ZRangeByLex("zset", redis.ZRangeBy{
|
2015-08-23 06:38:37 +03:00
|
|
|
Min: "(a",
|
|
|
|
Max: "[b",
|
|
|
|
})
|
|
|
|
Expect(zRangeByLex.Err()).NotTo(HaveOccurred())
|
|
|
|
Expect(zRangeByLex.Val()).To(Equal([]string{"b"}))
|
|
|
|
|
2016-04-09 13:15:33 +03:00
|
|
|
zRangeByLex = client.ZRangeByLex("zset", redis.ZRangeBy{
|
2015-08-23 06:38:37 +03:00
|
|
|
Min: "(a",
|
|
|
|
Max: "(b",
|
|
|
|
})
|
|
|
|
Expect(zRangeByLex.Err()).NotTo(HaveOccurred())
|
|
|
|
Expect(zRangeByLex.Val()).To(Equal([]string{}))
|
|
|
|
})
|
|
|
|
|
2015-01-15 18:51:22 +03:00
|
|
|
It("should ZRangeByScoreWithScoresMap", func() {
|
2018-03-07 12:56:24 +03:00
|
|
|
err := client.ZAdd("zset", redis.Z{Score: 1, Member: "one"}).Err()
|
|
|
|
Expect(err).NotTo(HaveOccurred())
|
|
|
|
err = client.ZAdd("zset", redis.Z{Score: 2, Member: "two"}).Err()
|
|
|
|
Expect(err).NotTo(HaveOccurred())
|
|
|
|
err = client.ZAdd("zset", redis.Z{Score: 3, Member: "three"}).Err()
|
|
|
|
Expect(err).NotTo(HaveOccurred())
|
2015-01-15 18:51:22 +03:00
|
|
|
|
2018-03-07 12:56:24 +03:00
|
|
|
vals, err := client.ZRangeByScoreWithScores("zset", redis.ZRangeBy{
|
2015-01-15 18:51:22 +03:00
|
|
|
Min: "-inf",
|
|
|
|
Max: "+inf",
|
|
|
|
}).Result()
|
|
|
|
Expect(err).NotTo(HaveOccurred())
|
2018-03-07 12:56:24 +03:00
|
|
|
Expect(vals).To(Equal([]redis.Z{{
|
|
|
|
Score: 1,
|
|
|
|
Member: "one",
|
|
|
|
}, {
|
|
|
|
Score: 2,
|
|
|
|
Member: "two",
|
|
|
|
}, {
|
|
|
|
Score: 3,
|
|
|
|
Member: "three",
|
|
|
|
}}))
|
|
|
|
|
|
|
|
vals, err = client.ZRangeByScoreWithScores("zset", redis.ZRangeBy{
|
2015-01-15 18:51:22 +03:00
|
|
|
Min: "1",
|
|
|
|
Max: "2",
|
|
|
|
}).Result()
|
|
|
|
Expect(err).NotTo(HaveOccurred())
|
2018-03-07 12:56:24 +03:00
|
|
|
Expect(vals).To(Equal([]redis.Z{{
|
|
|
|
Score: 1,
|
|
|
|
Member: "one",
|
|
|
|
}, {
|
|
|
|
Score: 2,
|
|
|
|
Member: "two",
|
|
|
|
}}))
|
2015-01-15 18:51:22 +03:00
|
|
|
|
2018-03-07 12:56:24 +03:00
|
|
|
vals, err = client.ZRangeByScoreWithScores("zset", redis.ZRangeBy{
|
2015-01-15 18:51:22 +03:00
|
|
|
Min: "(1",
|
|
|
|
Max: "2",
|
|
|
|
}).Result()
|
|
|
|
Expect(err).NotTo(HaveOccurred())
|
2018-03-07 12:56:24 +03:00
|
|
|
Expect(vals).To(Equal([]redis.Z{{Score: 2, Member: "two"}}))
|
2015-01-15 18:51:22 +03:00
|
|
|
|
2018-03-07 12:56:24 +03:00
|
|
|
vals, err = client.ZRangeByScoreWithScores("zset", redis.ZRangeBy{
|
2015-01-15 18:51:22 +03:00
|
|
|
Min: "(1",
|
|
|
|
Max: "(2",
|
|
|
|
}).Result()
|
|
|
|
Expect(err).NotTo(HaveOccurred())
|
2018-03-07 12:56:24 +03:00
|
|
|
Expect(vals).To(Equal([]redis.Z{}))
|
2015-01-15 18:51:22 +03:00
|
|
|
})
|
|
|
|
|
|
|
|
It("should ZRank", func() {
|
2018-03-07 12:56:24 +03:00
|
|
|
err := client.ZAdd("zset", redis.Z{Score: 1, Member: "one"}).Err()
|
|
|
|
Expect(err).NotTo(HaveOccurred())
|
|
|
|
err = client.ZAdd("zset", redis.Z{Score: 2, Member: "two"}).Err()
|
|
|
|
Expect(err).NotTo(HaveOccurred())
|
|
|
|
err = client.ZAdd("zset", redis.Z{Score: 3, Member: "three"}).Err()
|
|
|
|
Expect(err).NotTo(HaveOccurred())
|
2015-01-15 18:51:22 +03:00
|
|
|
|
|
|
|
zRank := client.ZRank("zset", "three")
|
|
|
|
Expect(zRank.Err()).NotTo(HaveOccurred())
|
|
|
|
Expect(zRank.Val()).To(Equal(int64(2)))
|
|
|
|
|
|
|
|
zRank = client.ZRank("zset", "four")
|
|
|
|
Expect(zRank.Err()).To(Equal(redis.Nil))
|
|
|
|
Expect(zRank.Val()).To(Equal(int64(0)))
|
|
|
|
})
|
|
|
|
|
|
|
|
It("should ZRem", func() {
|
2018-03-07 12:56:24 +03:00
|
|
|
err := client.ZAdd("zset", redis.Z{Score: 1, Member: "one"}).Err()
|
|
|
|
Expect(err).NotTo(HaveOccurred())
|
|
|
|
err = client.ZAdd("zset", redis.Z{Score: 2, Member: "two"}).Err()
|
|
|
|
Expect(err).NotTo(HaveOccurred())
|
|
|
|
err = client.ZAdd("zset", redis.Z{Score: 3, Member: "three"}).Err()
|
|
|
|
Expect(err).NotTo(HaveOccurred())
|
2015-01-15 18:51:22 +03:00
|
|
|
|
|
|
|
zRem := client.ZRem("zset", "two")
|
|
|
|
Expect(zRem.Err()).NotTo(HaveOccurred())
|
|
|
|
Expect(zRem.Val()).To(Equal(int64(1)))
|
|
|
|
|
2018-03-07 12:56:24 +03:00
|
|
|
vals, err := client.ZRangeWithScores("zset", 0, -1).Result()
|
2015-01-15 18:51:22 +03:00
|
|
|
Expect(err).NotTo(HaveOccurred())
|
2018-03-07 12:56:24 +03:00
|
|
|
Expect(vals).To(Equal([]redis.Z{{
|
|
|
|
Score: 1,
|
|
|
|
Member: "one",
|
|
|
|
}, {
|
|
|
|
Score: 3,
|
|
|
|
Member: "three",
|
|
|
|
}}))
|
2015-01-15 18:51:22 +03:00
|
|
|
})
|
|
|
|
|
|
|
|
It("should ZRemRangeByRank", func() {
|
2018-03-07 12:56:24 +03:00
|
|
|
err := client.ZAdd("zset", redis.Z{Score: 1, Member: "one"}).Err()
|
|
|
|
Expect(err).NotTo(HaveOccurred())
|
|
|
|
err = client.ZAdd("zset", redis.Z{Score: 2, Member: "two"}).Err()
|
|
|
|
Expect(err).NotTo(HaveOccurred())
|
|
|
|
err = client.ZAdd("zset", redis.Z{Score: 3, Member: "three"}).Err()
|
|
|
|
Expect(err).NotTo(HaveOccurred())
|
2015-01-15 18:51:22 +03:00
|
|
|
|
|
|
|
zRemRangeByRank := client.ZRemRangeByRank("zset", 0, 1)
|
|
|
|
Expect(zRemRangeByRank.Err()).NotTo(HaveOccurred())
|
|
|
|
Expect(zRemRangeByRank.Val()).To(Equal(int64(2)))
|
|
|
|
|
2018-03-07 12:56:24 +03:00
|
|
|
vals, err := client.ZRangeWithScores("zset", 0, -1).Result()
|
2015-01-15 18:51:22 +03:00
|
|
|
Expect(err).NotTo(HaveOccurred())
|
2018-03-07 12:56:24 +03:00
|
|
|
Expect(vals).To(Equal([]redis.Z{{
|
|
|
|
Score: 3,
|
|
|
|
Member: "three",
|
|
|
|
}}))
|
2015-01-15 18:51:22 +03:00
|
|
|
})
|
|
|
|
|
|
|
|
It("should ZRemRangeByScore", func() {
|
2018-03-07 12:56:24 +03:00
|
|
|
err := client.ZAdd("zset", redis.Z{Score: 1, Member: "one"}).Err()
|
|
|
|
Expect(err).NotTo(HaveOccurred())
|
|
|
|
err = client.ZAdd("zset", redis.Z{Score: 2, Member: "two"}).Err()
|
|
|
|
Expect(err).NotTo(HaveOccurred())
|
|
|
|
err = client.ZAdd("zset", redis.Z{Score: 3, Member: "three"}).Err()
|
|
|
|
Expect(err).NotTo(HaveOccurred())
|
2015-01-15 18:51:22 +03:00
|
|
|
|
|
|
|
zRemRangeByScore := client.ZRemRangeByScore("zset", "-inf", "(2")
|
|
|
|
Expect(zRemRangeByScore.Err()).NotTo(HaveOccurred())
|
|
|
|
Expect(zRemRangeByScore.Val()).To(Equal(int64(1)))
|
|
|
|
|
2018-03-07 12:56:24 +03:00
|
|
|
vals, err := client.ZRangeWithScores("zset", 0, -1).Result()
|
2015-01-15 18:51:22 +03:00
|
|
|
Expect(err).NotTo(HaveOccurred())
|
2018-03-07 12:56:24 +03:00
|
|
|
Expect(vals).To(Equal([]redis.Z{{
|
|
|
|
Score: 2,
|
|
|
|
Member: "two",
|
|
|
|
}, {
|
|
|
|
Score: 3,
|
|
|
|
Member: "three",
|
|
|
|
}}))
|
2015-01-15 18:51:22 +03:00
|
|
|
})
|
|
|
|
|
2017-01-26 16:51:34 +03:00
|
|
|
It("should ZRemRangeByLex", func() {
|
|
|
|
zz := []redis.Z{
|
2018-03-07 12:56:24 +03:00
|
|
|
{Score: 0, Member: "aaaa"},
|
|
|
|
{Score: 0, Member: "b"},
|
|
|
|
{Score: 0, Member: "c"},
|
|
|
|
{Score: 0, Member: "d"},
|
|
|
|
{Score: 0, Member: "e"},
|
|
|
|
{Score: 0, Member: "foo"},
|
|
|
|
{Score: 0, Member: "zap"},
|
|
|
|
{Score: 0, Member: "zip"},
|
|
|
|
{Score: 0, Member: "ALPHA"},
|
|
|
|
{Score: 0, Member: "alpha"},
|
2017-01-26 16:51:34 +03:00
|
|
|
}
|
|
|
|
for _, z := range zz {
|
|
|
|
err := client.ZAdd("zset", z).Err()
|
|
|
|
Expect(err).NotTo(HaveOccurred())
|
|
|
|
}
|
|
|
|
|
|
|
|
n, err := client.ZRemRangeByLex("zset", "[alpha", "[omega").Result()
|
|
|
|
Expect(err).NotTo(HaveOccurred())
|
|
|
|
Expect(n).To(Equal(int64(6)))
|
|
|
|
|
|
|
|
vals, err := client.ZRange("zset", 0, -1).Result()
|
|
|
|
Expect(err).NotTo(HaveOccurred())
|
|
|
|
Expect(vals).To(Equal([]string{"ALPHA", "aaaa", "zap", "zip"}))
|
|
|
|
})
|
|
|
|
|
2015-01-15 18:51:22 +03:00
|
|
|
It("should ZRevRange", func() {
|
2018-03-07 12:56:24 +03:00
|
|
|
err := client.ZAdd("zset", redis.Z{Score: 1, Member: "one"}).Err()
|
|
|
|
Expect(err).NotTo(HaveOccurred())
|
|
|
|
err = client.ZAdd("zset", redis.Z{Score: 2, Member: "two"}).Err()
|
|
|
|
Expect(err).NotTo(HaveOccurred())
|
|
|
|
err = client.ZAdd("zset", redis.Z{Score: 3, Member: "three"}).Err()
|
|
|
|
Expect(err).NotTo(HaveOccurred())
|
2015-01-15 18:51:22 +03:00
|
|
|
|
2015-03-30 16:14:21 +03:00
|
|
|
zRevRange := client.ZRevRange("zset", 0, -1)
|
2015-01-15 18:51:22 +03:00
|
|
|
Expect(zRevRange.Err()).NotTo(HaveOccurred())
|
|
|
|
Expect(zRevRange.Val()).To(Equal([]string{"three", "two", "one"}))
|
|
|
|
|
2015-03-30 16:14:21 +03:00
|
|
|
zRevRange = client.ZRevRange("zset", 2, 3)
|
2015-01-15 18:51:22 +03:00
|
|
|
Expect(zRevRange.Err()).NotTo(HaveOccurred())
|
|
|
|
Expect(zRevRange.Val()).To(Equal([]string{"one"}))
|
|
|
|
|
2015-03-30 16:14:21 +03:00
|
|
|
zRevRange = client.ZRevRange("zset", -2, -1)
|
2015-01-15 18:51:22 +03:00
|
|
|
Expect(zRevRange.Err()).NotTo(HaveOccurred())
|
|
|
|
Expect(zRevRange.Val()).To(Equal([]string{"two", "one"}))
|
|
|
|
})
|
|
|
|
|
|
|
|
It("should ZRevRangeWithScoresMap", func() {
|
2018-03-07 12:56:24 +03:00
|
|
|
err := client.ZAdd("zset", redis.Z{Score: 1, Member: "one"}).Err()
|
|
|
|
Expect(err).NotTo(HaveOccurred())
|
|
|
|
err = client.ZAdd("zset", redis.Z{Score: 2, Member: "two"}).Err()
|
|
|
|
Expect(err).NotTo(HaveOccurred())
|
|
|
|
err = client.ZAdd("zset", redis.Z{Score: 3, Member: "three"}).Err()
|
|
|
|
Expect(err).NotTo(HaveOccurred())
|
2015-01-15 18:51:22 +03:00
|
|
|
|
2015-03-30 16:14:21 +03:00
|
|
|
val, err := client.ZRevRangeWithScores("zset", 0, -1).Result()
|
2015-01-15 18:51:22 +03:00
|
|
|
Expect(err).NotTo(HaveOccurred())
|
2018-03-07 12:56:24 +03:00
|
|
|
Expect(val).To(Equal([]redis.Z{{
|
|
|
|
Score: 3,
|
|
|
|
Member: "three",
|
|
|
|
}, {
|
|
|
|
Score: 2,
|
|
|
|
Member: "two",
|
|
|
|
}, {
|
|
|
|
Score: 1,
|
|
|
|
Member: "one",
|
|
|
|
}}))
|
2015-01-15 18:51:22 +03:00
|
|
|
|
2015-03-30 16:14:21 +03:00
|
|
|
val, err = client.ZRevRangeWithScores("zset", 2, 3).Result()
|
2015-01-15 18:51:22 +03:00
|
|
|
Expect(err).NotTo(HaveOccurred())
|
2018-03-07 12:56:24 +03:00
|
|
|
Expect(val).To(Equal([]redis.Z{{Score: 1, Member: "one"}}))
|
2015-01-15 18:51:22 +03:00
|
|
|
|
2015-03-30 16:14:21 +03:00
|
|
|
val, err = client.ZRevRangeWithScores("zset", -2, -1).Result()
|
2015-01-15 18:51:22 +03:00
|
|
|
Expect(err).NotTo(HaveOccurred())
|
2018-03-07 12:56:24 +03:00
|
|
|
Expect(val).To(Equal([]redis.Z{{
|
|
|
|
Score: 2,
|
|
|
|
Member: "two",
|
|
|
|
}, {
|
|
|
|
Score: 1,
|
|
|
|
Member: "one",
|
|
|
|
}}))
|
2015-01-15 18:51:22 +03:00
|
|
|
})
|
|
|
|
|
|
|
|
It("should ZRevRangeByScore", func() {
|
2018-03-07 12:56:24 +03:00
|
|
|
err := client.ZAdd("zset", redis.Z{Score: 1, Member: "one"}).Err()
|
|
|
|
Expect(err).NotTo(HaveOccurred())
|
|
|
|
err = client.ZAdd("zset", redis.Z{Score: 2, Member: "two"}).Err()
|
|
|
|
Expect(err).NotTo(HaveOccurred())
|
|
|
|
err = client.ZAdd("zset", redis.Z{Score: 3, Member: "three"}).Err()
|
|
|
|
Expect(err).NotTo(HaveOccurred())
|
2015-01-15 18:51:22 +03:00
|
|
|
|
|
|
|
vals, err := client.ZRevRangeByScore(
|
2016-04-09 13:15:33 +03:00
|
|
|
"zset", redis.ZRangeBy{Max: "+inf", Min: "-inf"}).Result()
|
2015-01-15 18:51:22 +03:00
|
|
|
Expect(err).NotTo(HaveOccurred())
|
|
|
|
Expect(vals).To(Equal([]string{"three", "two", "one"}))
|
|
|
|
|
|
|
|
vals, err = client.ZRevRangeByScore(
|
2016-04-09 13:15:33 +03:00
|
|
|
"zset", redis.ZRangeBy{Max: "2", Min: "(1"}).Result()
|
2015-01-15 18:51:22 +03:00
|
|
|
Expect(err).NotTo(HaveOccurred())
|
|
|
|
Expect(vals).To(Equal([]string{"two"}))
|
|
|
|
|
|
|
|
vals, err = client.ZRevRangeByScore(
|
2016-04-09 13:15:33 +03:00
|
|
|
"zset", redis.ZRangeBy{Max: "(2", Min: "(1"}).Result()
|
2015-08-25 22:15:01 +03:00
|
|
|
Expect(err).NotTo(HaveOccurred())
|
|
|
|
Expect(vals).To(Equal([]string{}))
|
|
|
|
})
|
|
|
|
|
|
|
|
It("should ZRevRangeByLex", func() {
|
2018-03-07 12:56:24 +03:00
|
|
|
err := client.ZAdd("zset", redis.Z{Score: 0, Member: "a"}).Err()
|
|
|
|
Expect(err).NotTo(HaveOccurred())
|
|
|
|
err = client.ZAdd("zset", redis.Z{Score: 0, Member: "b"}).Err()
|
|
|
|
Expect(err).NotTo(HaveOccurred())
|
|
|
|
err = client.ZAdd("zset", redis.Z{Score: 0, Member: "c"}).Err()
|
|
|
|
Expect(err).NotTo(HaveOccurred())
|
2015-08-25 22:15:01 +03:00
|
|
|
|
|
|
|
vals, err := client.ZRevRangeByLex(
|
2016-04-09 13:15:33 +03:00
|
|
|
"zset", redis.ZRangeBy{Max: "+", Min: "-"}).Result()
|
2015-08-25 22:15:01 +03:00
|
|
|
Expect(err).NotTo(HaveOccurred())
|
|
|
|
Expect(vals).To(Equal([]string{"c", "b", "a"}))
|
|
|
|
|
2015-08-25 22:18:17 +03:00
|
|
|
vals, err = client.ZRevRangeByLex(
|
2016-04-09 13:15:33 +03:00
|
|
|
"zset", redis.ZRangeBy{Max: "[b", Min: "(a"}).Result()
|
2015-08-25 22:15:01 +03:00
|
|
|
Expect(err).NotTo(HaveOccurred())
|
|
|
|
Expect(vals).To(Equal([]string{"b"}))
|
|
|
|
|
2015-08-25 22:18:17 +03:00
|
|
|
vals, err = client.ZRevRangeByLex(
|
2016-04-09 13:15:33 +03:00
|
|
|
"zset", redis.ZRangeBy{Max: "(b", Min: "(a"}).Result()
|
2015-01-15 18:51:22 +03:00
|
|
|
Expect(err).NotTo(HaveOccurred())
|
|
|
|
Expect(vals).To(Equal([]string{}))
|
|
|
|
})
|
|
|
|
|
|
|
|
It("should ZRevRangeByScoreWithScores", func() {
|
2018-03-07 12:56:24 +03:00
|
|
|
err := client.ZAdd("zset", redis.Z{Score: 1, Member: "one"}).Err()
|
|
|
|
Expect(err).NotTo(HaveOccurred())
|
|
|
|
err = client.ZAdd("zset", redis.Z{Score: 2, Member: "two"}).Err()
|
|
|
|
Expect(err).NotTo(HaveOccurred())
|
|
|
|
err = client.ZAdd("zset", redis.Z{Score: 3, Member: "three"}).Err()
|
|
|
|
Expect(err).NotTo(HaveOccurred())
|
2015-01-15 18:51:22 +03:00
|
|
|
|
|
|
|
vals, err := client.ZRevRangeByScoreWithScores(
|
2016-04-09 13:15:33 +03:00
|
|
|
"zset", redis.ZRangeBy{Max: "+inf", Min: "-inf"}).Result()
|
2015-01-15 18:51:22 +03:00
|
|
|
Expect(err).NotTo(HaveOccurred())
|
2018-03-07 12:56:24 +03:00
|
|
|
Expect(vals).To(Equal([]redis.Z{{
|
|
|
|
Score: 3,
|
|
|
|
Member: "three",
|
|
|
|
}, {
|
|
|
|
Score: 2,
|
|
|
|
Member: "two",
|
|
|
|
}, {
|
|
|
|
Score: 1,
|
|
|
|
Member: "one",
|
|
|
|
}}))
|
2015-01-15 18:51:22 +03:00
|
|
|
})
|
|
|
|
|
|
|
|
It("should ZRevRangeByScoreWithScoresMap", func() {
|
2018-03-07 12:56:24 +03:00
|
|
|
err := client.ZAdd("zset", redis.Z{Score: 1, Member: "one"}).Err()
|
|
|
|
Expect(err).NotTo(HaveOccurred())
|
|
|
|
err = client.ZAdd("zset", redis.Z{Score: 2, Member: "two"}).Err()
|
|
|
|
Expect(err).NotTo(HaveOccurred())
|
|
|
|
err = client.ZAdd("zset", redis.Z{Score: 3, Member: "three"}).Err()
|
|
|
|
Expect(err).NotTo(HaveOccurred())
|
2015-01-15 18:51:22 +03:00
|
|
|
|
2018-03-07 12:56:24 +03:00
|
|
|
vals, err := client.ZRevRangeByScoreWithScores(
|
2016-04-09 13:15:33 +03:00
|
|
|
"zset", redis.ZRangeBy{Max: "+inf", Min: "-inf"}).Result()
|
2015-01-15 18:51:22 +03:00
|
|
|
Expect(err).NotTo(HaveOccurred())
|
2018-03-07 12:56:24 +03:00
|
|
|
Expect(vals).To(Equal([]redis.Z{{
|
|
|
|
Score: 3,
|
|
|
|
Member: "three",
|
|
|
|
}, {
|
|
|
|
Score: 2,
|
|
|
|
Member: "two",
|
|
|
|
}, {
|
|
|
|
Score: 1,
|
|
|
|
Member: "one",
|
|
|
|
}}))
|
|
|
|
|
|
|
|
vals, err = client.ZRevRangeByScoreWithScores(
|
2016-04-09 13:15:33 +03:00
|
|
|
"zset", redis.ZRangeBy{Max: "2", Min: "(1"}).Result()
|
2015-01-15 18:51:22 +03:00
|
|
|
Expect(err).NotTo(HaveOccurred())
|
2018-03-07 12:56:24 +03:00
|
|
|
Expect(vals).To(Equal([]redis.Z{{Score: 2, Member: "two"}}))
|
2015-01-15 18:51:22 +03:00
|
|
|
|
2018-03-07 12:56:24 +03:00
|
|
|
vals, err = client.ZRevRangeByScoreWithScores(
|
2016-04-09 13:15:33 +03:00
|
|
|
"zset", redis.ZRangeBy{Max: "(2", Min: "(1"}).Result()
|
2015-01-15 18:51:22 +03:00
|
|
|
Expect(err).NotTo(HaveOccurred())
|
2018-03-07 12:56:24 +03:00
|
|
|
Expect(vals).To(Equal([]redis.Z{}))
|
2015-01-15 18:51:22 +03:00
|
|
|
})
|
|
|
|
|
|
|
|
It("should ZRevRank", func() {
|
2018-03-07 12:56:24 +03:00
|
|
|
err := client.ZAdd("zset", redis.Z{Score: 1, Member: "one"}).Err()
|
|
|
|
Expect(err).NotTo(HaveOccurred())
|
|
|
|
err = client.ZAdd("zset", redis.Z{Score: 2, Member: "two"}).Err()
|
|
|
|
Expect(err).NotTo(HaveOccurred())
|
|
|
|
err = client.ZAdd("zset", redis.Z{Score: 3, Member: "three"}).Err()
|
|
|
|
Expect(err).NotTo(HaveOccurred())
|
2015-01-15 18:51:22 +03:00
|
|
|
|
|
|
|
zRevRank := client.ZRevRank("zset", "one")
|
|
|
|
Expect(zRevRank.Err()).NotTo(HaveOccurred())
|
|
|
|
Expect(zRevRank.Val()).To(Equal(int64(2)))
|
|
|
|
|
|
|
|
zRevRank = client.ZRevRank("zset", "four")
|
|
|
|
Expect(zRevRank.Err()).To(Equal(redis.Nil))
|
|
|
|
Expect(zRevRank.Val()).To(Equal(int64(0)))
|
|
|
|
})
|
|
|
|
|
|
|
|
It("should ZScore", func() {
|
2018-03-07 12:56:24 +03:00
|
|
|
zAdd := client.ZAdd("zset", redis.Z{Score: 1.001, Member: "one"})
|
2015-01-15 18:51:22 +03:00
|
|
|
Expect(zAdd.Err()).NotTo(HaveOccurred())
|
|
|
|
|
|
|
|
zScore := client.ZScore("zset", "one")
|
|
|
|
Expect(zScore.Err()).NotTo(HaveOccurred())
|
|
|
|
Expect(zScore.Val()).To(Equal(float64(1.001)))
|
|
|
|
})
|
|
|
|
|
|
|
|
It("should ZUnionStore", func() {
|
2018-03-07 12:56:24 +03:00
|
|
|
err := client.ZAdd("zset1", redis.Z{Score: 1, Member: "one"}).Err()
|
|
|
|
Expect(err).NotTo(HaveOccurred())
|
|
|
|
err = client.ZAdd("zset1", redis.Z{Score: 2, Member: "two"}).Err()
|
|
|
|
Expect(err).NotTo(HaveOccurred())
|
2015-01-15 18:51:22 +03:00
|
|
|
|
2018-03-07 12:56:24 +03:00
|
|
|
err = client.ZAdd("zset2", redis.Z{Score: 1, Member: "one"}).Err()
|
|
|
|
Expect(err).NotTo(HaveOccurred())
|
|
|
|
err = client.ZAdd("zset2", redis.Z{Score: 2, Member: "two"}).Err()
|
|
|
|
Expect(err).NotTo(HaveOccurred())
|
|
|
|
err = client.ZAdd("zset2", redis.Z{Score: 3, Member: "three"}).Err()
|
|
|
|
Expect(err).NotTo(HaveOccurred())
|
2015-01-15 18:51:22 +03:00
|
|
|
|
|
|
|
zUnionStore := client.ZUnionStore(
|
2015-12-01 17:28:41 +03:00
|
|
|
"out", redis.ZStore{Weights: []float64{2, 3}}, "zset1", "zset2")
|
2015-01-15 18:51:22 +03:00
|
|
|
Expect(zUnionStore.Err()).NotTo(HaveOccurred())
|
|
|
|
Expect(zUnionStore.Val()).To(Equal(int64(3)))
|
|
|
|
|
|
|
|
val, err := client.ZRangeWithScores("out", 0, -1).Result()
|
|
|
|
Expect(err).NotTo(HaveOccurred())
|
2018-03-07 12:56:24 +03:00
|
|
|
Expect(val).To(Equal([]redis.Z{{
|
|
|
|
Score: 5,
|
|
|
|
Member: "one",
|
|
|
|
}, {
|
|
|
|
Score: 9,
|
|
|
|
Member: "three",
|
|
|
|
}, {
|
|
|
|
Score: 10,
|
|
|
|
Member: "two",
|
|
|
|
}}))
|
2015-01-15 18:51:22 +03:00
|
|
|
})
|
|
|
|
|
|
|
|
})
|
|
|
|
|
2017-11-25 05:06:13 +03:00
|
|
|
Describe("streams", func() {
|
2018-08-02 14:48:46 +03:00
|
|
|
BeforeEach(func() {
|
|
|
|
id, err := client.XAdd(&redis.XAddArgs{
|
|
|
|
Stream: "stream",
|
|
|
|
ID: "1-0",
|
|
|
|
Values: map[string]interface{}{"uno": "un"},
|
2017-11-25 05:06:13 +03:00
|
|
|
}).Result()
|
|
|
|
Expect(err).NotTo(HaveOccurred())
|
|
|
|
Expect(id).To(Equal("1-0"))
|
|
|
|
|
2018-08-02 14:48:46 +03:00
|
|
|
id, err = client.XAdd(&redis.XAddArgs{
|
|
|
|
Stream: "stream",
|
|
|
|
ID: "2-0",
|
|
|
|
Values: map[string]interface{}{"dos": "deux"},
|
2017-11-25 05:06:13 +03:00
|
|
|
}).Result()
|
|
|
|
Expect(err).NotTo(HaveOccurred())
|
|
|
|
Expect(id).To(Equal("2-0"))
|
|
|
|
|
2018-08-02 14:48:46 +03:00
|
|
|
id, err = client.XAdd(&redis.XAddArgs{
|
|
|
|
Stream: "stream",
|
|
|
|
ID: "3-0",
|
|
|
|
Values: map[string]interface{}{"tres": "troix"},
|
2017-11-25 05:06:13 +03:00
|
|
|
}).Result()
|
|
|
|
Expect(err).NotTo(HaveOccurred())
|
|
|
|
Expect(id).To(Equal("3-0"))
|
2018-08-02 14:48:46 +03:00
|
|
|
})
|
2017-11-25 05:06:13 +03:00
|
|
|
|
2018-08-02 14:48:46 +03:00
|
|
|
It("should XTrim", func() {
|
|
|
|
n, err := client.XTrim("stream", 0).Result()
|
|
|
|
Expect(err).NotTo(HaveOccurred())
|
|
|
|
Expect(n).To(Equal(int64(3)))
|
|
|
|
})
|
2017-11-25 05:06:13 +03:00
|
|
|
|
2018-08-02 14:48:46 +03:00
|
|
|
It("should XTrimApprox", func() {
|
|
|
|
n, err := client.XTrimApprox("stream", 0).Result()
|
|
|
|
Expect(err).NotTo(HaveOccurred())
|
|
|
|
Expect(n).To(Equal(int64(3)))
|
|
|
|
})
|
|
|
|
|
|
|
|
It("should XAdd", func() {
|
|
|
|
id, err := client.XAdd(&redis.XAddArgs{
|
|
|
|
Stream: "stream",
|
|
|
|
Values: map[string]interface{}{"quatro": "quatre"},
|
2017-11-25 05:06:13 +03:00
|
|
|
}).Result()
|
|
|
|
Expect(err).NotTo(HaveOccurred())
|
|
|
|
|
|
|
|
vals, err := client.XRange("stream", "-", "+").Result()
|
|
|
|
Expect(err).NotTo(HaveOccurred())
|
2018-08-02 14:48:46 +03:00
|
|
|
Expect(vals).To(Equal([]redis.XMessage{
|
2017-11-25 05:06:13 +03:00
|
|
|
{ID: "1-0", Values: map[string]interface{}{"uno": "un"}},
|
|
|
|
{ID: "2-0", Values: map[string]interface{}{"dos": "deux"}},
|
|
|
|
{ID: "3-0", Values: map[string]interface{}{"tres": "troix"}},
|
|
|
|
{ID: id, Values: map[string]interface{}{"quatro": "quatre"}},
|
|
|
|
}))
|
|
|
|
})
|
|
|
|
|
2018-08-02 14:48:46 +03:00
|
|
|
It("should XAdd with MaxLen", func() {
|
|
|
|
id, err := client.XAdd(&redis.XAddArgs{
|
2017-11-25 05:06:13 +03:00
|
|
|
Stream: "stream",
|
|
|
|
MaxLen: 1,
|
|
|
|
Values: map[string]interface{}{"quatro": "quatre"},
|
|
|
|
}).Result()
|
|
|
|
Expect(err).NotTo(HaveOccurred())
|
|
|
|
|
|
|
|
vals, err := client.XRange("stream", "-", "+").Result()
|
|
|
|
Expect(err).NotTo(HaveOccurred())
|
2018-08-02 14:48:46 +03:00
|
|
|
Expect(vals).To(Equal([]redis.XMessage{
|
2017-11-25 05:06:13 +03:00
|
|
|
{ID: id, Values: map[string]interface{}{"quatro": "quatre"}},
|
|
|
|
}))
|
|
|
|
})
|
|
|
|
|
2018-11-13 15:22:50 +03:00
|
|
|
It("should XDel", func() {
|
|
|
|
n, err := client.XDel("stream", "1-0", "2-0", "3-0").Result()
|
|
|
|
Expect(err).NotTo(HaveOccurred())
|
|
|
|
Expect(n).To(Equal(int64(3)))
|
|
|
|
})
|
|
|
|
|
2017-11-25 05:06:13 +03:00
|
|
|
It("should XLen", func() {
|
|
|
|
n, err := client.XLen("stream").Result()
|
|
|
|
Expect(err).NotTo(HaveOccurred())
|
|
|
|
Expect(n).To(Equal(int64(3)))
|
|
|
|
})
|
|
|
|
|
|
|
|
It("should XRange", func() {
|
|
|
|
msgs, err := client.XRange("stream", "-", "+").Result()
|
|
|
|
Expect(err).NotTo(HaveOccurred())
|
2018-08-02 14:48:46 +03:00
|
|
|
Expect(msgs).To(Equal([]redis.XMessage{
|
2017-11-25 05:06:13 +03:00
|
|
|
{ID: "1-0", Values: map[string]interface{}{"uno": "un"}},
|
|
|
|
{ID: "2-0", Values: map[string]interface{}{"dos": "deux"}},
|
|
|
|
{ID: "3-0", Values: map[string]interface{}{"tres": "troix"}},
|
|
|
|
}))
|
|
|
|
|
|
|
|
msgs, err = client.XRange("stream", "2", "+").Result()
|
|
|
|
Expect(err).NotTo(HaveOccurred())
|
2018-08-02 14:48:46 +03:00
|
|
|
Expect(msgs).To(Equal([]redis.XMessage{
|
2017-11-25 05:06:13 +03:00
|
|
|
{ID: "2-0", Values: map[string]interface{}{"dos": "deux"}},
|
|
|
|
{ID: "3-0", Values: map[string]interface{}{"tres": "troix"}},
|
|
|
|
}))
|
|
|
|
|
|
|
|
msgs, err = client.XRange("stream", "-", "2").Result()
|
|
|
|
Expect(err).NotTo(HaveOccurred())
|
2018-08-02 14:48:46 +03:00
|
|
|
Expect(msgs).To(Equal([]redis.XMessage{
|
2017-11-25 05:06:13 +03:00
|
|
|
{ID: "1-0", Values: map[string]interface{}{"uno": "un"}},
|
|
|
|
{ID: "2-0", Values: map[string]interface{}{"dos": "deux"}},
|
|
|
|
}))
|
|
|
|
})
|
|
|
|
|
|
|
|
It("should XRangeN", func() {
|
|
|
|
msgs, err := client.XRangeN("stream", "-", "+", 2).Result()
|
|
|
|
Expect(err).NotTo(HaveOccurred())
|
2018-08-02 14:48:46 +03:00
|
|
|
Expect(msgs).To(Equal([]redis.XMessage{
|
2017-11-25 05:06:13 +03:00
|
|
|
{ID: "1-0", Values: map[string]interface{}{"uno": "un"}},
|
|
|
|
{ID: "2-0", Values: map[string]interface{}{"dos": "deux"}},
|
|
|
|
}))
|
|
|
|
|
|
|
|
msgs, err = client.XRangeN("stream", "2", "+", 1).Result()
|
|
|
|
Expect(err).NotTo(HaveOccurred())
|
2018-08-02 14:48:46 +03:00
|
|
|
Expect(msgs).To(Equal([]redis.XMessage{
|
2017-11-25 05:06:13 +03:00
|
|
|
{ID: "2-0", Values: map[string]interface{}{"dos": "deux"}},
|
|
|
|
}))
|
|
|
|
|
|
|
|
msgs, err = client.XRangeN("stream", "-", "2", 1).Result()
|
|
|
|
Expect(err).NotTo(HaveOccurred())
|
2018-08-02 14:48:46 +03:00
|
|
|
Expect(msgs).To(Equal([]redis.XMessage{
|
2017-11-25 05:06:13 +03:00
|
|
|
{ID: "1-0", Values: map[string]interface{}{"uno": "un"}},
|
|
|
|
}))
|
|
|
|
})
|
|
|
|
|
|
|
|
It("should XRevRange", func() {
|
|
|
|
msgs, err := client.XRevRange("stream", "+", "-").Result()
|
|
|
|
Expect(err).NotTo(HaveOccurred())
|
2018-08-02 14:48:46 +03:00
|
|
|
Expect(msgs).To(Equal([]redis.XMessage{
|
2017-11-25 05:06:13 +03:00
|
|
|
{ID: "3-0", Values: map[string]interface{}{"tres": "troix"}},
|
|
|
|
{ID: "2-0", Values: map[string]interface{}{"dos": "deux"}},
|
|
|
|
{ID: "1-0", Values: map[string]interface{}{"uno": "un"}},
|
|
|
|
}))
|
|
|
|
|
|
|
|
msgs, err = client.XRevRange("stream", "+", "2").Result()
|
|
|
|
Expect(err).NotTo(HaveOccurred())
|
2018-08-02 14:48:46 +03:00
|
|
|
Expect(msgs).To(Equal([]redis.XMessage{
|
2017-11-25 05:06:13 +03:00
|
|
|
{ID: "3-0", Values: map[string]interface{}{"tres": "troix"}},
|
|
|
|
{ID: "2-0", Values: map[string]interface{}{"dos": "deux"}},
|
|
|
|
}))
|
|
|
|
})
|
|
|
|
|
|
|
|
It("should XRevRangeN", func() {
|
|
|
|
msgs, err := client.XRevRangeN("stream", "+", "-", 2).Result()
|
|
|
|
Expect(err).NotTo(HaveOccurred())
|
2018-08-02 14:48:46 +03:00
|
|
|
Expect(msgs).To(Equal([]redis.XMessage{
|
2017-11-25 05:06:13 +03:00
|
|
|
{ID: "3-0", Values: map[string]interface{}{"tres": "troix"}},
|
|
|
|
{ID: "2-0", Values: map[string]interface{}{"dos": "deux"}},
|
|
|
|
}))
|
|
|
|
|
|
|
|
msgs, err = client.XRevRangeN("stream", "+", "2", 1).Result()
|
|
|
|
Expect(err).NotTo(HaveOccurred())
|
2018-08-02 14:48:46 +03:00
|
|
|
Expect(msgs).To(Equal([]redis.XMessage{
|
2017-11-25 05:06:13 +03:00
|
|
|
{ID: "3-0", Values: map[string]interface{}{"tres": "troix"}},
|
|
|
|
}))
|
|
|
|
})
|
|
|
|
|
|
|
|
It("should XRead", func() {
|
2018-08-02 14:48:46 +03:00
|
|
|
res, err := client.XReadStreams("stream", "0").Result()
|
2017-11-25 05:06:13 +03:00
|
|
|
Expect(err).NotTo(HaveOccurred())
|
2018-08-02 14:48:46 +03:00
|
|
|
Expect(res).To(Equal([]redis.XStream{{
|
2017-11-25 05:06:13 +03:00
|
|
|
Stream: "stream",
|
2018-08-02 14:48:46 +03:00
|
|
|
Messages: []redis.XMessage{
|
2017-11-25 05:06:13 +03:00
|
|
|
{ID: "1-0", Values: map[string]interface{}{"uno": "un"}},
|
|
|
|
{ID: "2-0", Values: map[string]interface{}{"dos": "deux"}},
|
|
|
|
{ID: "3-0", Values: map[string]interface{}{"tres": "troix"}},
|
|
|
|
}},
|
|
|
|
}))
|
|
|
|
|
2018-08-02 14:48:46 +03:00
|
|
|
_, err = client.XReadStreams("stream", "3").Result()
|
2017-11-25 05:06:13 +03:00
|
|
|
Expect(err).To(Equal(redis.Nil))
|
|
|
|
})
|
|
|
|
|
2018-08-02 14:48:46 +03:00
|
|
|
It("should XRead", func() {
|
|
|
|
res, err := client.XRead(&redis.XReadArgs{
|
2017-11-25 05:06:13 +03:00
|
|
|
Streams: []string{"stream", "0"},
|
|
|
|
Count: 2,
|
|
|
|
Block: 100 * time.Millisecond,
|
|
|
|
}).Result()
|
|
|
|
Expect(err).NotTo(HaveOccurred())
|
2018-08-02 14:48:46 +03:00
|
|
|
Expect(res).To(Equal([]redis.XStream{{
|
2017-11-25 05:06:13 +03:00
|
|
|
Stream: "stream",
|
2018-08-02 14:48:46 +03:00
|
|
|
Messages: []redis.XMessage{
|
2017-11-25 05:06:13 +03:00
|
|
|
{ID: "1-0", Values: map[string]interface{}{"uno": "un"}},
|
|
|
|
{ID: "2-0", Values: map[string]interface{}{"dos": "deux"}},
|
|
|
|
}},
|
|
|
|
}))
|
|
|
|
|
2018-08-02 14:48:46 +03:00
|
|
|
_, err = client.XRead(&redis.XReadArgs{
|
2017-11-25 05:06:13 +03:00
|
|
|
Streams: []string{"stream", "3"},
|
|
|
|
Count: 1,
|
|
|
|
Block: 100 * time.Millisecond,
|
|
|
|
}).Result()
|
|
|
|
Expect(err).To(Equal(redis.Nil))
|
|
|
|
})
|
2018-08-02 14:48:46 +03:00
|
|
|
|
|
|
|
Describe("group", func() {
|
|
|
|
BeforeEach(func() {
|
|
|
|
err := client.XGroupCreate("stream", "group", "0").Err()
|
|
|
|
Expect(err).NotTo(HaveOccurred())
|
|
|
|
|
|
|
|
res, err := client.XReadGroup(&redis.XReadGroupArgs{
|
|
|
|
Group: "group",
|
|
|
|
Consumer: "consumer",
|
2018-11-21 12:09:21 +03:00
|
|
|
Streams: []string{"stream", ">"},
|
2018-08-02 14:48:46 +03:00
|
|
|
}).Result()
|
2018-11-21 12:09:21 +03:00
|
|
|
Expect(err).NotTo(HaveOccurred())
|
2018-08-02 14:48:46 +03:00
|
|
|
Expect(res).To(Equal([]redis.XStream{{
|
|
|
|
Stream: "stream",
|
|
|
|
Messages: []redis.XMessage{
|
|
|
|
{ID: "1-0", Values: map[string]interface{}{"uno": "un"}},
|
|
|
|
{ID: "2-0", Values: map[string]interface{}{"dos": "deux"}},
|
|
|
|
{ID: "3-0", Values: map[string]interface{}{"tres": "troix"}},
|
|
|
|
}},
|
|
|
|
}))
|
|
|
|
})
|
|
|
|
|
|
|
|
AfterEach(func() {
|
|
|
|
n, err := client.XGroupDestroy("stream", "group").Result()
|
|
|
|
Expect(err).NotTo(HaveOccurred())
|
|
|
|
Expect(n).To(Equal(int64(1)))
|
|
|
|
})
|
|
|
|
|
|
|
|
It("should XPending", func() {
|
|
|
|
info, err := client.XPending("stream", "group").Result()
|
|
|
|
Expect(err).NotTo(HaveOccurred())
|
|
|
|
Expect(info).To(Equal(&redis.XPending{
|
|
|
|
Count: 3,
|
|
|
|
Lower: "1-0",
|
|
|
|
Higher: "3-0",
|
|
|
|
Consumers: map[string]int64{"consumer": 3},
|
|
|
|
}))
|
|
|
|
|
|
|
|
infoExt, err := client.XPendingExt(&redis.XPendingExtArgs{
|
|
|
|
Stream: "stream",
|
|
|
|
Group: "group",
|
|
|
|
Start: "-",
|
|
|
|
End: "+",
|
|
|
|
Count: 10,
|
|
|
|
Consumer: "consumer",
|
|
|
|
}).Result()
|
|
|
|
Expect(err).NotTo(HaveOccurred())
|
|
|
|
for i := range infoExt {
|
|
|
|
infoExt[i].Idle = 0
|
|
|
|
}
|
|
|
|
Expect(infoExt).To(Equal([]redis.XPendingExt{
|
|
|
|
{Id: "1-0", Consumer: "consumer", Idle: 0, RetryCount: 1},
|
|
|
|
{Id: "2-0", Consumer: "consumer", Idle: 0, RetryCount: 1},
|
|
|
|
{Id: "3-0", Consumer: "consumer", Idle: 0, RetryCount: 1},
|
|
|
|
}))
|
|
|
|
|
|
|
|
n, err := client.XGroupDelConsumer("stream", "group", "consumer").Result()
|
|
|
|
Expect(err).NotTo(HaveOccurred())
|
|
|
|
Expect(n).To(Equal(int64(3)))
|
|
|
|
})
|
|
|
|
|
|
|
|
It("should XClaim", func() {
|
|
|
|
msgs, err := client.XClaim(&redis.XClaimArgs{
|
|
|
|
Stream: "stream",
|
|
|
|
Group: "group",
|
|
|
|
Consumer: "consumer",
|
|
|
|
Messages: []string{"1-0", "2-0", "3-0"},
|
|
|
|
}).Result()
|
|
|
|
Expect(err).NotTo(HaveOccurred())
|
|
|
|
Expect(msgs).To(Equal([]redis.XMessage{{
|
|
|
|
ID: "1-0",
|
|
|
|
Values: map[string]interface{}{"uno": "un"},
|
|
|
|
}, {
|
|
|
|
ID: "2-0",
|
|
|
|
Values: map[string]interface{}{"dos": "deux"},
|
|
|
|
}, {
|
|
|
|
ID: "3-0",
|
|
|
|
Values: map[string]interface{}{"tres": "troix"},
|
|
|
|
}}))
|
|
|
|
|
|
|
|
ids, err := client.XClaimJustID(&redis.XClaimArgs{
|
|
|
|
Stream: "stream",
|
|
|
|
Group: "group",
|
|
|
|
Consumer: "consumer",
|
|
|
|
Messages: []string{"1-0", "2-0", "3-0"},
|
|
|
|
}).Result()
|
|
|
|
Expect(err).NotTo(HaveOccurred())
|
|
|
|
Expect(ids).To(Equal([]string{"1-0", "2-0", "3-0"}))
|
|
|
|
})
|
|
|
|
|
|
|
|
It("should XAck", func() {
|
|
|
|
n, err := client.XAck("stream", "group", "1-0", "2-0", "4-0").Result()
|
|
|
|
Expect(err).NotTo(HaveOccurred())
|
|
|
|
Expect(n).To(Equal(int64(2)))
|
|
|
|
})
|
|
|
|
})
|
2017-11-25 05:06:13 +03:00
|
|
|
})
|
|
|
|
|
2015-09-20 16:13:13 +03:00
|
|
|
Describe("Geo add and radius search", func() {
|
2015-11-14 17:36:21 +03:00
|
|
|
BeforeEach(func() {
|
2018-08-02 14:48:46 +03:00
|
|
|
n, err := client.GeoAdd(
|
2015-10-15 00:39:39 +03:00
|
|
|
"Sicily",
|
|
|
|
&redis.GeoLocation{Longitude: 13.361389, Latitude: 38.115556, Name: "Palermo"},
|
|
|
|
&redis.GeoLocation{Longitude: 15.087269, Latitude: 37.502669, Name: "Catania"},
|
2018-08-02 14:48:46 +03:00
|
|
|
).Result()
|
|
|
|
Expect(err).NotTo(HaveOccurred())
|
|
|
|
Expect(n).To(Equal(int64(2)))
|
2015-09-20 16:13:13 +03:00
|
|
|
})
|
|
|
|
|
2015-11-14 17:36:21 +03:00
|
|
|
It("should not add same geo location", func() {
|
2015-10-15 00:39:39 +03:00
|
|
|
geoAdd := client.GeoAdd(
|
|
|
|
"Sicily",
|
|
|
|
&redis.GeoLocation{Longitude: 13.361389, Latitude: 38.115556, Name: "Palermo"},
|
|
|
|
)
|
2015-09-20 16:13:13 +03:00
|
|
|
Expect(geoAdd.Err()).NotTo(HaveOccurred())
|
2015-11-14 17:36:21 +03:00
|
|
|
Expect(geoAdd.Val()).To(Equal(int64(0)))
|
|
|
|
})
|
2015-09-20 16:13:13 +03:00
|
|
|
|
2015-11-14 17:36:21 +03:00
|
|
|
It("should search geo radius", func() {
|
|
|
|
res, err := client.GeoRadius("Sicily", 15, 37, &redis.GeoRadiusQuery{
|
|
|
|
Radius: 200,
|
|
|
|
}).Result()
|
2015-10-15 00:39:39 +03:00
|
|
|
Expect(err).NotTo(HaveOccurred())
|
|
|
|
Expect(res).To(HaveLen(2))
|
|
|
|
Expect(res[0].Name).To(Equal("Palermo"))
|
|
|
|
Expect(res[1].Name).To(Equal("Catania"))
|
2015-09-20 16:13:13 +03:00
|
|
|
})
|
|
|
|
|
|
|
|
It("should search geo radius with options", func() {
|
2015-10-15 00:39:39 +03:00
|
|
|
res, err := client.GeoRadius("Sicily", 15, 37, &redis.GeoRadiusQuery{
|
|
|
|
Radius: 200,
|
|
|
|
Unit: "km",
|
|
|
|
WithGeoHash: true,
|
|
|
|
WithCoord: true,
|
|
|
|
WithDist: true,
|
|
|
|
Count: 2,
|
|
|
|
Sort: "ASC",
|
|
|
|
}).Result()
|
|
|
|
Expect(err).NotTo(HaveOccurred())
|
|
|
|
Expect(res).To(HaveLen(2))
|
|
|
|
Expect(res[1].Name).To(Equal("Palermo"))
|
2015-11-14 17:36:21 +03:00
|
|
|
Expect(res[1].Dist).To(Equal(190.4424))
|
2015-10-15 00:39:39 +03:00
|
|
|
Expect(res[1].GeoHash).To(Equal(int64(3479099956230698)))
|
|
|
|
Expect(res[1].Longitude).To(Equal(13.361389338970184))
|
|
|
|
Expect(res[1].Latitude).To(Equal(38.115556395496299))
|
|
|
|
Expect(res[0].Name).To(Equal("Catania"))
|
2015-11-14 17:36:21 +03:00
|
|
|
Expect(res[0].Dist).To(Equal(56.4413))
|
2015-10-15 00:39:39 +03:00
|
|
|
Expect(res[0].GeoHash).To(Equal(int64(3479447370796909)))
|
|
|
|
Expect(res[0].Longitude).To(Equal(15.087267458438873))
|
|
|
|
Expect(res[0].Latitude).To(Equal(37.50266842333162))
|
|
|
|
})
|
|
|
|
|
2015-11-14 17:36:21 +03:00
|
|
|
It("should search geo radius with WithDist=false", func() {
|
|
|
|
res, err := client.GeoRadius("Sicily", 15, 37, &redis.GeoRadiusQuery{
|
|
|
|
Radius: 200,
|
|
|
|
Unit: "km",
|
|
|
|
WithGeoHash: true,
|
|
|
|
WithCoord: true,
|
|
|
|
Count: 2,
|
|
|
|
Sort: "ASC",
|
|
|
|
}).Result()
|
|
|
|
Expect(err).NotTo(HaveOccurred())
|
|
|
|
Expect(res).To(HaveLen(2))
|
|
|
|
Expect(res[1].Name).To(Equal("Palermo"))
|
|
|
|
Expect(res[1].Dist).To(Equal(float64(0)))
|
|
|
|
Expect(res[1].GeoHash).To(Equal(int64(3479099956230698)))
|
|
|
|
Expect(res[1].Longitude).To(Equal(13.361389338970184))
|
|
|
|
Expect(res[1].Latitude).To(Equal(38.115556395496299))
|
|
|
|
Expect(res[0].Name).To(Equal("Catania"))
|
|
|
|
Expect(res[0].Dist).To(Equal(float64(0)))
|
|
|
|
Expect(res[0].GeoHash).To(Equal(int64(3479447370796909)))
|
|
|
|
Expect(res[0].Longitude).To(Equal(15.087267458438873))
|
|
|
|
Expect(res[0].Latitude).To(Equal(37.50266842333162))
|
|
|
|
})
|
2015-09-20 16:13:13 +03:00
|
|
|
|
2015-11-14 17:36:21 +03:00
|
|
|
It("should search geo radius by member with options", func() {
|
2015-10-15 00:39:39 +03:00
|
|
|
res, err := client.GeoRadiusByMember("Sicily", "Catania", &redis.GeoRadiusQuery{
|
|
|
|
Radius: 200,
|
|
|
|
Unit: "km",
|
|
|
|
WithGeoHash: true,
|
|
|
|
WithCoord: true,
|
|
|
|
WithDist: true,
|
|
|
|
Count: 2,
|
|
|
|
Sort: "ASC",
|
|
|
|
}).Result()
|
|
|
|
Expect(err).NotTo(HaveOccurred())
|
|
|
|
Expect(res).To(HaveLen(2))
|
|
|
|
Expect(res[0].Name).To(Equal("Catania"))
|
2015-11-14 17:36:21 +03:00
|
|
|
Expect(res[0].Dist).To(Equal(0.0))
|
2015-10-15 00:39:39 +03:00
|
|
|
Expect(res[0].GeoHash).To(Equal(int64(3479447370796909)))
|
|
|
|
Expect(res[0].Longitude).To(Equal(15.087267458438873))
|
|
|
|
Expect(res[0].Latitude).To(Equal(37.50266842333162))
|
|
|
|
Expect(res[1].Name).To(Equal("Palermo"))
|
2015-11-14 17:36:21 +03:00
|
|
|
Expect(res[1].Dist).To(Equal(166.2742))
|
2015-10-15 00:39:39 +03:00
|
|
|
Expect(res[1].GeoHash).To(Equal(int64(3479099956230698)))
|
|
|
|
Expect(res[1].Longitude).To(Equal(13.361389338970184))
|
|
|
|
Expect(res[1].Latitude).To(Equal(38.115556395496299))
|
2015-09-20 16:13:13 +03:00
|
|
|
})
|
|
|
|
|
|
|
|
It("should search geo radius with no results", func() {
|
2015-10-15 00:39:39 +03:00
|
|
|
res, err := client.GeoRadius("Sicily", 99, 37, &redis.GeoRadiusQuery{
|
|
|
|
Radius: 200,
|
|
|
|
Unit: "km",
|
|
|
|
WithGeoHash: true,
|
|
|
|
WithCoord: true,
|
|
|
|
WithDist: true,
|
|
|
|
}).Result()
|
|
|
|
Expect(err).NotTo(HaveOccurred())
|
|
|
|
Expect(res).To(HaveLen(0))
|
|
|
|
})
|
|
|
|
|
|
|
|
It("should get geo distance with unit options", func() {
|
|
|
|
// From Redis CLI, note the difference in rounding in m vs
|
|
|
|
// km on Redis itself.
|
|
|
|
//
|
|
|
|
// GEOADD Sicily 13.361389 38.115556 "Palermo" 15.087269 37.502669 "Catania"
|
|
|
|
// GEODIST Sicily Palermo Catania m
|
|
|
|
// "166274.15156960033"
|
|
|
|
// GEODIST Sicily Palermo Catania km
|
|
|
|
// "166.27415156960032"
|
2016-08-22 12:46:42 +03:00
|
|
|
dist, err := client.GeoDist("Sicily", "Palermo", "Catania", "km").Result()
|
|
|
|
Expect(err).NotTo(HaveOccurred())
|
|
|
|
Expect(dist).To(BeNumerically("~", 166.27, 0.01))
|
2015-10-15 00:39:39 +03:00
|
|
|
|
2016-08-22 12:46:42 +03:00
|
|
|
dist, err = client.GeoDist("Sicily", "Palermo", "Catania", "m").Result()
|
|
|
|
Expect(err).NotTo(HaveOccurred())
|
|
|
|
Expect(dist).To(BeNumerically("~", 166274.15, 0.01))
|
2015-09-20 16:13:13 +03:00
|
|
|
})
|
2015-10-15 00:39:39 +03:00
|
|
|
|
|
|
|
It("should get geo hash in string representation", func() {
|
2016-08-22 12:46:42 +03:00
|
|
|
hashes, err := client.GeoHash("Sicily", "Palermo", "Catania").Result()
|
|
|
|
Expect(err).NotTo(HaveOccurred())
|
|
|
|
Expect(hashes).To(ConsistOf([]string{"sqc8b49rny0", "sqdtr74hyu0"}))
|
|
|
|
})
|
|
|
|
|
|
|
|
It("should return geo position", func() {
|
|
|
|
pos, err := client.GeoPos("Sicily", "Palermo", "Catania", "NonExisting").Result()
|
2015-10-15 00:39:39 +03:00
|
|
|
Expect(err).NotTo(HaveOccurred())
|
2016-08-22 12:46:42 +03:00
|
|
|
Expect(pos).To(ConsistOf([]*redis.GeoPos{
|
|
|
|
{
|
|
|
|
Longitude: 13.361389338970184,
|
|
|
|
Latitude: 38.1155563954963,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Longitude: 15.087267458438873,
|
|
|
|
Latitude: 37.50266842333162,
|
|
|
|
},
|
|
|
|
nil,
|
|
|
|
}))
|
2015-10-15 00:39:39 +03:00
|
|
|
})
|
2015-09-20 16:13:13 +03:00
|
|
|
})
|
|
|
|
|
2015-05-28 15:51:19 +03:00
|
|
|
Describe("marshaling/unmarshaling", func() {
|
|
|
|
|
|
|
|
type convTest struct {
|
|
|
|
value interface{}
|
|
|
|
wanted string
|
|
|
|
dest interface{}
|
|
|
|
}
|
|
|
|
|
|
|
|
convTests := []convTest{
|
|
|
|
{nil, "", nil},
|
|
|
|
{"hello", "hello", new(string)},
|
|
|
|
{[]byte("hello"), "hello", new([]byte)},
|
|
|
|
{int(1), "1", new(int)},
|
|
|
|
{int8(1), "1", new(int8)},
|
|
|
|
{int16(1), "1", new(int16)},
|
|
|
|
{int32(1), "1", new(int32)},
|
|
|
|
{int64(1), "1", new(int64)},
|
|
|
|
{uint(1), "1", new(uint)},
|
|
|
|
{uint8(1), "1", new(uint8)},
|
|
|
|
{uint16(1), "1", new(uint16)},
|
|
|
|
{uint32(1), "1", new(uint32)},
|
|
|
|
{uint64(1), "1", new(uint64)},
|
|
|
|
{float32(1.0), "1", new(float32)},
|
|
|
|
{float64(1.0), "1", new(float64)},
|
|
|
|
{true, "1", new(bool)},
|
|
|
|
{false, "0", new(bool)},
|
|
|
|
}
|
|
|
|
|
|
|
|
It("should convert to string", func() {
|
|
|
|
for _, test := range convTests {
|
|
|
|
err := client.Set("key", test.value, 0).Err()
|
|
|
|
Expect(err).NotTo(HaveOccurred())
|
|
|
|
|
|
|
|
s, err := client.Get("key").Result()
|
|
|
|
Expect(err).NotTo(HaveOccurred())
|
|
|
|
Expect(s).To(Equal(test.wanted))
|
|
|
|
|
|
|
|
if test.dest == nil {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
|
|
|
err = client.Get("key").Scan(test.dest)
|
|
|
|
Expect(err).NotTo(HaveOccurred())
|
|
|
|
Expect(deref(test.dest)).To(Equal(test.value))
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
Describe("json marshaling/unmarshaling", func() {
|
2016-05-06 21:12:31 +03:00
|
|
|
|
2015-05-28 15:51:19 +03:00
|
|
|
BeforeEach(func() {
|
|
|
|
value := &numberStruct{Number: 42}
|
|
|
|
err := client.Set("key", value, 0).Err()
|
|
|
|
Expect(err).NotTo(HaveOccurred())
|
|
|
|
})
|
|
|
|
|
|
|
|
It("should marshal custom values using json", func() {
|
|
|
|
s, err := client.Get("key").Result()
|
|
|
|
Expect(err).NotTo(HaveOccurred())
|
|
|
|
Expect(s).To(Equal(`{"Number":42}`))
|
|
|
|
})
|
|
|
|
|
|
|
|
It("should scan custom values using json", func() {
|
|
|
|
value := &numberStruct{}
|
|
|
|
err := client.Get("key").Scan(value)
|
2016-05-06 21:12:31 +03:00
|
|
|
Expect(err).NotTo(HaveOccurred())
|
2015-05-28 15:51:19 +03:00
|
|
|
Expect(value.Number).To(Equal(42))
|
|
|
|
})
|
|
|
|
|
|
|
|
})
|
|
|
|
|
2017-01-03 13:21:22 +03:00
|
|
|
Describe("Eval", func() {
|
|
|
|
|
|
|
|
It("returns keys and values", func() {
|
|
|
|
vals, err := client.Eval(
|
|
|
|
"return {KEYS[1],ARGV[1]}",
|
|
|
|
[]string{"key"},
|
|
|
|
"hello",
|
|
|
|
).Result()
|
|
|
|
Expect(err).NotTo(HaveOccurred())
|
|
|
|
Expect(vals).To(Equal([]interface{}{"key", "hello"}))
|
|
|
|
})
|
|
|
|
|
2018-02-16 14:39:56 +03:00
|
|
|
It("returns all values after an error", func() {
|
|
|
|
vals, err := client.Eval(
|
|
|
|
`return {12, {err="error"}, "abc"}`,
|
|
|
|
nil,
|
|
|
|
).Result()
|
|
|
|
Expect(err).NotTo(HaveOccurred())
|
2018-02-22 15:14:30 +03:00
|
|
|
Expect(vals).To(Equal([]interface{}{int64(12), proto.RedisError("error"), "abc"}))
|
2018-02-16 14:39:56 +03:00
|
|
|
})
|
|
|
|
|
2017-01-03 13:21:22 +03:00
|
|
|
})
|
|
|
|
|
2015-01-15 18:51:22 +03:00
|
|
|
})
|
2015-05-28 15:51:19 +03:00
|
|
|
|
|
|
|
type numberStruct struct {
|
|
|
|
Number int
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *numberStruct) MarshalBinary() ([]byte, error) {
|
|
|
|
return json.Marshal(s)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *numberStruct) UnmarshalBinary(b []byte) error {
|
|
|
|
return json.Unmarshal(b, s)
|
|
|
|
}
|
|
|
|
|
|
|
|
func deref(viface interface{}) interface{} {
|
|
|
|
v := reflect.ValueOf(viface)
|
|
|
|
for v.Kind() == reflect.Ptr {
|
|
|
|
v = v.Elem()
|
|
|
|
}
|
|
|
|
return v.Interface()
|
|
|
|
}
|