When using redis sorted set, I want to make class methods more readable. In redis-py, especially in sorted set, push
and update
operation work same. For example,
class A(object):
def push(self, key, value, score):
return redis.zadd(key, {value: score})
def update(self, key, value, score):
return self.push(key, value, score)
if __name__ == 'main':
a = A()
# push item1 in redis sorted set
a.push('sorted_set', 'item1', 1)
# update item1 in redis sorted set to score 2
# but I also know that this is same with
# a.push('sorted_set', 'item1', 2)
a.update('sorted_set', 'item1', 2)
However, I wondering that there is better way to solve this issue. Please let me know.