Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
if numkeys < 1:
raise redis.ResponseError(ZUNIONSTORE_KEYS_MSG)
if numkeys > len(args):
raise redis.ResponseError(SYNTAX_ERROR_MSG)
aggregate = b'sum'
sets = []
for i in range(numkeys):
item = CommandItem(args[i], self._db, item=self._db.get(args[i]), default=ZSet())
sets.append(self._get_zset(item.value))
weights = [1.0] * numkeys
i = numkeys
while i < len(args):
arg = args[i]
if casematch(arg, b'weights') and i + numkeys < len(args):
weights = [Float.decode(x) for x in args[i + 1:i + numkeys + 1]]
i += numkeys + 1
elif casematch(arg, b'aggregate') and i + 1 < len(args):
aggregate = casenorm(args[i + 1])
if aggregate not in (b'sum', b'min', b'max'):
raise redis.ResponseError(SYNTAX_ERROR_MSG)
i += 2
else:
raise redis.ResponseError(SYNTAX_ERROR_MSG)
out_members = set(sets[0])
for s in sets[1:]:
if func == 'ZUNIONSTORE':
out_members |= set(s)
else:
out_members.intersection_update(s)
def incrbyfloat(self, key, amount):
# TODO: introduce convert_order so that we can specify amount is Float
c = Float.decode(key.get(b'0')) + Float.decode(amount)
if not isfinite(c):
raise redis.ResponseError(NONFINITE_MSG)
encoded = Float.encode(c, True)
key.update(encoded)
return encoded
xx = True
i += 1
else:
# First argument not matching flags indicates the start of
# score pairs.
break
if nx and xx:
raise redis.ResponseError(ZADD_NX_XX_ERROR_MSG)
elements = args[i:]
if not elements or len(elements) % 2 != 0:
raise redis.ResponseError(SYNTAX_ERROR_MSG)
# Parse all scores first, before updating
items = [
(Float.decode(elements[j]), elements[j + 1])
for j in range(0, len(elements), 2)
]
old_len = len(zset)
changed_items = 0
for item_score, item_name in items:
if (
(not nx or item_name not in zset)
and (not xx or item_name in zset)
):
if zset.add(item_name, item_score):
changed_items += 1
if changed_items:
key.updated()
def decode(cls, value):
try:
exclusive = False
if value[:1] == b'(':
exclusive = True
value = value[1:]
value = Float.decode(
value, allow_leading_whitespace=True, allow_erange=True,
allow_empty=True, crop_null=True)
return cls(value, exclusive)
except redis.ResponseError:
raise redis.ResponseError(INVALID_MIN_MAX_FLOAT_MSG)