本文整理匯總了Golang中github.com/garyburd/redigo/redis.Strings函數的典型用法代碼示例。如果您正苦於以下問題:Golang Strings函數的具體用法?Golang Strings怎麽用?Golang Strings使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了Strings函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: getSuggestCandidates
func (rr *Redrec) getSuggestCandidates(user string, max int) ([]string, error) {
similarUsers, err := redis.Strings(rr.rconn.Do("ZRANGE", fmt.Sprintf("user:%s:similars", user), 0, max))
if err != nil {
return nil, err
}
max = len(similarUsers)
args := []interface{}{}
args = append(args, "ztmp", float64(max+1), fmt.Sprintf("user:%s:items", user))
weights := []interface{}{}
weights = append(weights, "WEIGHTS", -1.0)
for _, simuser := range similarUsers {
args = append(args, fmt.Sprintf("user:%s:items", simuser))
weights = append(weights, 1.0)
}
args = append(args, weights...)
args = append(args, "AGGREGATE", "MIN")
_, err = rr.rconn.Do("ZUNIONSTORE", args...)
if err != nil {
return nil, err
}
candidates, err := redis.Strings(rr.rconn.Do("ZRANGEBYSCORE", "ztmp", 0, "inf"))
if err != nil {
return nil, err
}
_, err = rr.rconn.Do("DEL", "ztmp")
if err != nil {
return nil, err
}
return candidates, nil
}
示例2: getJobs
func getJobs() (jobs map[string]*CronJob, err error) {
jobs = make(map[string]*CronJob)
var jobKeys []string
var jobData []string
jobKeys, err = redis.Strings(RedisConn.Do("SMEMBERS", "cronstalk:jobs"))
if err != nil {
log.Println("error updating jobs from redis")
return
}
for _, key := range jobKeys {
jobData, err = redis.Strings(RedisConn.Do("HGETALL", key))
if err != nil {
log.Printf("error getting job \"%s\": %s\n", key, err)
continue
}
job, err := NewJob(key, jobData)
if err != nil {
log.Printf("error creating job %s\n", key)
continue
}
jobs[key] = job
}
return
}
示例3: TestFlushDb
func TestFlushDb(t *testing.T) {
c := NewFakeRedis()
redis.String(c.Do("SET", "foo", "bar"))
assertStrings(t, must(redis.Strings(c.Do("KEYS", "foo"))).([]string), []string{"foo"}, false)
c.Do("FLUSHDB")
assertStrings(t, must(redis.Strings(c.Do("KEYS", "foo"))).([]string), []string{}, false)
}
示例4: update
func (s Similars) update(user User) error {
items, err := redis.Strings(s.e.c.Do("SUNION", fmt.Sprintf("%s:%s:%s", s.e.class, user, s.e.Likes.kind), fmt.Sprintf("%s:%s:%s", s.e.class, user, s.e.Dislikes.kind)))
if err != nil && err != redis.ErrNil {
return err
}
args := []interface{}{}
for _, item := range items {
args = append(args, fmt.Sprintf("%s:%s:%s", s.e.class, item, s.e.Likes.kind))
args = append(args, fmt.Sprintf("%s:%s:%s", s.e.class, item, s.e.Dislikes.kind))
}
users, err := redis.Strings(s.e.c.Do("SUNION", args...))
if err != nil && err != redis.ErrNil {
return err
}
for _, other := range users {
if other != string(user) {
v, err := s.Jaccard(user, User(other))
if err != nil {
return err
}
_, err = s.e.c.Do("ZADD", fmt.Sprintf("%s:%s:similars", s.e.class, user), v, other)
if err != nil {
return err
}
}
}
return nil
}
示例5: GetUserDevices
func GetUserDevices(userId int64) ([]int64, error) {
r := Redix[_GetUserDevices]
RedixMu[_GetUserDevices].Lock()
defer RedixMu[_GetUserDevices].Unlock()
var idStrs []string //字串類型的設備數組
hostId, err := redis.String(r.Do("hget", "user:family", userId))
//hostId為空說明此用戶為孤兒
if err != nil || hostId == "" {
idStrs, _ = redis.Strings(r.Do("smembers", fmt.Sprintf(RedisUserDevices, userId)))
} else {
mems, _ := redis.Strings(r.Do("smembers", fmt.Sprintf("family:%v", hostId)))
for _, m := range mems {
devs, err := redis.Strings(r.Do("smembers", fmt.Sprintf(RedisUserDevices, m)))
if err == nil && len(devs) > 0 {
idStrs = append(idStrs, devs...)
}
}
}
bindedIds := make([]int64, 0, len(idStrs))
for _, v := range idStrs {
id, err := strconv.ParseInt(v, 10, 64)
if err != nil {
continue
}
bindedIds = append(bindedIds, id)
}
return bindedIds, nil
}
示例6: GetFullErrorHistory
func (d *dataAccess) GetFullErrorHistory() (map[string][]*models.AlertError, error) {
defer collect.StartTimer("redis", opentsdb.TagSet{"op": "GetFullErrorHistory"})()
conn := d.GetConnection()
defer conn.Close()
alerts, err := redis.Strings(conn.Do("SMEMBERS", alertsWithErrors))
if err != nil {
return nil, err
}
results := make(map[string][]*models.AlertError, len(alerts))
for _, a := range alerts {
rows, err := redis.Strings(conn.Do("LRANGE", errorListKey(a), 0, -1))
if err != nil {
return nil, err
}
list := make([]*models.AlertError, len(rows))
for i, row := range rows {
ae := &models.AlertError{}
err = json.Unmarshal([]byte(row), ae)
if err != nil {
return nil, err
}
list[i] = ae
}
results[a] = list
}
return results, nil
}
示例7: GetKeysAndValuesWithFilter
// GetKeysAndValuesWithFilter will return all keys and their values with a filter
func (r *RedisClusterStorageManager) GetKeysAndValuesWithFilter(filter string) map[string]string {
if r.db == nil {
log.Info("Connection dropped, connecting..")
r.Connect()
return r.GetKeysAndValuesWithFilter(filter)
}
searchStr := r.KeyPrefix + r.hashKey(filter) + "*"
log.Debug("[STORE] Getting list by: ", searchStr)
sessionsInterface, err := r.db.Do("KEYS", searchStr)
if err != nil {
log.Error("Error trying to get filtered client keys:")
log.Error(err)
} else {
keys, _ := redis.Strings(sessionsInterface, err)
valueObj, err := r.db.Do("MGET", sessionsInterface.([]interface{})...)
values, err := redis.Strings(valueObj, err)
returnValues := make(map[string]string)
for i, v := range keys {
returnValues[r.cleanKey(v)] = values[i]
}
return returnValues
}
return map[string]string{}
}
示例8: newServerState
// TODO: add timeouts
func newServerState() (state *ServerState, err error) {
conn, err := redis.Dial("tcp", "127.0.0.1:6379")
if err != nil {
return
}
defer conn.Close()
urls, err := redis.Strings(conn.Do("SMEMBERS", "urls"))
if err != nil {
return
}
profiles, err := redis.Strings(conn.Do("SMEMBERS", "profiles"))
if err != nil {
return
}
urlProfileWeights, err := getWeights(conn, urls, profiles)
if err != nil {
return
}
state = new(ServerState)
state.urls = urls
state.profiles = profiles
state.urlProfileWeights = urlProfileWeights
return
}
示例9: Build
// Fetch Txos and Txins
func (tx *Tx) Build(rpool *redis.Pool) (err error) {
c := rpool.Get()
defer c.Close()
tx.TxIns = []*TxIn{}
tx.TxOuts = []*TxOut{}
txinskeys := []interface{}{}
for i := range iter.N(int(tx.TxInCnt)) {
txinskeys = append(txinskeys, fmt.Sprintf("txi:%v:%v", tx.Hash, i))
}
txinsjson, _ := redis.Strings(c.Do("MGET", txinskeys...))
for _, txinjson := range txinsjson {
ctxi := new(TxIn)
err = json.Unmarshal([]byte(txinjson), ctxi)
tx.TxIns = append(tx.TxIns, ctxi)
}
txoutskeys := []interface{}{}
txoutsspentkeys := []interface{}{}
for i := range iter.N(int(tx.TxOutCnt)) {
txoutskeys = append(txoutskeys, fmt.Sprintf("txo:%v:%v", tx.Hash, i))
txoutsspentkeys = append(txoutsspentkeys, fmt.Sprintf("txo:%v:%v:spent", tx.Hash, i))
}
txoutsjson, _ := redis.Strings(c.Do("MGET", txoutskeys...))
txoutsspentjson, _ := redis.Strings(c.Do("MGET", txoutsspentkeys...))
for txoindex, txoutjson := range txoutsjson {
ctxo := new(TxOut)
err = json.Unmarshal([]byte(txoutjson), ctxo)
if txoutsspentjson[txoindex] != "" {
cspent := new(TxoSpent)
err = json.Unmarshal([]byte(txoutsspentjson[txoindex]), cspent)
ctxo.Spent = cspent
}
tx.TxOuts = append(tx.TxOuts, ctxo)
}
return
}
示例10: crawl
func crawl(c *command) {
if len(c.flag.Args()) != 0 {
c.printUsage()
os.Exit(1)
}
db, err := database.New()
if err != nil {
log.Fatal(err)
}
conn := db.Pool.Get()
defer conn.Close()
paths, err := redis.Strings(conn.Do("SMEMBERS", "newCrawl"))
if err != nil {
log.Fatal(err)
}
fmt.Println("NEW")
for _, path := range paths {
fmt.Println(path)
}
paths, err = redis.Strings(conn.Do("SMEMBERS", "badCrawl"))
if err != nil {
log.Fatal(err)
}
fmt.Println("BAD")
for _, path := range paths {
fmt.Println(path)
}
}
示例11: GetKeysAndValues
// GetKeysAndValues will return all keys and their values - not to be used lightly
func (r *RedisClusterStorageManager) GetKeysAndValues() map[string]string {
if GetRelevantClusterReference(r.IsCache) == nil {
log.Info("Connection dropped, connecting..")
r.Connect()
return r.GetKeysAndValues()
}
searchStr := r.KeyPrefix + "*"
sessionsInterface, err := GetRelevantClusterReference(r.IsCache).Do("KEYS", searchStr)
if err != nil {
log.Error("Error trying to get all keys:")
log.Error(err)
} else {
keys, _ := redis.Strings(sessionsInterface, err)
valueObj, err := GetRelevantClusterReference(r.IsCache).Do("MGET", sessionsInterface.([]interface{})...)
values, err := redis.Strings(valueObj, err)
m := make(map[string]string)
for i, v := range keys {
m[r.cleanKey(v)] = values[i]
}
return m
}
return map[string]string{}
}
示例12: TestHashValues
func TestHashValues(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")
s.HSet("wim", "gijs", "lam")
s.HSet("wim", "kees", "bok")
v, err := redis.Strings(c.Do("HVALS", "wim"))
ok(t, err)
equals(t, 4, len(v))
sort.Strings(v)
equals(t, []string{
"bok",
"jet",
"lam",
"vuur",
}, v)
v, err = redis.Strings(c.Do("HVALS", "nosuch"))
ok(t, err)
equals(t, 0, len(v))
// Wrong key type
s.Set("foo", "bar")
_, err = redis.Int(c.Do("HVALS", "foo"))
assert(t, err != nil, "no HVALS error")
}
示例13: GetKeysAndValues
// GetKeysAndValues will return all keys and their values - not to be used lightly
func (r *RedisStorageManager) GetKeysAndValues() map[string]string {
db := r.pool.Get()
defer db.Close()
if db == nil {
log.Info("Connection dropped, connecting..")
r.Connect()
return r.GetKeysAndValues()
}
searchStr := r.KeyPrefix + "*"
sessionsInterface, err := db.Do("KEYS", searchStr)
if err != nil {
log.Error("Error trying to get all keys:")
log.Error(err)
} else {
keys, _ := redis.Strings(sessionsInterface, err)
valueObj, err := db.Do("MGET", sessionsInterface.([]interface{})...)
values, err := redis.Strings(valueObj, err)
returnValues := make(map[string]string)
for i, v := range keys {
returnValues[r.cleanKey(v)] = values[i]
}
return returnValues
}
return map[string]string{}
}
示例14: TestHashGetall
func TestHashGetall(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")
s.HSet("wim", "gijs", "lam")
s.HSet("wim", "kees", "bok")
v, err := redis.Strings(c.Do("HGETALL", "wim"))
ok(t, err)
equals(t, 8, len(v))
d := map[string]string{}
for len(v) > 0 {
d[v[0]] = v[1]
v = v[2:]
}
equals(t, map[string]string{
"zus": "jet",
"teun": "vuur",
"gijs": "lam",
"kees": "bok",
}, d)
v, err = redis.Strings(c.Do("HGETALL", "nosuch"))
ok(t, err)
equals(t, 0, len(v))
// Wrong key type
s.Set("foo", "bar")
_, err = redis.Int(c.Do("HGETALL", "foo"))
assert(t, err != nil, "no HGETALL error")
}
示例15: TestAuthenticateExcistingUser
func (s *AuthTest) TestAuthenticateExcistingUser() {
entities.Save(&entities.Planet{
Name: "GOP6720",
Position: &vec2d.Vector{2, 2},
})
entities.Save(&entities.Player{
Username: "gophie",
RaceID: 1,
TwitterID: "gop",
HomePlanet: "planet.GOP6720",
ScreenSize: []uint64{1, 1},
ScreenPosition: &vec2d.Vector{2, 2},
})
players_before, err := redis.Strings(s.conn.Do("KEYS", "player.*"))
before := len(players_before)
assert.Nil(s.T(), err)
s.assertSend(&user)
s.assertReceive("server_params")
s.assertReceive("login_success")
players_after, err := redis.Strings(s.conn.Do("KEYS", "player.*"))
after := len(players_after)
assert.Nil(s.T(), err)
assert.Equal(s.T(), before, after)
}