MCPcopy Create free account
hub / github.com/IceFireDB/IceFireDB / cmdBITOP

Function cmdBITOP

strings.go:569–610  ·  view source on GitHub ↗
(m uhaha.Machine, args []string)

Source from the content-addressed store, hash-verified

567 return redcon.SimpleInt(n), nil
568}
569
570func cmdBITOP(m uhaha.Machine, args []string) (interface{}, error) {
571 // Check the number of arguments
572 if len(args) < 4 {
573 return nil, uhaha.ErrWrongNumArgs
574 }
575
576 // Get the operation type
577 op := strings.ToUpper(args[1])
578 if op != "AND" && op != "OR" && op != "XOR" && op != "NOT" {
579 return nil, fmt.Errorf("ERR syntax error, invalid operation: %s", op)
580 }
581
582 // Get the destination key
583 destKey := []byte(args[2])
584
585 // Get the source keys
586 srcKeys := make([][]byte, 0)
587 if op == "NOT" {
588 // NOT operation requires exactly one source key
589 if len(args) != 3 {
590 return nil, uhaha.ErrWrongNumArgs
591 }
592 srcKeys = append(srcKeys, []byte(args[2]))
593 } else {
594 // AND, OR, XOR operations require at least one source key
595 if len(args) < 4 {
596 return nil, uhaha.ErrWrongNumArgs
597 }
598 for i := 3; i < len(args); i++ {
599 srcKeys = append(srcKeys, []byte(args[i]))
600 }
601 }
602
603 // Call the underlying BitOP function
604 n, err := ldb.BitOP(op, destKey, srcKeys...)
605 if err != nil {
606 return nil, err
607 }
608
609 // Return the length of the resulting string
610 return redcon.SimpleInt(n), nil
611}
612
613func cmdAPPEND(m uhaha.Machine, args []string) (interface{}, error) {

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected