本文整理匯總了Golang中github.com/reborndb/go/redis/resp.NewString函數的典型用法代碼示例。如果您正苦於以下問題:Golang NewString函數的具體用法?Golang NewString怎麽用?Golang NewString使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了NewString函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: SlotsRestoreCmd
// SLOTSRESTORE key ttlms value [key ttlms value ...]
func SlotsRestoreCmd(s Session, args [][]byte) (redis.Resp, error) {
if err := s.Store().SlotsRestore(s.DB(), args); err != nil {
return toRespError(err)
} else {
return redis.NewString("OK"), nil
}
}
示例2: ReplConfCmd
// REPLCONF listening-port port / ack sync-offset
func ReplConfCmd(s Session, args [][]byte) (redis.Resp, error) {
if len(args) != 2 {
return toRespErrorf("len(args) = %d, expect = 2", len(args))
}
c, _ := s.(*conn)
if c == nil {
return nil, errors.New("invalid connection")
}
switch strings.ToLower(string(args[0])) {
case "listening-port":
if port, err := strconv.ParseInt(string(args[1]), 10, 16); err != nil {
return toRespErrorf("invalid port REPLCONF listening-port, err: %v", err)
} else {
c.listeningPort.Set(int64(port))
}
case "ack":
if ack, err := strconv.ParseInt(string(args[1]), 10, 64); err != nil {
return toRespErrorf("invalid port REPLCONF ACK, err: %v", err)
} else {
c.backlogACKOffset.Set(ack)
c.backlogACKTime.Set(time.Now().Unix())
// ACK will not reply anything
return nil, nil
}
default:
return toRespErrorf("Unrecognized REPLCONF option:%s", args[0])
}
return redis.NewString("OK"), nil
}
示例3: PingCmd
// PING
func PingCmd(s Session, args [][]byte) (redis.Resp, error) {
if len(args) != 0 {
return toRespErrorf("len(args) = %d, expect = 0", len(args))
}
return redis.NewString("PONG"), nil
}
示例4: TypeCmd
// TYPE key
func TypeCmd(s Session, args [][]byte) (redis.Resp, error) {
if c, err := s.Store().Type(s.DB(), args); err != nil {
return toRespError(err)
} else {
return redis.NewString(c.String()), nil
}
}
示例5: BgsaveToCmd
// BGSAVETO path
func BgsaveToCmd(s Session, args [][]byte) (redis.Resp, error) {
if len(args) != 1 {
return toRespErrorf("len(args) = %d, expect = 1", len(args))
}
c, _ := s.(*conn)
if c == nil {
return nil, errors.New("invalid connection")
}
if ok := c.h.bgSaveSem.AcquireTimeout(time.Second); !ok {
return toRespErrorf("wait others do bgsave timeout")
}
defer c.h.bgSaveSem.Release()
sp, err := c.Store().NewSnapshot()
if err != nil {
return toRespError(err)
}
defer c.Store().ReleaseSnapshot(sp)
if err := c.h.bgsaveTo(sp, string(args[0])); err != nil {
return toRespError(err)
} else {
return redis.NewString("OK"), nil
}
}
示例6: SlaveOfCmd
// SLAVEOF host port
func SlaveOfCmd(s Session, args [][]byte) (redis.Resp, error) {
if len(args) != 2 {
return toRespErrorf("len(args) = %d, expect = 2", len(args))
}
addr := fmt.Sprintf("%s:%s", string(args[0]), string(args[1]))
log.Infof("set slave of %s", addr)
c, _ := s.(*conn)
if c == nil {
return nil, errors.New("invalid connection")
}
var cc *conn
var err error
if strings.ToLower(addr) != "no:one" {
if cc, err = c.h.replicationConnectMaster(addr); err != nil {
return toRespError(errors.Trace(err))
}
}
select {
case <-c.h.signal:
if cc != nil {
cc.Close()
}
return toRespErrorf("sync master has been closed")
case c.h.master <- cc:
<-c.h.slaveofReply
return redis.NewString("OK"), nil
}
}
示例7: SetCmd
// SET key value [EX seconds] [PX milliseconds] [NX|XX]
func SetCmd(s Session, args [][]byte) (redis.Resp, error) {
if err := s.Store().Set(s.DB(), args); err != nil && errors2.ErrorNotEqual(err, store.ErrSetAborted) {
return toRespError(err)
} else if errors2.ErrorEqual(err, store.ErrSetAborted) {
return redis.NewBulkBytes(nil), nil
} else {
return redis.NewString("OK"), nil
}
}
示例8: SelectCmd
// SELECT db
func SelectCmd(s Session, args [][]byte) (redis.Resp, error) {
if db, err := store.ParseUint(args[0]); err != nil {
return toRespError(err)
} else if db > math.MaxUint32 {
return toRespErrorf("parse db = %d", db)
} else {
s.SetDB(uint32(db))
return redis.NewString("OK"), nil
}
}
示例9: CompactAllCmd
// COMPACTALL
func CompactAllCmd(s Session, args [][]byte) (redis.Resp, error) {
if len(args) != 0 {
return toRespErrorf("len(args) = %d, expect = 0", len(args))
}
if err := s.Store().CompactAll(); err != nil {
return toRespError(err)
} else {
return redis.NewString("OK"), nil
}
}
示例10: RegisterStringReply
func RegisterStringReply(name string, f CommandSimpleStringFunc, flag CommandFlag) {
v := func(s Session, args [][]byte) (redis.Resp, error) {
r, err := f(s, args)
if err != nil {
return toRespError(err)
}
return redis.NewString(r), nil
}
register(name, v, flag)
}
示例11: RegisterOKReply
func RegisterOKReply(name string, f CommandOKFunc) {
v := func(s Session, args [][]byte) (redis.Resp, error) {
err := f(s, args)
if err != nil {
return toRespError(err)
}
return redis.NewString("OK"), nil
}
register(name, v)
}
示例12: ConfigCmd
// CONFIG get key / set key value
func ConfigCmd(s Session, args [][]byte) (redis.Resp, error) {
if len(args) != 2 && len(args) != 3 {
return toRespErrorf("len(args) = %d, expect = 2 or 3", len(args))
}
c, _ := s.(*conn)
if c == nil {
return nil, errors.New("invalid connection")
}
sub := strings.ToLower(string(args[0]))
switch sub {
default:
return toRespErrorf("unknown sub-command = %s", sub)
case "get":
if len(args) != 2 {
return toRespErrorf("len(args) = %d, expect = 2", len(args))
}
switch e := strings.ToLower(string(args[1])); e {
default:
return toRespErrorf("unknown entry %s", e)
case "maxmemory":
return redis.NewString("0"), nil
}
case "set":
if len(args) != 3 {
return toRespErrorf("len(args) = %d, expect = 3", len(args))
}
switch e := strings.ToLower(string(args[1])); e {
default:
return toRespErrorf("unknown entry %s", e)
case "requirepass":
auth := string(args[2])
c.h.config.Auth = auth
return redis.NewString("OK"), nil
}
}
}
示例13: handleSyncCommand
func (h *Handler) handleSyncCommand(opt string, c *conn, args [][]byte) (redis.Resp, error) {
if h.isSlave(c) {
// ignore SYNC if already slave
return nil, nil
}
if opt == "psync" {
// first try whether full resync or not
need, syncOffset := h.needFullReSync(c, args)
if !need {
// write CONTINUE and resume replication
if err := c.writeRESP(redis.NewString("CONTINUE")); err != nil {
log.Errorf("reply slave %s psync CONTINUE err - %s", c, err)
c.Close()
return nil, errors.Trace(err)
}
h.counters.syncPartialOK.Add(1)
h.startSlaveReplication(c, syncOffset)
return nil, nil
}
// we must handle full resync
if err := h.replicationReplyFullReSync(c); err != nil {
return nil, errors.Trace(err)
}
// slave will use ? to force resync, this is not error
if !bytes.Equal(args[0], []byte{'?'}) {
h.counters.syncPartialErr.Add(1)
}
}
offset, resp, err := h.replicationSlaveFullSync(c)
if err != nil {
return resp, errors.Trace(err)
}
h.startSlaveReplication(c, offset)
return nil, nil
}
示例14: AuthCmd
// AUTH password
func AuthCmd(s Session, args [][]byte) (redis.Resp, error) {
if len(args) != 1 {
return toRespErrorf("len(args) = %d, expect = 1", len(args))
}
c, _ := s.(*conn)
if c == nil {
return nil, errors.New("invalid connection")
}
if len(c.h.config.Auth) == 0 {
return toRespErrorf("Client sent AUTH, but no password is set")
} else if c.h.config.Auth == string(args[0]) {
c.authenticated = true
return redis.NewString("OK"), nil
} else {
c.authenticated = false
return toRespErrorf("invalid password")
}
}
示例15: replicationReplyFullReSync
func (h *Handler) replicationReplyFullReSync(c *conn) error {
// lock all to get the current master replication offset
if err := c.Store().Acquire(); err != nil {
return errors.Trace(err)
}
syncOffset := h.repl.masterOffset
if h.repl.backlogBuf == nil {
// we will increment the master offset by one when backlog buffer created
syncOffset++
}
c.Store().Release()
if err := c.writeRESP(redis.NewString(fmt.Sprintf("FULLRESYNC %s %d", h.runID, syncOffset))); err != nil {
log.Errorf("reply slave %s psync FULLRESYNC err - %s", c, err)
c.Close()
return errors.Trace(err)
}
return nil
}