not able to insert data using ZADD(sorted set ) in redis using python
@TheDude is almost close.
The newer version of redis from (redis-py 3.0), the method signature has changed. Along with ZADD, MSET and MSETNX signatures were also changed.
The old signature was:
data = "hello world"
score = 1
redis.zadd("redis_key_name", data, score) # not used in redis-py > 3.0
The new signature is:
data = "hello world"
score = 1
redis.zadd("redis_key_name", {data: score})
To add multiple at once:
data1 = "foo"
score1 = 10
data2 = "bar"
score2 = 20
redis.zadd("redis_key_name", {data1: score1, data2: score2})
Instead of args/kwargs, a dict is expected, with key as data and value is the ZADD score. There are no changes in retrieving the data back.
rediscleint.execute_command('ZADD', "rishu", 1, "123").this one works ...trying to figure how to add elements to sorted sets without using execute_command approach.