當前位置: 首頁>>代碼示例>>Golang>>正文


Golang stdlog.Println函數代碼示例

本文整理匯總了Golang中GoRedis/libs/stdlog.Println函數的典型用法代碼示例。如果您正苦於以下問題:Golang Println函數的具體用法?Golang Println怎麽用?Golang Println使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了Println函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: main

// ./slaveof-proxy -src localhost:6379 -dest remote:6379 -pullrate 400 -pushrate 400
func main() {
	runtime.GOMAXPROCS(4)
	src := flag.String("src", "", "master")
	dest := flag.String("dest", "", "slave")
	pullrate := flag.Int("pullrate", 400, "pull rate in Mbits/s")
	pushrate := flag.Int("pushrate", 400, "push rate in Mbits/s")
	buffer := flag.Int("buffer", 100, "buffer x10000 records")
	flag.Parse()

	if *pullrate < 100 {
		*pullrate = 100
	}
	if *pushrate < 100 {
		*pushrate = 100
	}
	if *buffer < 100 {
		*buffer = 100
	} else if *buffer > 1000 {
		*buffer = 1000
	}

	stdlog.Println("slaveof-proxy 1.0.3")
	stdlog.Printf("from [%s] to [%s]\n", *src, *dest)
	stdlog.Printf("pull [%d] buffer [%d]\n", *pullrate, *buffer)
	stdlog.Println("SYNC ...")

	client, err := NewClient(*src, *dest, *buffer)
	if err != nil {
		stdlog.Println("ERR", err)
		return
	}
	client.SetPullRate(*pullrate / 8 * 1024 * 1024)
	client.SetPushRate(*pushrate / 8 * 1024 * 1024)
	client.Sync()
}
開發者ID:rocfy,項目名稱:GoRedis,代碼行數:36,代碼來源:slaveof-proxy.go

示例2: OnSYNC

// S: SYNC UID [UID] PORT [PORT] SNAP [1/0] SEQ [-1/...]
func (server *GoRedisServer) OnSYNC(session *Session, cmd *Command) (reply *Reply) {
	stdlog.Printf("[S %s] %s\n", session.RemoteAddr(), cmd)

	args := cmd.Args()[1:]
	if len(args) < 2 || len(args)%2 != 0 {
		session.Close()
		return
	}
	for i := 0; i < len(args); i += 2 {
		session.SetAttribute(string(args[i]), string(args[i+1]))
	}

	if !server.synclog.IsEnabled() {
		stdlog.Println("synclog enable")
		server.synclog.Enable()
	}

	// 使用從庫端口代替socket端口,標識來源
	h, _ := splitHostPort(session.RemoteAddr().String())
	remoteHost := fmt.Sprintf("%s:%s", h, session.GetAttribute("PORT"))
	session.SetAttribute(S_HOST, remoteHost)
	session.SetAttribute(S_STATUS, REPL_WAIT)

	go func() {
		server.syncmgr.Put(remoteHost, session)
		err := server.doSync(session, cmd)
		if err != nil {
			stdlog.Println("sync ", err)
		}
		session.Close()
		server.syncmgr.Remove(remoteHost)
	}()

	return NOREPLY
}
開發者ID:ming-hai,項目名稱:GoRedis,代碼行數:36,代碼來源:go_redis_server_sync.go

示例3: OnAOF

func (server *GoRedisServer) OnAOF(session *Session, cmd *Command) (reply *Reply) {
	defer func() {
		if v := recover(); v != nil {
			stdlog.Printf("aof panic %s\n", cmd)
			stdlog.Println(string(debug.Stack()))
		}
	}()

	onoff := strings.ToUpper(cmd.StringAtIndex(1))
	if onoff == "YES" {
		if server.aofwriter != nil {
			return ErrorReply("aof already inited")
		}
		if !server.synclog.IsEnabled() {
			stdlog.Println("synclog enable")
			server.synclog.Enable()
		}
		go func() {
			err := server.aofStart()
			if err != nil {
				stdlog.Println("aof", err)
			}
		}()
	} else if onoff == "NO" {
		return server.onAOF_NO()
	} else {
		return ErrorReply("must be YES/NO")
	}
	return StatusReply("OK")
}
開發者ID:WaylandGod,項目名稱:GoRedis,代碼行數:30,代碼來源:go_redis_server_aof.go

示例4: main

func main() {
	opts := levigo.NewOptions()
	opts.SetCache(levigo.NewLRUCache(128 * 1024 * 1024))
	opts.SetCompression(levigo.SnappyCompression)
	opts.SetBlockSize(32 * 1024)
	opts.SetWriteBufferSize(128 * 1024 * 1024)
	opts.SetMaxOpenFiles(100000)
	opts.SetCreateIfMissing(true)

	db, e1 := levigo.Open("/tmp/rocksdb0", opts)
	if e1 != nil {
		panic(e1)
	}
	stdlog.Println(db)

	batch := levigo.NewWriteBatch()
	batch.Put([]byte("name"), []byte("later"))
	wo := levigo.NewWriteOptions()
	db.Write(wo, batch)

	ro := levigo.NewReadOptions()
	value, err := db.Get(ro, []byte("name"))
	stdlog.Println(string(value), err)

	db.Close()
}
開發者ID:WaylandGod,項目名稱:GoRedis,代碼行數:26,代碼來源:rocksdb.go

示例5: main

func main() {
	srcptr := flag.String("src", "", "source host")
	destptr := flag.String("dest", "", "dest host")
	modePtr := flag.String("mode", "", "r/w/rw")
	flag.Parse()

	if len(*srcptr) == 0 || len(*destptr) == 0 {
		stdlog.Println("must set -src or -dest")
		return
	}
	desthost = *destptr
	mode = *modePtr
	if len(mode) == 0 {
		stdlog.Println("must set -mode [r|w|rw]")
		return
	}

	go runloop()

	r := redis_tool.NewMonitorReader(*srcptr)
	r.DidRecvCommand = recvCommand // bind
	err := r.Connect()
	if err != nil {
		panic(err)
	}
}
開發者ID:rocfy,項目名稱:GoRedis,代碼行數:26,代碼來源:redis_redirect.go

示例6: main

// go run goredis-server.go -h localhost -p 1602
// go run goredis-server.go -procs 8 -p 17600
// go run goredis-server.go -slaveof localhost:1603
func main() {
	version := flag.Bool("v", false, "print goredis-server version")
	host := flag.String("h", "", "server host")
	port := flag.Int("p", 1602, "server port")
	slaveof := flag.String("slaveof", "", "replication")
	procs := flag.Int("procs", 8, "GOMAXPROCS")
	repair := flag.Bool("repair", false, "repaire rocksdb")
	flag.Parse()

	if *version {
		fmt.Println("goredis-server", goredis_server.VERSION)
		return
	}

	runtime.GOMAXPROCS(*procs)

	opt := goredis_server.NewOptions()
	opt.SetBind(fmt.Sprintf("%s:%d", *host, *port))
	opt.SetDirectory(dbHome(*port))
	if len(*slaveof) > 0 {
		h, p, e := splitHostPort(*slaveof)
		if e != nil {
			panic(e)
		}
		opt.SetSlaveOf(h, p)
	}

	// 重定向日誌輸出位置
	redirectLogOutput(opt.Directory())

	// repair
	if *repair {
		dbhome := opt.Directory() + "db0"
		finfo, e1 := os.Stat(dbhome)
		if os.IsNotExist(e1) || !finfo.IsDir() {
			stdlog.Println("db not exist")
			return
		} else {
			stdlog.Println("start repair", dbhome)
			levelredis.Repair(dbhome)
			stdlog.Println("repair finish")
		}
		return
	}

	stdlog.Println("========================================")
	server := goredis_server.NewGoRedisServer(opt)
	if err := server.Init(); err != nil {
		panic(err)
	}
	if err := server.Listen(); err != nil {
		panic(err)
	}
}
開發者ID:rocfy,項目名稱:GoRedis,代碼行數:57,代碼來源:goredis-server.go

示例7: Init

// 初始化入口
func (server *GoRedisProxy) Init() (err error) {
	e1 := server.resetMaster(server.options.MasterHost)
	e2 := server.resetSlave(server.options.SlaveHost)
	if e1 != nil {
		stdlog.Println(e1)
	}
	if e2 != nil {
		stdlog.Println(e2)
	}
	return
}
開發者ID:WaylandGod,項目名稱:GoRedis,代碼行數:12,代碼來源:goredis_proxy_init.go

示例8: initLevelDB

// 初始化leveldb
func (server *GoRedisServer) initLevelDB() (err error) {
	opts := levelredis.NewOptions()
	cache := levelredis.NewLRUCache(128 * 1024 * 1024)
	opts.SetCache(cache)
	opts.SetCompression(levelredis.SnappyCompression)
	opts.SetBlockSize(8 * 1024)
	opts.SetMaxBackgroundCompactions(6)
	opts.SetWriteBufferSize(32 * 1024 * 1024)
	opts.SetMaxOpenFiles(100000)
	opts.SetCreateIfMissing(true)
	env := levelredis.NewDefaultEnv()
	env.SetBackgroundThreads(6)
	env.SetHighPriorityBackgroundThreads(2)
	opts.SetEnv(env)
	db, e1 := levelredis.Open(server.directory+"/db0", opts)
	if e1 != nil {
		return e1
	}
	server.levelRedis = levelredis.NewLevelRedis(db, false)
	server.DeferClosing(func() {
		opts.Close()
		cache.Close()
		env.Close()
		stdlog.Println("db closed")
	})
	return
}
開發者ID:rocfy,項目名稱:GoRedis,代碼行數:28,代碼來源:go_redis_server_init.go

示例9: Sync

func (s *SlaveClient) Sync() (err error) {
	session := s.src
	if err = session.WriteCommand(NewCommand([]byte("SYNC"))); err != nil {
		return
	}

	rdbsaved := false
	for {
		var c byte
		if c, err = session.PeekByte(); err != nil {
			break
		}
		if !rdbsaved && c == '$' {
			if err = s.recvRdb(); err != nil {
				break
			}
			rdbsaved = true
		} else if c == '\n' {
			if _, err = session.ReadByte(); err != nil {
				break
			}
			stdlog.Println("waiting ...")
		} else {
			var cmd *Command
			if cmd, err = session.ReadCommand(); err != nil {
				break
			}
			s.counters.Get("in").Incr(1)
			s.buffer <- cmd
		}
	}
	return
}
開發者ID:WaylandGod,項目名稱:GoRedis,代碼行數:33,代碼來源:slave_client.go

示例10: OnSLAVEOF

// 從主庫獲取數據
func (server *GoRedisServer) OnSLAVEOF(session *Session, cmd *Command) (reply *Reply) {
	// 保障不會奔潰
	defer func() {
		if v := recover(); v != nil {
			stdlog.Printf("[%s] slaveof panic %s\n", session.RemoteAddr(), cmd)
			stdlog.Println(string(debug.Stack()))
		}
	}()
	arg1, arg2 := cmd.StringAtIndex(1), cmd.StringAtIndex(2)
	// SLAVEOF NO ONE
	if strings.ToUpper(arg1) == "NO" && strings.ToUpper(arg2) == "ONE" {
		return server.onSlaveOfNoOne(session, cmd)
	}

	// connect to master
	hostPort := arg1 + ":" + arg2
	conn, err := net.Dial("tcp", hostPort)
	if err != nil {
		return ErrorReply(err)
	}

	// check exists
	remoteHost := conn.RemoteAddr().String()
	if server.slavemgr.Contains(remoteHost) {
		return ErrorReply("connection exists")
	}

	masterSession := NewSession(conn)
	isgoredis, version, err := redisInfo(masterSession)
	if err != nil {
		return ErrorReply(err)
	}

	var client ISlaveClient
	if isgoredis {
		slavelog.Printf("[M %s] SLAVEOF %s GoRedis:%s\n", remoteHost, remoteHost, version)
		if client, err = NewSlaveClientV2(server, masterSession); err != nil {
			return ErrorReply(err)
		}
	} else {
		slavelog.Printf("[M %s] SLAVEOF %s Redis:%s\n", remoteHost, remoteHost, version)
		if client, err = NewSlaveClient(server, masterSession); err != nil {
			return ErrorReply(err)
		}
	}

	// async
	go func() {
		client.Session().SetAttribute(S_STATUS, REPL_WAIT)
		server.slavemgr.Put(remoteHost, client)
		err := client.Sync()
		if err != nil {
			slavelog.Printf("[M %s] sync broken %s\n", remoteHost, err)
		}
		client.Close()
		server.slavemgr.Remove(remoteHost)
	}()

	return StatusReply("OK")
}
開發者ID:ming-hai,項目名稱:GoRedis,代碼行數:61,代碼來源:go_redis_server_slaveof.go

示例11: initSyncLog

// 初始化主從日誌
func (server *GoRedisServer) initSyncLog() error {
	opts := levelredis.NewOptions()
	cache := levelredis.NewLRUCache(32 * 1024 * 1024)
	opts.SetCache(cache)
	opts.SetCompression(levelredis.SnappyCompression)
	opts.SetBlockSize(4 * 1024)
	opts.SetMaxBackgroundCompactions(2)
	opts.SetWriteBufferSize(32 * 1024 * 1024)
	opts.SetMaxOpenFiles(100000)
	opts.SetCreateIfMissing(true)
	env := levelredis.NewDefaultEnv()
	env.SetBackgroundThreads(2)
	env.SetHighPriorityBackgroundThreads(1)
	opts.SetEnv(env)
	db, e1 := levelredis.Open(server.directory+"/synclog", opts)
	if e1 != nil {
		return e1
	}
	ldb := levelredis.NewLevelRedis(db, false)
	server.synclog = NewSyncLog(ldb, "sync")
	server.DeferClosing(func() {
		opts.Close()
		cache.Close()
		env.Close()
		stdlog.Println("synclog closed")
	})
	return nil
}
開發者ID:rocfy,項目名稱:GoRedis,代碼行數:29,代碼來源:go_redis_server_init.go

示例12: Init

func (server *GoRedisServer) Init() (err error) {

	server.initSignalNotify()

	stdlog.Println("server init, version", VERSION, "...")
	err = server.initLevelDB()
	if err != nil {
		return
	}
	err = server.initSyncLog()
	if err != nil {
		return
	}
	server.config = NewConfig(server.levelRedis, PREFIX+"config:")
	// monitor
	server.initCommandMonitor(server.directory + "/cmd.log")
	server.initCommandCounterLog("string", []string{"GET", "SET", "MGET", "MSET", "INCR", "DECR", "INCRBY", "DECRBY"})
	server.initCommandCounterLog("hash", []string{"HGETALL", "HGET", "HSET", "HDEL", "HMGET", "HMSET", "HINCRBY", "HLEN"})
	server.initCommandCounterLog("set", []string{"SADD", "SCARD", "SISMEMBER", "SMEMBERS", "SREM"})
	server.initCommandCounterLog("list", []string{"LPUSH", "RPUSH", "LPOP", "RPOP", "LINDEX", "LLEN", "LRANGE", "LTRIM"})
	server.initCommandCounterLog("zset", []string{"ZADD", "ZCARD", "ZSCORE", "ZINCRBY", "ZRANGE", "ZRANGEBYSCORE", "ZRANK", "ZREM", "ZREMRANGEBYRANK", "ZREMRANGEBYSCORE", "ZREVRANGE", "ZREVRANGEBYSCORE", "ZREVRANK"})
	server.initSeqLog(server.directory + "/seq.log")
	server.initLeveldbIOLog(server.directory + "/leveldb.io.log")
	server.initLeveldbStatsLog(server.directory + "/leveldb.stats.log")
	server.initExecLog(server.directory + "/exec.time.log")
	server.initSlowlog(server.directory + "/slow.log")
	stdlog.Printf("init uid %s\n", server.UID())
	server.initSlaveOf()
	return
}
開發者ID:rocfy,項目名稱:GoRedis,代碼行數:30,代碼來源:go_redis_server_init.go

示例13: onAOF_NO

func (server *GoRedisServer) onAOF_NO() (reply *Reply) {
	if server.aofwriter == nil {
		return ErrorReply("aof not inited")
	}
	server.aofwriter.Close()
	stdlog.Println("aof closed")
	return StatusReply("OK")
}
開發者ID:WaylandGod,項目名稱:GoRedis,代碼行數:8,代碼來源:go_redis_server_aof.go

示例14: resetMode

// 包含w表示可寫入,包容rr表示主從均可以讀
// mode=r, 從庫提供讀,寫操作返回錯誤
// mode=rr, 主從均提供讀,寫操作返回錯誤
// mode=rw, 主庫提供寫,從庫提供讀
// mode=rrw,主庫提供寫,主從均提供讀
func (server *GoRedisProxy) resetMode(mode string) (err error) {
	server.Suspend()
	defer server.Resume()

	stdlog.Println("CONFIG mode", mode)
	server.options.Mode = mode
	return
}
開發者ID:ming-hai,項目名稱:GoRedis,代碼行數:13,代碼來源:goredis_proxy_config.go

示例15: main

// ./slaveof-proxy -src localhost:6379 -dest remote:6379 -pullrate 400 -pushrate 400
func main() {
	runtime.GOMAXPROCS(4)
	src := flag.String("src", "", "master")
	dest := flag.String("dest", "", "slave")
	pullrate := flag.Int("pullrate", 400, "pull rate in Mbits/s")
	pushrate := flag.Int("pushrate", 400, "push rate in Mbits/s")
	buffer := flag.Int("buffer", 100, "buffer x10000 records")
	dbpath := flag.String("dbpath", "/tmp", "rdb path")
	flag.Parse()

	if *pullrate < 100 {
		*pullrate = 100
	}
	if *pushrate < 100 {
		*pushrate = 100
	}
	if *buffer < 100 {
		*buffer = 100
	} else if *buffer > 1000 {
		*buffer = 1000
	}

	stdlog.Println("slaveof-proxy 1.0.4")
	if len(*src) == 0 || len(*dest) == 0 {
		stdlog.Println("Usage: ./slaveof-proxy -src master:port -dest slave:6379 -pullrate 400 -pushrate 400 -buffer 100 -dbpath /tmp")
		return
	}

	stdlog.Printf("from [%s] to [%s]\n", *src, *dest)
	stdlog.Printf("pull [%d] buffer [%d]\n", *pullrate, *buffer)
	stdlog.Println("SYNC ...")

	client, err := NewClient(*src, *dest, *buffer)
	if err != nil {
		stdlog.Println("ERR", err)
		return
	}
	client.SetPullRate(*pullrate / 8 * 1024 * 1024)
	client.SetPushRate(*pushrate / 8 * 1024 * 1024)
	client.SetDbPath(*dbpath)
	err = client.Sync()
	if err != nil {
		panic(err)
	}
}
開發者ID:WaylandGod,項目名稱:GoRedis,代碼行數:46,代碼來源:slaveof-proxy.go


注:本文中的GoRedis/libs/stdlog.Println函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。