MSetNx et multiple keys to multiple values,only if none of the keys exist TODO bug
(ctx *Context, txn *db.Transaction)
| 157 | // MSetNx et multiple keys to multiple values,only if none of the keys exist |
| 158 | //TODO bug |
| 159 | func MSetNx(ctx *Context, txn *db.Transaction) (OnCommit, error) { |
| 160 | argc := len(ctx.Args) |
| 161 | args := ctx.Args |
| 162 | if argc%2 != 0 { |
| 163 | return nil, ErrMSet |
| 164 | } |
| 165 | for i := 2; i <= argc; i += 2 { |
| 166 | if str, _ := txn.String([]byte(ctx.Args[0])); !str.Exist() { |
| 167 | ctx.Args = append(args[i-2:i], "nx") |
| 168 | if _, err := Set(ctx, txn); err != nil { |
| 169 | return nil, errors.New("ERR " + err.Error()) |
| 170 | } |
| 171 | ctx.Args = ctx.Args[2:] |
| 172 | continue |
| 173 | } |
| 174 | return Integer(ctx.Out, int64(0)), nil |
| 175 | } |
| 176 | return Integer(ctx.Out, int64(1)), nil |
| 177 | } |
| 178 | |
| 179 | // Strlen returns the length of the string value stored at key |
| 180 | func Strlen(ctx *Context, txn *db.Transaction) (OnCommit, error) { |