本文整理汇总了Golang中github.com/zond/god/client.Conn.MirrorSlice方法的典型用法代码示例。如果您正苦于以下问题:Golang Conn.MirrorSlice方法的具体用法?Golang Conn.MirrorSlice怎么用?Golang Conn.MirrorSlice使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/zond/god/client.Conn
的用法示例。
在下文中一共展示了Conn.MirrorSlice方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: handleUDP
func handleUDP(ch chan []byte, c *client.Conn, queueSize *int32) {
var err error
var mess common.Message
for bytes := range ch {
err = json.Unmarshal(bytes, &mess)
if err == nil {
if mess.Type == common.View {
// Create a byte encoded timestamp for now
t := time.Now().UnixNano()
encT := godCommon.EncodeInt64(t)
// Make the object id active
c.SubPut(activeObjectsKey, []byte(mess.Object), encT)
// Create a key for the views of this user
vKey := uViewsKey(mess.User)
// Make sure the sub tree is mirrored
c.SubAddConfiguration(vKey, "mirrored", "yes")
// Log this view
c.SubPut(vKey, []byte(mess.Object), encT)
// Create an encoded timestamp for something older than timeout
tooOld := time.Now().Add(-time.Hour * 24 * time.Duration((*timeout))).UnixNano()
// Delete all viewed entries with timestamp older than that
for _, item := range c.MirrorSlice(vKey, nil, godCommon.EncodeInt64(tooOld), true, true) {
c.SubDel(vKey, item.Value)
}
// Delete all active entries with timestamp older than that
for _, item := range c.MirrorSlice(activeObjectsKey, nil, godCommon.EncodeInt64(tooOld), true, true) {
c.SubDel(activeObjectsKey, item.Value)
}
} else if mess.Type == common.Like {
// Record the liked object under user
c.SubPut(uLikesKey(mess.User), []byte(mess.Object), godCommon.EncodeFloat64(mess.Weight))
// Record the liker under the liked object
c.SubPut(oLikesKey(mess.Object), []byte(mess.User), nil)
if !mess.DontActivate {
// Make the object id active
c.SubPut(activeObjectsKey, []byte(mess.Object), nil)
}
// Create an encoded timestamp for something older than timeout
tooOld := time.Now().Add(-time.Hour * 24 * time.Duration((*timeout))).UnixNano()
// Delete all active entries with timestamp older than that
for _, item := range c.MirrorSlice(activeObjectsKey, nil, godCommon.EncodeInt64(tooOld), true, true) {
c.SubDel(activeObjectsKey, item.Value)
}
} else if mess.Type == common.Deactivate {
// Remote the object id from the active objects
c.SubDel(activeObjectsKey, []byte(mess.Object))
}
} else {
fmt.Printf("When parsing %v: %v\n", string(bytes), err)
}
atomic.AddInt32(queueSize, -1)
}
}
示例2: mirrorSlice
func mirrorSlice(conn *client.Conn, args []string) {
for i, item := range conn.MirrorSlice([]byte(args[1]), []byte(args[2]), []byte(args[3]), true, false) {
fmt.Printf("%v: %v => %v\n", i, decode(item.Key), string(item.Value))
}
}