在使用redis排序集时,我希望使类方法更具可读性。在redis-py中,尤其是在排序集中,push
和update
操作的工作方式相同。例如
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)
不过,我想知道有没有更好的办法来解决这个问题。请告诉我
我从来没有见过这种用法,所以这可能不是“推荐”,但技术上你可以做到这一点
另见this
相关问题 更多 >
编程相关推荐