本文整理匯總了Golang中github.com/nyxtom/broadcast/server.ProtocolClient.WriteLen方法的典型用法代碼示例。如果您正苦於以下問題:Golang ProtocolClient.WriteLen方法的具體用法?Golang ProtocolClient.WriteLen怎麽用?Golang ProtocolClient.WriteLen使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/nyxtom/broadcast/server.ProtocolClient
的用法示例。
在下文中一共展示了ProtocolClient.WriteLen方法的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: SInter
func (stats *StatsBackend) SInter(data interface{}, client server.ProtocolClient) error {
d, _ := data.([][]byte)
if len(d) < 2 {
client.WriteError(errors.New("SINTER takes at least 2 parameters (SINTER key [key ...])"))
client.Flush()
return nil
} else {
keys := make([]string, len(d))
for i, v := range d {
keys[i] = string(v)
}
results, err := stats.mem.SInter(keys)
if err != nil {
return err
}
if results == nil {
client.WriteNull()
client.Flush()
return nil
}
client.WriteLen('*', len(results))
for k, _ := range results {
client.WriteString(k)
}
client.Flush()
return nil
}
}
示例2: SIsMember
func (stats *StatsBackend) SIsMember(data interface{}, client server.ProtocolClient) error {
d, _ := data.([][]byte)
if len(d) < 2 {
client.WriteError(errors.New("SISMEMBER takes 2 parameters (SISMEMBER key member)"))
client.Flush()
return nil
} else {
key := string(d[0])
results := make([]int64, len(d)-1)
for i, v := range d[1:] {
result, err := stats.mem.SIsMember(key, string(v))
if err != nil {
return err
}
results[i] = result
}
if len(results) > 1 {
client.WriteLen('*', len(results))
for _, v := range results {
client.WriteInt64(v)
}
} else {
client.WriteInt64(results[0])
}
client.Flush()
return nil
}
}
示例3: SMembers
func (stats *StatsBackend) SMembers(data interface{}, client server.ProtocolClient) error {
d, _ := data.([][]byte)
if len(d) == 0 {
client.WriteError(errors.New("SMEMBERS takes 1 parameter (SMEMBERS key)"))
client.Flush()
return nil
} else {
values, err := stats.mem.SMembers(string(d[0]))
if err != nil {
return err
}
if values == nil {
client.WriteNull()
client.Flush()
return nil
}
client.WriteLen('*', len(values))
for k, _ := range values {
client.WriteString(k)
}
client.Flush()
return nil
}
}
示例4: SDiff
func (stats *StatsBackend) SDiff(data interface{}, client server.ProtocolClient) error {
d, _ := data.([][]byte)
if len(d) < 2 {
client.WriteError(errors.New("SDIFF requires at least 2 parameters (SDIFF key [key ...])"))
client.Flush()
return nil
} else {
results, err := stats.mem.SMembers(string(d[0]))
if err != nil {
return err
} else if results == nil {
client.WriteNull()
client.Flush()
return nil
} else {
for _, v := range d[1:] {
results, err = stats.mem.SDiff(results, string(v))
if err != nil {
return err
} else if len(results) == 0 {
break
}
}
client.WriteLen('*', len(results))
for k, _ := range results {
client.WriteString(k)
}
client.Flush()
return nil
}
}
}
示例5: SCard
func (stats *StatsBackend) SCard(data interface{}, client server.ProtocolClient) error {
d, _ := data.([][]byte)
if len(d) < 1 {
client.WriteError(errors.New("SCARD takes at least 1 parameter (SCARD key)"))
client.Flush()
return nil
} else {
results := make([]int64, len(d))
for i, v := range d {
r, err := stats.mem.SCard(string(v))
if err != nil {
return err
} else {
results[i] = r
}
}
if len(d) > 1 {
client.WriteLen('*', len(d))
for _, v := range results {
client.WriteInt64(v)
}
} else {
client.WriteInt64(results[0])
}
client.Flush()
return nil
}
}
示例6: Keys
func (stats *StatsBackend) Keys(data interface{}, client server.ProtocolClient) error {
d, _ := data.([][]byte)
key := ""
if len(d) > 0 {
pattern, err := stats.readString(d[0])
if err != nil {
return err
}
key = pattern
}
results, err := stats.mem.Keys(key)
if err != nil {
client.WriteError(err)
client.Flush()
return nil
}
client.WriteLen('*', len(results))
for _, k := range results {
client.WriteString(k)
}
client.Flush()
return nil
}