本文整理汇总了Golang中github.com/garyburd/redigo/redis.Int函数的典型用法代码示例。如果您正苦于以下问题:Golang Int函数的具体用法?Golang Int怎么用?Golang Int使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Int函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: TestHashSetNX
func TestHashSetNX(t *testing.T) {
s, err := Run()
ok(t, err)
defer s.Close()
c, err := redis.Dial("tcp", s.Addr())
ok(t, err)
// New Hash
v, err := redis.Int(c.Do("HSETNX", "wim", "zus", "jet"))
ok(t, err)
equals(t, 1, v)
v, err = redis.Int(c.Do("HSETNX", "wim", "zus", "jet"))
ok(t, err)
equals(t, 0, v)
// Just a new key
v, err = redis.Int(c.Do("HSETNX", "wim", "aap", "noot"))
ok(t, err)
equals(t, 1, v)
// Wrong key type
s.Set("foo", "bar")
_, err = redis.Int(c.Do("HSETNX", "foo", "nosuch", "nosuch"))
assert(t, err != nil, "no HSETNX error")
}
开发者ID:Goyoo,项目名称:codis-docker,代码行数:26,代码来源:cmd_hash_test.go
示例2: CreateURL
// creates the requested shortened URL
func CreateURL(conn redis.Conn, longURL string, shortURL string) (string, error) {
// randomly assign URL if not given
if shortURL == "" {
for { // loop until unique string
shortURL = randURL()
v, err := redis.Int(conn.Do("EXISTS", shortURL))
if err == nil && v == 0 {
break
}
}
} else { // confirm that URL is free
v, err := redis.Int(conn.Do("EXISTS", shortURL))
if err != nil {
return "", err
} else if v == 1 {
return "", UrlInUse
}
}
// create hash record
v, err := redis.String(conn.Do("HMSET", shortURL, LONG, longURL, COUNT, 0))
if v != "OK" || err != nil {
return "", err
}
return shortURL, err
}
开发者ID:natebrennand,项目名称:shrtnr,代码行数:27,代码来源:shrink.go
示例3: TestHashExists
func TestHashExists(t *testing.T) {
s, err := Run()
ok(t, err)
defer s.Close()
c, err := redis.Dial("tcp", s.Addr())
ok(t, err)
s.HSet("wim", "zus", "jet")
s.HSet("wim", "teun", "vuur")
v, err := redis.Int(c.Do("HEXISTS", "wim", "zus"))
ok(t, err)
equals(t, 1, v)
v, err = redis.Int(c.Do("HEXISTS", "wim", "nosuch"))
ok(t, err)
equals(t, 0, v)
v, err = redis.Int(c.Do("HEXISTS", "nosuch", "nosuch"))
ok(t, err)
equals(t, 0, v)
// Wrong key type
s.Set("foo", "bar")
_, err = redis.Int(c.Do("HEXISTS", "foo", "nosuch"))
assert(t, err != nil, "no HDEL error")
}
开发者ID:Goyoo,项目名称:codis-docker,代码行数:26,代码来源:cmd_hash_test.go
示例4: TestUnsetTwoCNames
func (s *S) TestUnsetTwoCNames(c *check.C) {
router := hipacheRouter{prefix: "hipache"}
err := router.AddBackend("myapp")
c.Assert(err, check.IsNil)
err = router.SetCName("myapp.com", "myapp")
c.Assert(err, check.IsNil)
cnames, err := redis.Int(conn.Do("LLEN", "cname:myapp"))
c.Assert(err, check.IsNil)
c.Assert(1, check.Equals, cnames)
err = router.SetCName("myapptwo.com", "myapp")
c.Assert(err, check.IsNil)
cnames, err = redis.Int(conn.Do("LLEN", "cname:myapp"))
c.Assert(err, check.IsNil)
c.Assert(2, check.Equals, cnames)
err = router.UnsetCName("myapp.com", "myapp")
c.Assert(err, check.IsNil)
cnames, err = redis.Int(conn.Do("LLEN", "cname:myapp"))
c.Assert(err, check.IsNil)
c.Assert(1, check.Equals, cnames)
err = router.UnsetCName("myapptwo.com", "myapp")
c.Assert(err, check.IsNil)
cnames, err = redis.Int(conn.Do("LLEN", "cname:myapp"))
c.Assert(err, check.IsNil)
c.Assert(0, check.Equals, cnames)
}
开发者ID:zhenruyan,项目名称:tsuru,代码行数:25,代码来源:router_test.go
示例5: CreateUser
func (db *DB) CreateUser(login, name string) (int, error) {
// allocate a connection
c := db.Get()
defer c.Close()
// check if username is taken
if exists, err := redis.Int(c.Do("HEXISTS", "users:", login)); err != nil || exists == 1 {
return -1, err
}
// increment global user count
id, err := redis.Int(c.Do("INCR", "user:id"))
if err != nil {
return -1, err
}
// we want to do a transaction so we use MULTI cmd1 cmd2 ... EXEC
c.Do("MULTI")
// register the username to the uid
c.Do("HSET", "users:", login, id)
// set fields for user structure
c.Do("HMSET", "user:"+strconv.Itoa(id), "login", login,
"id", id, "name", name, "followers", "0", "following", "0",
"posts", "0", "signup", time.Now().Unix())
if _, err := c.Do("EXEC"); err != nil {
return -1, err
}
return id, nil
}
开发者ID:yungyikim,项目名称:simple,代码行数:29,代码来源:db.go
示例6: Queue
func (this *tallySubscriberImpl) Queue(queue string, inbound <-chan interface{}) {
go func() {
var queueLength int = 0
var err error
queueLength, _ = redis.Int(this.queue.Do("LLEN", queue))
for {
select {
case message := <-inbound:
if queueLength >= this.settings.MaxQueueLength {
// do a read of the length in the hope that at some point the queue starts to drain
queueLength, err = redis.Int(this.queue.Do("LLEN", queue))
if err != nil {
glog.Warningln("error-llen", queue, err, this.settings)
}
if queueLength >= this.settings.MaxQueueLength {
glog.Warningln("queue-length-exceeds-limit", this.settings.MaxQueueLength, queueLength)
// drop the message
continue
}
}
queueLength, err = redis.Int(this.queue.Do("LPUSH", queue, message))
if err != nil {
glog.Warningln("error-lpush", queue, err, this.settings)
}
case stop := <-this.stop:
if stop {
return
}
}
}
}()
}
开发者ID:qorio,项目名称:omni,代码行数:32,代码来源:subscriber.go
示例7: addResultsToWinsAndLosses
func addResultsToWinsAndLosses(resultString string, gameSessionPair lib.GameSessionPair, r redis.Conn) {
var winningIndex, losingIndex int
if resultString == "tie" {
_, err := redis.Int(r.Do("SADD", gameSessionPair[0].GetTieRedisKey(), gameSessionPair[1].ID.Hex()))
if err != nil {
panic(err)
}
_, err = redis.Int(r.Do("SADD", gameSessionPair[1].GetTieRedisKey(), gameSessionPair[0].ID.Hex()))
if err != nil {
panic(err)
}
} else {
switch resultString {
case "humans":
winningIndex = 0
losingIndex = 1
case "ogres":
winningIndex = 1
losingIndex = 0
default:
fmt.Println("You screwed up with the switch, buddy")
}
_, err := redis.Int(r.Do("SADD", gameSessionPair[winningIndex].GetWinningRedisKey(), gameSessionPair[losingIndex].ID.Hex()))
if err != nil {
panic(err)
}
_, err = redis.Int(r.Do("SADD", gameSessionPair[losingIndex].GetLosingRedisKey(), gameSessionPair[winningIndex].ID.Hex()))
if err != nil {
panic(err)
}
}
}
开发者ID:schmatz,项目名称:coco-verify,代码行数:35,代码来源:client.go
示例8: TestZSetRank
func TestZSetRank(t *testing.T) {
startTestApp()
c := getTestConn()
defer c.Close()
key := []byte("myzset")
if _, err := redis.Int(c.Do("zadd", key, 1, "a", 2, "b", 3, "c", 4, "d")); err != nil {
t.Fatal(err)
}
if n, err := redis.Int(c.Do("zrank", key, "c")); err != nil {
t.Fatal(err)
} else if n != 2 {
t.Fatal(n)
}
if _, err := redis.Int(c.Do("zrank", key, "e")); err != redis.ErrNil {
t.Fatal(err)
}
if n, err := redis.Int(c.Do("zrevrank", key, "c")); err != nil {
t.Fatal(err)
} else if n != 1 {
t.Fatal(n)
}
if _, err := redis.Int(c.Do("zrevrank", key, "e")); err != redis.ErrNil {
t.Fatal(err)
}
}
开发者ID:nodephp,项目名称:ledisdb,代码行数:31,代码来源:cmd_zset_test.go
示例9: GetLength
// 返回名称为key的list的长度
func (this *RedisListHelper) GetLength(key string) int {
var (
n int
err error
)
if atomic.CompareAndSwapInt32(&this.readMark1, 0, 1) {
n, err = redis.Int(this.readCon1.Do("LLEN", key))
atomic.StoreInt32(&this.readMark1, 0)
} else if atomic.CompareAndSwapInt32(&this.readMark2, 0, 1) {
n, err = redis.Int(this.readCon2.Do("LLEN", key))
atomic.StoreInt32(&this.readMark2, 0)
} else if atomic.CompareAndSwapInt32(&this.readMark3, 0, 1) {
n, err = redis.Int(this.readCon3.Do("LLEN", key))
atomic.StoreInt32(&this.readMark3, 0)
} else if atomic.CompareAndSwapInt32(&this.readMark4, 0, 1) {
n, err = redis.Int(this.readCon4.Do("LLEN", key))
atomic.StoreInt32(&this.readMark4, 0)
}
if err != nil {
return 0
}
return n
}
开发者ID:cautonwong,项目名称:chatserver,代码行数:29,代码来源:redislist.go
示例10: TestListMPush
func TestListMPush(t *testing.T) {
startTestApp()
c := getTestConn()
defer c.Close()
key := []byte("b")
if n, err := redis.Int(c.Do("rpush", key, 1, 2, 3)); err != nil {
t.Fatal(err)
} else if n != 3 {
t.Fatal(n)
}
if err := testListRange(key, 0, 3, 1, 2, 3); err != nil {
t.Fatal(err)
}
if n, err := redis.Int(c.Do("lpush", key, 1, 2, 3)); err != nil {
t.Fatal(err)
} else if n != 6 {
t.Fatal(n)
}
if err := testListRange(key, 0, 6, 3, 2, 1, 1, 2, 3); err != nil {
t.Fatal(err)
}
}
开发者ID:nodephp,项目名称:ledisdb,代码行数:26,代码来源:cmd_list_test.go
示例11: GetMsgNum
// 获取uuid的离线消息数量
func GetMsgNum(uuid string) int {
var (
n int
err error
)
if atomic.CompareAndSwapInt32(&offlinemsg_readMark1, 0, 1) {
n, err = redis.Int(offlinemsg_readCon1.Do("LLEN", uuid))
atomic.StoreInt32(&offlinemsg_readMark1, 0)
} else if atomic.CompareAndSwapInt32(&offlinemsg_readMark2, 0, 1) {
n, err = redis.Int(offlinemsg_readCon2.Do("LLEN", uuid))
atomic.StoreInt32(&offlinemsg_readMark2, 0)
} else if atomic.CompareAndSwapInt32(&offlinemsg_readMark3, 0, 1) {
n, err = redis.Int(offlinemsg_readCon3.Do("LLEN", uuid))
atomic.StoreInt32(&offlinemsg_readMark3, 0)
} else if atomic.CompareAndSwapInt32(&offlinemsg_readMark4, 0, 1) {
n, err = redis.Int(offlinemsg_readCon4.Do("LLEN", uuid))
atomic.StoreInt32(&offlinemsg_readMark4, 0)
}
if err != nil {
return 0
}
return n
}
开发者ID:neutony,项目名称:chatserver,代码行数:30,代码来源:offlinemsg.go
示例12: TestEnqueue
func TestEnqueue(t *testing.T) {
conn := pool.Get()
defer conn.Close()
job.Enqueue(pool)
expected := fmt.Sprintf(`{"jid":"%s","retry":false,"queue":"default","class":"HardWorder","args":[],"enqueued_at":%d}`,
job.JID,
job.EnqueuedAt)
actual := job.toJSON()
if expected != actual {
t.Errorf("Excepted JSON to be %s, got %s", expected, job.toJSON())
}
count, _ := redis.Int(conn.Do("SISMEMBER", "queues", job.Queue))
if count != 1 {
t.Error("Expected queues list to have the correct queue but didn't found it.")
}
count, _ = redis.Int(conn.Do("LLEN", "queue:default"))
if count != 1 {
t.Errorf("Expected the queue to have exactly one job but found %d", count)
}
resetRedis(pool)
}
开发者ID:Nitrino,项目名称:gokiq,代码行数:29,代码来源:gokiq_test.go
示例13: TestRedisCache
func TestRedisCache(t *testing.T) {
bm, err := cache.NewCache("redis", `{"conn": "127.0.0.1:6379"}`)
if err != nil {
t.Error("init err")
}
if err = bm.Put("astaxie", 1, 10); err != nil {
t.Error("set Error", err)
}
if !bm.IsExist("astaxie") {
t.Error("check err")
}
time.Sleep(10 * time.Second)
if bm.IsExist("astaxie") {
t.Error("check err")
}
if err = bm.Put("astaxie", 1, 10); err != nil {
t.Error("set Error", err)
}
if v, _ := redis.Int(bm.Get("astaxie"), err); v != 1 {
t.Error("get err")
}
if err = bm.Incr("astaxie"); err != nil {
t.Error("Incr Error", err)
}
if v, _ := redis.Int(bm.Get("astaxie"), err); v != 2 {
t.Error("get err")
}
if err = bm.Decr("astaxie"); err != nil {
t.Error("Decr Error", err)
}
if v, _ := redis.Int(bm.Get("astaxie"), err); v != 1 {
t.Error("get err")
}
bm.Delete("astaxie")
if bm.IsExist("astaxie") {
t.Error("delete err")
}
//test string
if err = bm.Put("astaxie", "author", 10); err != nil {
t.Error("set Error", err)
}
if !bm.IsExist("astaxie") {
t.Error("check err")
}
if v, _ := redis.String(bm.Get("astaxie"), err); v != "author" {
t.Error("get err")
}
// test clear all
if err = bm.ClearAll(); err != nil {
t.Error("clear all err")
}
}
开发者ID:kalbasit,项目名称:beego,代码行数:60,代码来源:redis_test.go
示例14: TestLlen
func TestLlen(t *testing.T) {
s, err := Run()
ok(t, err)
defer s.Close()
c, err := redis.Dial("tcp", s.Addr())
ok(t, err)
s.Push("l", "aap", "noot", "mies", "vuur")
{
el, err := redis.Int(c.Do("LLEN", "l"))
ok(t, err)
equals(t, 4, el)
}
// Non exising key
{
el, err := redis.Int(c.Do("LLEN", "nonexisting"))
ok(t, err)
equals(t, 0, el)
}
// Wrong type of key
{
_, err := redis.String(c.Do("SET", "str", "value"))
ok(t, err)
_, err = redis.Int(c.Do("LLEN", "str"))
assert(t, err != nil, "LLEN error")
// Too many arguments
_, err = redis.String(c.Do("LLEN", "too", "many"))
assert(t, err != nil, "LLEN error")
}
}
开发者ID:Goyoo,项目名称:codis-docker,代码行数:33,代码来源:cmd_list_test.go
示例15: TestHLen
func TestHLen(t *testing.T) {
c := NewFakeRedis()
c.Do("HSET", "foo", "k1", "v1")
c.Do("HSET", "foo", "k2", "v2")
assertInt(t, must(redis.Int(c.Do("HLEN", "foo"))), 2)
assertInt(t, must(redis.Int(c.Do("HLEN", "empty"))), 0)
}
开发者ID:gmlexx,项目名称:redigomock,代码行数:7,代码来源:fake_test.go
示例16: ScheduledSpec
func ScheduledSpec(c gospec.Context) {
scheduled := newScheduled(RETRY_KEY)
was := Config.namespace
Config.namespace = "prod:"
c.Specify("empties retry queues up to the current time", func() {
conn := Config.Pool.Get()
defer conn.Close()
now := time.Now().Unix()
message1, _ := NewMsg("{\"queue\":\"default\",\"foo\":\"bar1\"}")
message2, _ := NewMsg("{\"queue\":\"myqueue\",\"foo\":\"bar2\"}")
message3, _ := NewMsg("{\"queue\":\"default\",\"foo\":\"bar3\"}")
conn.Do("zadd", "prod:"+RETRY_KEY, now-60, message1.ToJson())
conn.Do("zadd", "prod:"+RETRY_KEY, now-10, message2.ToJson())
conn.Do("zadd", "prod:"+RETRY_KEY, now+60, message3.ToJson())
scheduled.poll(false)
defaultCount, _ := redis.Int(conn.Do("llen", "prod:queue:default"))
myqueueCount, _ := redis.Int(conn.Do("llen", "prod:queue:myqueue"))
pending, _ := redis.Int(conn.Do("zcard", "prod:"+RETRY_KEY))
c.Expect(defaultCount, Equals, 1)
c.Expect(myqueueCount, Equals, 1)
c.Expect(pending, Equals, 1)
})
Config.namespace = was
}
开发者ID:neilkinnish,项目名称:go-workers,代码行数:33,代码来源:scheduled_test.go
示例17: groupfetch
func (tc *ExtraIncrTestCase) groupfetch(c1, c2 redis.Conn, key string) int {
r1, e1 := c1.Do("get", key)
r2, e2 := c2.Do("get", key)
if e1 != nil || e2 != nil {
Panic("groupfetch key = %s, e1 = %s, e2 = %s", key, e1, e2)
}
if r1 == nil && r2 == nil {
Panic("groupfetch key = %s, r1 == nil && r2 == nil", key)
}
if r1 != nil && r2 != nil {
Panic("groupfetch key = %s, r1 != nil && r2 != nil, %v %v", key, r1, r2)
}
if r1 != nil {
if v, err := redis.Int(r1, nil); err != nil {
Panic("groupfetch key = %s, error = %s", key, err)
} else {
return v
}
}
if r2 != nil {
if v, err := redis.Int(r2, nil); err != nil {
Panic("groupfetch key = %s, error = %s", key, err)
} else {
return v
}
}
return -1
}
开发者ID:cougar731,项目名称:codis,代码行数:28,代码来源:extra_incr.go
示例18: TestExpireat
func TestExpireat(t *testing.T) {
s, err := Run()
ok(t, err)
defer s.Close()
c, err := redis.Dial("tcp", s.Addr())
ok(t, err)
// Not volatile yet
{
equals(t, 0, s.Expire("foo"))
b, err := redis.Int(c.Do("TTL", "foo"))
ok(t, err)
equals(t, -2, b)
}
// Set something
{
_, err := c.Do("SET", "foo", "bar")
ok(t, err)
// Key exists, but no Expire set yet.
b, err := redis.Int(c.Do("TTL", "foo"))
ok(t, err)
equals(t, -1, b)
n, err := redis.Int(c.Do("EXPIREAT", "foo", 1234567890))
ok(t, err)
equals(t, 1, n) // EXPIREAT returns 1 on success.
equals(t, 1234567890, s.Expire("foo"))
b, err = redis.Int(c.Do("TTL", "foo"))
ok(t, err)
equals(t, 1234567890, b)
equals(t, 1234567890, s.Expire("foo"))
}
}
开发者ID:jameswei,项目名称:xcodis,代码行数:35,代码来源:cmd_generic_test.go
示例19: init
func init() { // connect to Redis on init, and get highest group ID
err := goenv.Load()
if err != nil {
fmt.Println("Missing environment variables file")
panic(err)
}
rC := RedisConnection()
defer rC.Close()
groupSeqValue, err := redis.Int(rC.Do("GET", "id:groups"))
if err != nil {
_, err := rC.Do("SET", "id:groups", 1) // initialize if doesn't exist
ErrorHandler(err)
groupSeqValue = 1
}
gifSeqValue, err := redis.Int(rC.Do("GET", "id:gifs"))
if err != nil {
_, err := rC.Do("SET", "id:gifs", 1) // initialize if doesn't exist
ErrorHandler(err)
gifSeqValue = 1
}
groupSeq = groupSeqValue
gifSeq = gifSeqValue
}
开发者ID:elvingm,项目名称:cc-gif-group-api,代码行数:29,代码来源:main.go
示例20: TestCommonUsingDo
//-----------------------------------------------------------------------------
// Test
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
//EXPIRE(key, seconds), TTL(key), INFO
//-----------------------------------------------------------------------------
func TestCommonUsingDo(t *testing.T) {
//tu.SkipLog(t)
sleepS := 2
c := GetRedis().Conn
c.Do("MSET", "key1", 20, "key2", 30)
c.Do("HMSET", "key3:subkey1", "field1", 1, "field2", 2)
c.Do("HMSET", "key3:subkey2", "field1", 99, "field2", 100)
val, err := redis.Int(c.Do("GET", "key1"))
if err != nil {
t.Errorf("key1 is 10: value is %v, error is %s", val, err)
}
fields, err := redis.Ints(c.Do("HMGET", "key3:subkey1", "field1", "field2"))
if err != nil {
t.Errorf("field1 should be 1, field2 should be 1 but result is %#v, error is %s", fields, err)
}
//EXPIRE
c.Do("EXPIRE", "key1", sleepS)
c.Do("EXPIRE", "key3:subkey1", sleepS)
//TTL
s, err := redis.Int(c.Do("TTL", "key1"))
if err != nil {
t.Errorf("redis.Int(c.Do(\"TTL\", \"key1\")) error : %s", err)
}
lg.Debugf("TTL is %v", s)
//sleep
time.Sleep(time.Duration(sleepS+1) * time.Second)
s, _ = redis.Int(c.Do("TTL", "key1"))
lg.Debugf("TTL is %v", s)
//It can't access
val, err = redis.Int(c.Do("GET", "key1"))
if err == nil {
t.Errorf("key1 has already expired: value is %v", val)
}
//It can't access
//TODO:somehow it can access. but value is 0
fields, err = redis.Ints(c.Do("HMGET", "key3:subkey1", "field1", "field2"))
//if err == nil {
if err != nil || fields[0] != 0 || fields[1] != 0 {
t.Errorf("key3:subkey1 has already expired: value is %+v", fields)
}
//It's OK.
fields, err = redis.Ints(c.Do("HMGET", "key3:subkey2", "field1", "field2"))
if err != nil {
//if err != nil || fields[0] != 99 || fields[1] != 100 {
t.Errorf("field1 should be 99, field2 should be 100 but result is %#v", fields)
}
}
开发者ID:hiromaily,项目名称:golibs,代码行数:65,代码来源:redis_test.go
注:本文中的github.com/garyburd/redigo/redis.Int函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论