Skip to content

Commit

Permalink
fixup! fixup! fixup! fixup! fixup! fixup! Adapt to redis 3.*
Browse files Browse the repository at this point in the history
  • Loading branch information
em92 committed Aug 10, 2024
1 parent 75e4298 commit 8c21675
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 5 deletions.
3 changes: 0 additions & 3 deletions python/minqlx/database.py
Original file line number Diff line number Diff line change
Expand Up @@ -319,9 +319,6 @@ def close(self):
Redis._pool = None

if redis.VERSION > (3,):
def lrem(self, name, count, value):
return self.r.lrem(name, value, count)

def setex(self, name, time, value):
return self.r.setex(name, value, time)

Expand Down
21 changes: 19 additions & 2 deletions python/tests/test_database.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
from unittest import TestCase
import database
import random
import string
from time import sleep
from unittest import TestCase

import redis

import database


def random_string():
Expand All @@ -28,6 +31,20 @@ def test_zadd_01(self):
self.assertEqual(res["player1"], 2)
self.assertEqual(res["player2"], 6)

c.zadd(key, 4, "player2")
res = dict(c.zrange(key, 0, -1, withscores=True))
self.assertEqual(res["player1"], 2)
self.assertEqual(res["player2"], 4)

def test_zadd_02(self):
c = self.c
key = "zadd_02_key_" + random_string()

# redis-py 3.* introduced xx, nx, ch and incr kwarg params
# this codes deliberately does not work in redis-py 2.*
if redis.VERSION < (3,):
self.skipTest("Old version of redis package: %s" % (redis.VERSION,))
c.zadd(key, 5, "player1", 6, "player2")
c.zadd(key, {"player1": 3}, xx=True)
res = dict(c.zrange(key, 0, -1, withscores=True))
self.assertEqual(res["player1"], 3)
Expand Down

0 comments on commit 8c21675

Please sign in to comment.