本文整理汇总了Golang中redis.DefaultSpec函数的典型用法代码示例。如果您正苦于以下问题:Golang DefaultSpec函数的具体用法?Golang DefaultSpec怎么用?Golang DefaultSpec使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了DefaultSpec函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: main
func main() {
// create the client. Here we are using a synchronous client.
// Using the default ConnectionSpec, we are specifying the client to connect
// to db 13 (e.g. SELECT 13), and a password of go-redis (e.g. AUTH go-redis)
spec := redis.DefaultSpec().Db(13).Password("go-redis")
client, e := redis.NewSynchClientWithSpec(spec)
if e != nil {
log.Println("failed to create the client", e)
return
}
key := "examples/hello/user.name"
value, e := client.Get(key)
if e != nil {
log.Println("error on Get", e)
return
}
if value == nil {
fmt.Printf("\nHello, don't believe we've met before!\nYour name? ")
reader := bufio.NewReader(os.Stdin)
user, _ := reader.ReadString(byte('\n'))
if len(user) > 1 {
user = user[0 : len(user)-1]
value = []byte(user)
client.Set(key, value)
} else {
fmt.Printf("vafanculo!\n")
return
}
}
fmt.Printf("Hey, ciao %s!\n", fmt.Sprintf("%s", value))
}
示例2: RedisPush
func RedisPush(rawtokenstring string) int {
spec := redis.DefaultSpec().Password("go-redis")
client, e := redis.NewSynchClientWithSpec(spec)
if e != nil {
fmt.Println("error creating client for: ", e)
}
defer client.Quit()
//pidString := strconv.Itoa(cmdI.Process.Pid)
decryptedToken, err := jwt.Parse(rawtokenstring, func(token *jwt.Token) (interface{}, error) {
return []byte(secretKey), nil
})
//fmt.Printf("token strings\nRaw: [%s]\nHeader: [%s]\nSignature: [%s]\n", decryptedToken.Raw, decryptedToken.Header, decryptedToken.Signature)
//check if no error and valid token
if err == nil && decryptedToken.Valid {
fmt.Println("token is valid and not expired")
} else {
fmt.Println("Not valid: ", err)
return 0
}
userID := decryptedToken.Claims["id"].(string)
//fmt.Println("redis func userid: " + userID + "\n redis func raw: " + decryptedToken.Raw)
var buf bytes.Buffer
buf.Write([]byte(decryptedToken.Raw))
e = client.Hset("clients/token", userID, buf.Bytes())
//to retrieve token in redis-cli, do hget clients/tokens legacy
if e != nil {
fmt.Println("error writing to list")
return 0
}
return 1
}
示例3: benchTask
// Use a single redis.AsyncClient with specified number
// of workers to bench concurrent load on the async client
func benchTask(taskspec taskSpec, iterations int, workers int, printReport bool) (delta int64, err os.Error) {
signal := make(chan int, workers) // Buffering optional but sensible.
spec := redis.DefaultSpec().Db(13).Password("go-redis")
client, e := redis.NewAsynchClientWithSpec(spec)
if e != nil {
log.Println("Error creating client for worker: ", e)
return -1, e
}
// defer client.Quit() // will be deprecated soon
defer client.RedisClient().Quit()
t0 := time.Nanoseconds()
for i := 0; i < workers; i++ {
id := fmt.Sprintf("%d", i)
go taskspec.task(id, signal, client, iterations)
}
for i := 0; i < workers; i++ {
<-signal
}
delta = time.Nanoseconds() - t0
// for i := 0; i < workers; i++ {
// clients[i].Quit()
// }
//
if printReport {
report("concurrent "+taskspec.name, delta, iterations*workers)
}
return
}
示例4: getDefinedMethods
// Reflect over the methods defined in redis.Client
// and send back as []string (tolowercase)
// TOOD get rid of redundant code in switch
// (REVU: needs minor update to core code)
func getDefinedMethods(ctype clientType) (map[string]string, *error_) {
var mmap = map[string]string{}
spec := redis.DefaultSpec().Db(13).Password("go-redis")
var e redis.Error
var client interface{}
switch ctype {
case sync:
client, e = redis.NewSynchClientWithSpec(spec)
case async:
client, e = redis.NewAsynchClientWithSpec(spec)
}
if e != nil {
log.Println("ignoring - ", e)
}
if client == nil {
return mmap, &error_{"client is nil", nil}
} else {
defer client.(redis.RedisClient).Quit()
}
tc := reflect.TypeOf(client)
nm := tc.NumMethod()
for i := 0; i < nm; i++ {
m := tc.Method(i)
mname := strings.ToLower(m.Name)
mmap[mname] = mname
}
return mmap, nil
}
示例5: spamChat1
func spamChat1(chanKey string) {
fmt.Println("spamchat being called")
spec := redis.DefaultSpec().Password("go-redis")
client, e := redis.NewAsynchClientWithSpec(spec)
if e != nil {
fmt.Print("Error creating spam client for: ", e)
}
defer client.Quit()
for i := 0; i < 1000000; i++ {
var fr redis.FutureInt64
//var fr2 redis.FutureBool
var buf bytes.Buffer
buf.Write([]byte("hello" + string(i)))
bt := buf.Bytes()
fr, e = client.Publish("chat", bt)
//fmt.Println("we got past 2 publishes")
if e != nil {
fmt.Println("error in publishing: ", e)
}
_, e = client.Rpush("chatlog", bt)
if e != nil {
fmt.Println("error in storing list: ", e)
}
numRecieved, _ := fr.Get()
//fmt.Println(numRecieved)
//fr2.Get()
}
}
示例6: NewRedisAsyncClient
func NewRedisAsyncClient() redis.AsyncClient {
spec := redis.DefaultSpec().Db(0).Host("10.174.178.235")
client, err := redis.NewAsynchClientWithSpec(spec)
if err != nil {
panic(err)
}
return client
}
示例7: getclient
func getclient() redis.Client {
spec := redis.DefaultSpec().Db(1)
client, e := redis.NewSynchClientWithSpec(spec)
if e != nil {
log.Fatal(e)
}
return client
}
示例8: Do
func Do(w http.ResponseWriter, req *http.Request) {
taskid := req.URL.Query().Get("taskid") // 通知主删除这个任务
var spec *redis.ConnectionSpec = redis.DefaultSpec()
ackip := utils.Cfg.GetString("redisIpACK")
ackport := utils.Cfg.GetInt("redisIpACK")
spec.Host(ackip)
spec.Port(ackport)
redis1.SyncPublish(spec, "ACK", taskid)
}
示例9: NewLogger
/// 创建新的日志记录器.
///
/// @param servAddr redis服务器地址
/// @param servPort redis服务器端口
/// @param logLev 限制日志输出级别
/// @return 成功则返回日志记录器,同时error为nil.
func NewLogger(servAddr string, servPort int, logLev uint8) (*Logger, error) {
spec := redis.DefaultSpec().Host(servAddr).Port(servPort)
cli, err := redis.NewSynchClientWithSpec(spec)
if nil != err {
return nil, err
}
return &Logger{logLev, servAddr, servPort, cli, new(defaultFormatter)}, nil
}
示例10: _test_getDefConnSpec
// connection spec used in tests, using db 13 and password 'go-redis'.
// db 13 will be repeatedly flushed, as noted elsewhere.
func _test_getDefConnSpec() *redis.ConnectionSpec {
host := "localhost"
port := 6379
db := 13
password := "go-redis"
connspec := redis.DefaultSpec().Host(host).Port(port).Db(db).Password(password)
return connspec
}
示例11: NewReportInfo
func NewReportInfo(mid string, mt string, intv int16, reportAddr string, reportPort int) (*ReportInfo, error) {
spec := redis.DefaultSpec().Host(reportAddr).Port(reportPort)
cli, err := redis.NewSynchClientWithSpec(spec)
if err != nil {
return nil, err
}
return &ReportInfo{mid, mt, intv, cli}, nil
}
示例12: makeConcurrentClients
func makeConcurrentClients(workers int) (clients []redis.Client, err error) {
clients = make([]redis.Client, workers)
for i := 0; i < workers; i++ {
spec := redis.DefaultSpec().Db(13).Password("go-redis")
client, e := redis.NewSynchClientWithSpec(spec)
if e != nil {
log.Println("Error creating client for worker: ", e)
return nil, e
}
clients[i] = client
}
return
}
示例13: makeConcurrentClients
func makeConcurrentClients(workers int) (clients []redis.Client, err os.Error) {
clients = make([]redis.Client, workers);
for i := 0; i < workers; i++ {
spec := redis.DefaultSpec().Db(13);
client, e := redis.NewSynchClientWithSpec (spec);
if e != nil {
log.Stderr ("Error creating client for worker: ", e);
return nil, e;
}
clients[i] = client;
}
return;
}
示例14: doOne
func doOne(cnt int) error {
var delta time.Duration
spec := redis.DefaultSpec().Db(13).Password("go-redis")
fmt.Printf("\n\n=== Bench synchclient ================ 1 Client -- %d opts --- \n", cnt)
fmt.Println()
client, e := redis.NewSynchClientWithSpec(spec)
if e != nil {
return onError("on NewSynchClient call: ", e)
}
if client == nil {
return failedTest("NewSynchClient returned nil!")
}
// defer client.Quit() // will be deprecated soon
defer client.RedisClient().Quit()
client.Flushdb()
delta = doPing(client, cnt)
report("PING", delta, cnt)
delta = doIncr(client, cnt)
report("INCR", delta, cnt)
delta = doSet(client, cnt)
report("SET", delta, cnt)
delta = doGet(client, cnt)
report("GET", delta, cnt)
delta = doSadd(client, cnt)
report("SADD", delta, cnt)
delta = doLpush(client, cnt)
report("LPUSH", delta, cnt)
delta = doRpush(client, cnt)
report("RPUSH", delta, cnt)
delta = doLpop(client, cnt)
report("LPOP", delta, cnt)
delta = doRpop(client, cnt)
report("RPOP", delta, cnt)
return nil
}
示例15: NewUniverse
func NewUniverse(dbNo int) *Universe {
u := new(Universe)
u.Players = make(map[int]*Player)
u.Rooms = make(map[int]*Room)
u.children = NewFlexContainer("Persistents", "TimeListeners")
spec := redis.DefaultSpec().Db(dbNo)
client, err := redis.NewSynchClientWithSpec(spec)
if err != nil {
panic(err)
} else {
u.dbConn = client
u.Store = NewTinyDB(client)
}
return u
}