Saturday, September 30, 2017

Redis: ZADD

https://github.com/andymccurdy/redis-py/issues/771

>>> import redis
>>> r = redis.StrictRedis()
>>> d = {'foo': 1.5, 'bar': 2.5}
>>> r.zadd('testing1', **d)
2
>>> d1 = r.zrange('testing1', 0, -1, withscores=True)
>>> d1
[('foo', 1.5), ('bar', 2.5)]
>>> r.zadd('testing2', **dict(d1))
2
>>> r.zrange('testing2', 0, -1, withscores=True)
[('foo', 1.5), ('bar', 2.5)]

http://redis-py.readthedocs.io/en/latest/_modules/redis/client.html

https://redis.io/commands/zrangebyscore

https://www.w3resource.com/redis/redis-zadd-key-score1-member1.php

def zaddWithTimeScore(self, keyname, key1):
   """ Redis zadd that uses the current time for the score
   """
   score1 = str(float(time.time()))

   print("keyname: " + str(keyname) + " key1: " + str(key1) + " score1: " + str(score1))

   dict = {key1: score1}
 
   self.cache.zadd(keyname, **dict)

No comments:

Post a Comment