How to use sadd with multiple elements in Redis using Python API?

前端 未结 2 1564
长情又很酷
长情又很酷 2021-02-07 12:04

Please consider the following example

>>import redis
>>redis_db_url = \'127.0.0.1\'
>>r = redis.StrictRedis(host = redis_db_url,port = 6379,db          


        
相关标签:
2条回答
  • 2021-02-07 12:44

    When you see the syntax *values in an argument list, it means the function takes a variable number of arguments.

    Therefore, call it as

    r.sadd('a', 1, 2, 3)
    

    You can pass an iterable by using the splat operator to unpack it:

    r.sadd('a', *set([3, 4]))
    

    or

    r.sadd('a', *[3, 4])
    
    0 讨论(0)
  • 2021-02-07 12:44

    Consider the following:

    r.sadd('a', 1, 2, 3)
    

    That should do the trick.

    0 讨论(0)
提交回复
热议问题