当前位置: 首页>>代码示例>>Golang>>正文


Golang Responder.WriteOK方法代码示例

本文整理汇总了Golang中github.com/bsm/redeo.Responder.WriteOK方法的典型用法代码示例。如果您正苦于以下问题:Golang Responder.WriteOK方法的具体用法?Golang Responder.WriteOK怎么用?Golang Responder.WriteOK使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在github.com/bsm/redeo.Responder的用法示例。


在下文中一共展示了Responder.WriteOK方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: cmdHmset

// MMSET
func (m *Miniredis) cmdHmset(out *redeo.Responder, r *redeo.Request) error {
	if len(r.Args) < 3 {
		setDirty(r.Client())
		out.WriteErrorString("ERR wrong number of arguments for 'hmset' command")
		return nil
	}
	key := r.Args[0]
	args := r.Args[1:]
	if len(args)%2 != 0 {
		setDirty(r.Client())
		out.WriteErrorString("ERR wrong number of arguments for HMSET")
		return nil
	}
	return withTx(m, out, r, func(out *redeo.Responder, ctx *connCtx) {
		db := m.db(ctx.selectedDB)

		if t, ok := db.keys[key]; ok && t != "hash" {
			out.WriteErrorString(msgWrongType)
			return
		}

		for len(args) > 0 {
			field := args[0]
			value := args[1]
			args = args[2:]

			db.hashSet(key, field, value)
		}
		out.WriteOK()
	})
}
开发者ID:jameswei,项目名称:xcodis,代码行数:32,代码来源:cmd_hash.go

示例2: cmdPsetex

// PSETEX
func (m *Miniredis) cmdPsetex(out *redeo.Responder, r *redeo.Request) error {
	if len(r.Args) != 3 {
		setDirty(r.Client())
		return r.WrongNumberOfArgs()
	}
	if !m.handleAuth(r.Client(), out) {
		return nil
	}
	key := r.Args[0]
	ttl, err := strconv.Atoi(r.Args[1])
	if err != nil {
		setDirty(r.Client())
		out.WriteErrorString(msgInvalidInt)
		return nil
	}
	value := r.Args[2]

	return withTx(m, out, r, func(out *redeo.Responder, ctx *connCtx) {
		db := m.db(ctx.selectedDB)

		db.del(key, true) // Clear any existing keys.
		db.stringSet(key, value)
		db.expire[key] = ttl // We put millisecond keys in with the second keys.
		out.WriteOK()
	})
}
开发者ID:Goyoo,项目名称:codis-docker,代码行数:27,代码来源:cmd_string.go

示例3: cmdMset

// MSET
func (m *Miniredis) cmdMset(out *redeo.Responder, r *redeo.Request) error {
	if len(r.Args) < 2 {
		setDirty(r.Client())
		return r.WrongNumberOfArgs()
	}
	if !m.handleAuth(r.Client(), out) {
		return nil
	}
	if len(r.Args)%2 != 0 {
		setDirty(r.Client())
		// non-default error message
		out.WriteErrorString("ERR wrong number of arguments for MSET")
		return nil
	}
	return withTx(m, out, r, func(out *redeo.Responder, ctx *connCtx) {
		db := m.db(ctx.selectedDB)

		for len(r.Args) > 0 {
			key := r.Args[0]
			value := r.Args[1]
			r.Args = r.Args[2:]

			db.del(key, true) // clear TTL
			db.stringSet(key, value)
		}
		out.WriteOK()
	})
}
开发者ID:Goyoo,项目名称:codis-docker,代码行数:29,代码来源:cmd_string.go

示例4: cmdFlushall

// FLUSHALL
func (m *Miniredis) cmdFlushall(out *redeo.Responder, r *redeo.Request) error {
	if len(r.Args) > 0 {
		setDirty(r.Client())
		return r.WrongNumberOfArgs()
	}
	if !m.handleAuth(r.Client(), out) {
		return nil
	}

	return withTx(m, out, r, func(out *redeo.Responder, ctx *connCtx) {
		m.dbs = map[int]*RedisDB{}
		out.WriteOK()
	})
}
开发者ID:Goyoo,项目名称:codis-docker,代码行数:15,代码来源:cmd_server.go

示例5: cmdFlushdb

// FLUSHDB
func (m *Miniredis) cmdFlushdb(out *redeo.Responder, r *redeo.Request) error {
	if len(r.Args) > 0 {
		setDirty(r.Client())
		return r.WrongNumberOfArgs()
	}
	if !m.handleAuth(r.Client(), out) {
		return nil
	}

	return withTx(m, out, r, func(out *redeo.Responder, ctx *connCtx) {
		delete(m.dbs, ctx.selectedDB)
		out.WriteOK()
	})
}
开发者ID:Goyoo,项目名称:codis-docker,代码行数:15,代码来源:cmd_server.go

示例6: cmdUnwatch

// UNWATCH
func (m *Miniredis) cmdUnwatch(out *redeo.Responder, r *redeo.Request) error {
	if len(r.Args) != 0 {
		setDirty(r.Client())
		out.WriteErrorString("ERR wrong number of arguments for 'unwatch' command")
		return nil
	}

	// Doesn't matter if UNWATCH is in a TX or not. Looks like a Redis bug to me.
	unwatch(getCtx(r.Client()))

	return withTx(m, out, r, func(out *redeo.Responder, ctx *connCtx) {
		// Do nothing if it's called in a transaction.
		out.WriteOK()
	})
}
开发者ID:jameswei,项目名称:xcodis,代码行数:16,代码来源:cmd_transactions.go

示例7: cmdMulti

// MULTI
func (m *Miniredis) cmdMulti(out *redeo.Responder, r *redeo.Request) error {
	if len(r.Args) != 0 {
		out.WriteErrorString("ERR wrong number of arguments for 'multi' command")
		return nil
	}
	ctx := getCtx(r.Client())

	if inTx(ctx) {
		out.WriteErrorString("ERR MULTI calls can not be nested")
		return nil
	}

	startTx(ctx)

	out.WriteOK()
	return nil
}
开发者ID:jameswei,项目名称:xcodis,代码行数:18,代码来源:cmd_transactions.go

示例8: cmdDiscard

// DISCARD
func (m *Miniredis) cmdDiscard(out *redeo.Responder, r *redeo.Request) error {
	if len(r.Args) != 0 {
		setDirty(r.Client())
		out.WriteErrorString("ERR wrong number of arguments for 'discard' command")
		return nil
	}

	ctx := getCtx(r.Client())
	if !inTx(ctx) {
		out.WriteErrorString("ERR DISCARD without MULTI")
		return nil
	}

	stopTx(ctx)
	out.WriteOK()
	return nil
}
开发者ID:jameswei,项目名称:xcodis,代码行数:18,代码来源:cmd_transactions.go

示例9: cmdUnwatch

// UNWATCH
func (m *Miniredis) cmdUnwatch(out *redeo.Responder, r *redeo.Request) error {
	if len(r.Args) != 0 {
		setDirty(r.Client())
		return r.WrongNumberOfArgs()
	}
	if !m.handleAuth(r.Client(), out) {
		return nil
	}

	// Doesn't matter if UNWATCH is in a TX or not. Looks like a Redis bug to me.
	unwatch(getCtx(r.Client()))

	return withTx(m, out, r, func(out *redeo.Responder, ctx *connCtx) {
		// Do nothing if it's called in a transaction.
		out.WriteOK()
	})
}
开发者ID:Goyoo,项目名称:codis-docker,代码行数:18,代码来源:cmd_transactions.go

示例10: cmdDiscard

// DISCARD
func (m *Miniredis) cmdDiscard(out *redeo.Responder, r *redeo.Request) error {
	if len(r.Args) != 0 {
		setDirty(r.Client())
		return r.WrongNumberOfArgs()
	}
	if !m.handleAuth(r.Client(), out) {
		return nil
	}

	ctx := getCtx(r.Client())
	if !inTx(ctx) {
		return redeo.ClientError("DISCARD without MULTI")
	}

	stopTx(ctx)
	out.WriteOK()
	return nil
}
开发者ID:Goyoo,项目名称:codis-docker,代码行数:19,代码来源:cmd_transactions.go

示例11: cmdMulti

// MULTI
func (m *Miniredis) cmdMulti(out *redeo.Responder, r *redeo.Request) error {
	if len(r.Args) != 0 {
		return r.WrongNumberOfArgs()
	}
	if !m.handleAuth(r.Client(), out) {
		return nil
	}

	ctx := getCtx(r.Client())

	if inTx(ctx) {
		return redeo.ClientError("MULTI calls can not be nested")
	}

	startTx(ctx)

	out.WriteOK()
	return nil
}
开发者ID:Goyoo,项目名称:codis-docker,代码行数:20,代码来源:cmd_transactions.go

示例12: cmdLset

// LSET
func (m *Miniredis) cmdLset(out *redeo.Responder, r *redeo.Request) error {
	if len(r.Args) != 3 {
		setDirty(r.Client())
		return r.WrongNumberOfArgs()
	}
	if !m.handleAuth(r.Client(), out) {
		return nil
	}
	key := r.Args[0]
	index, err := strconv.Atoi(r.Args[1])
	if err != nil {
		setDirty(r.Client())
		out.WriteErrorString(msgInvalidInt)
		return nil
	}
	value := r.Args[2]

	return withTx(m, out, r, func(out *redeo.Responder, ctx *connCtx) {
		db := m.db(ctx.selectedDB)

		if !db.exists(key) {
			out.WriteErrorString(msgKeyNotFound)
			return
		}
		if db.t(key) != "list" {
			out.WriteErrorString(msgWrongType)
			return
		}

		l := db.listKeys[key]
		if index < 0 {
			index = len(l) + index
		}
		if index < 0 || index > len(l)-1 {
			out.WriteErrorString(msgOutOfRange)
			return
		}
		l[index] = value
		db.keyVersion[key]++

		out.WriteOK()
	})
}
开发者ID:Goyoo,项目名称:codis-docker,代码行数:44,代码来源:cmd_list.go

示例13: cmdLtrim

// LTRIM
func (m *Miniredis) cmdLtrim(out *redeo.Responder, r *redeo.Request) error {
	if len(r.Args) != 3 {
		setDirty(r.Client())
		return r.WrongNumberOfArgs()
	}
	if !m.handleAuth(r.Client(), out) {
		return nil
	}
	key := r.Args[0]
	start, err := strconv.Atoi(r.Args[1])
	if err != nil {
		setDirty(r.Client())
		out.WriteErrorString(msgInvalidInt)
		return nil
	}
	end, err := strconv.Atoi(r.Args[2])
	if err != nil {
		setDirty(r.Client())
		out.WriteErrorString(msgInvalidInt)
		return nil
	}

	return withTx(m, out, r, func(out *redeo.Responder, ctx *connCtx) {
		db := m.db(ctx.selectedDB)

		t, ok := db.keys[key]
		if !ok {
			out.WriteOK()
			return
		}
		if t != "list" {
			out.WriteErrorString(msgWrongType)
			return
		}

		l := db.listKeys[key]
		rs, re := redisRange(len(l), start, end, false)
		db.listKeys[key] = l[rs:re]
		db.keyVersion[key]++
		out.WriteOK()
	})
}
开发者ID:Goyoo,项目名称:codis-docker,代码行数:43,代码来源:cmd_list.go

示例14: cmdSelect

// SELECT
func (m *Miniredis) cmdSelect(out *redeo.Responder, r *redeo.Request) error {
	if len(r.Args) != 1 {
		setDirty(r.Client())
		out.WriteErrorString("usage error")
		return nil
	}
	id, err := strconv.Atoi(r.Args[0])
	if err != nil {
		id = 0
	}

	m.Lock()
	defer m.Unlock()

	ctx := getCtx(r.Client())
	ctx.selectedDB = id

	out.WriteOK()
	return nil
}
开发者ID:jameswei,项目名称:xcodis,代码行数:21,代码来源:cmd_connection.go

示例15: cmdAuth

// AUTH
func (m *Redico) cmdAuth(out *redeo.Responder, r *redeo.Request) error {
	if len(r.Args) != 1 {
		setDirty(r.Client())
		return r.WrongNumberOfArgs()
	}
	pw := r.Args[0]

	m.Lock()
	defer m.Unlock()
	if m.password == "" {
		out.WriteErrorString("ERR Client sent AUTH, but no password is set")
		return nil
	}
	if m.password != pw {
		out.WriteErrorString("ERR invalid password")
		return nil
	}

	setAuthenticated(r.Client())
	out.WriteOK()
	return nil
}
开发者ID:yqj2012,项目名称:Coolpy5Sub,代码行数:23,代码来源:cmd_connnection.go


注:本文中的github.com/bsm/redeo.Responder.WriteOK方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。