{"record":{"id":"30ce1b4a942f2c78","repo":"redis/redis-rb","slug":"can-t-supply-both-nx-and-xx","errorCode":null,"errorMessage":"can't supply both nx and xx","messagePattern":"can't supply both nx and xx","errorType":"exception","errorClass":"ArgumentError","httpStatus":null,"severity":"error","filePath":"lib/redis/commands/geo.rb","lineNumber":15,"sourceCode":"# frozen_string_literal: true\n\nclass Redis\n  module Commands\n    module Geo\n      # Adds the specified geospatial items (latitude, longitude, name) to the specified key\n      #\n      # @param [String] key\n      # @param [Array] member arguemnts for member or members: longitude, latitude, name\n      # @param [Boolean] nx don't update already existing elements, always add new ones (since Redis 6.2)\n      # @param [Boolean] xx only update elements that already exist, never add new ones (since Redis 6.2)\n      # @param [Boolean] ch modify the return value to the number of changed elements (since Redis 6.2)\n      # @return [Integer] number of elements added to the sorted set, or changed when `ch` is set\n      def geoadd(key, *member, nx: false, xx: false, ch: false)\n        raise ArgumentError, \"can't supply both nx and xx\" if nx && xx\n\n        args = [:geoadd, key]\n        args << \"NX\" if nx\n        args << \"XX\" if xx\n        args << \"CH\" if ch\n        args.concat(member)\n        send_command(args)\n      end\n\n      # Returns geohash string representing position for specified members of the specified key.\n      #\n      # @param [String] key\n      # @param [String, Array<String>] member one member or array of members\n      # @return [Array<String, nil>] returns array containg geohash string if member is present, nil otherwise\n      def geohash(key, member)\n        send_command([:geohash, key, member])\n      end\n","sourceCodeStart":1,"sourceCodeEnd":33,"githubUrl":"https://github.com/redis/redis-rb/blob/2ba9010b91dab9e0fde1fbae3a9aae003f8bc307/lib/redis/commands/geo.rb#L1-L33","documentation":"geoadd maps the nx:/xx: keywords to the server's GEOADD NX and XX flags. NX means 'only add new members, never update existing ones'; XX means 'only update existing members, never add' — mutually exclusive by definition. Passing both truthy raises ArgumentError 'can't supply both nx and xx' client-side before anything is sent (the server would reject NX XX too).","triggerScenarios":"redis.geoadd('Sicily', 13.36, 38.11, 'Palermo', nx: true, xx: true); option hashes merged from defaults plus user input where both keys end up set.","commonSituations":"Config-driven option merging (default nx: true, user overrides xx: true); wrappers around SET-style APIs where nx/xx pairs are familiar; enabling both flags 'to be safe'.","solutions":["Pick one semantic: nx: true (add-only) or xx: true (update-only), never both","When merging option hashes, resolve conflicts explicitly: delete :nx if :xx is set (or vice versa) before the call","ch: true composes with either flag — use it freely when you need changed-element counts"],"exampleFix":"# before\nredis.geoadd('Sicily', 13.36, 38.11, 'Palermo', nx: true, xx: true)  # ArgumentError\n\n# after\nredis.geoadd('Sicily', 13.36, 38.11, 'Palermo', nx: true, ch: true)","handlingStrategy":"validation","validationCode":"opts = { nx: nx, xx: xx, ch: ch }.compact\nopts.delete(:nx) if opts[:xx]  # resolve the conflict explicitly: xx wins\nredis.geoadd(key, *member, **opts)","typeGuard":null,"tryCatchPattern":"begin\n  redis.geoadd(key, *member, nx: nx, xx: xx)\nrescue ArgumentError => e\n  raise if e.message != \"can't supply both nx and xx\"\n  redis.geoadd(key, *member, xx: true)  # apply one semantic\nend","preventionTips":["Never merge nx/xx from independent sources without a conflict rule","Pick one flag per call site and state the intent in a comment or wrapper name","Remember ch composes with either flag"],"tags":["argument-validation","geo","mutually-exclusive-options"],"backgroundTag":"mutually-exclusive-flags","analyzedSha":"2ba9010b91dab9e0fde1fbae3a9aae003f8bc307","analyzedAt":"2026-08-23T03:54:57.017Z","schemaVersion":2},"datasetVersion":"2026-08-23T08:06:27.607Z"}