diff options
author | michael-grunder <michael.grunder@gmail.com> | 2022-10-23 21:38:29 +0300 |
---|---|---|
committer | Michael Grunder <michael.grunder@gmail.com> | 2022-10-23 23:18:13 +0300 |
commit | 8c7c5a3aa2c6b693839a391bffa18ee161cbe73a (patch) | |
tree | 5da4bc9ca3f46d7ef1ee54a7ff643ef7d22c50be /tests | |
parent | 1343f5008301a256fcbfa0161931e2a39791055f (diff) |
Refactor SORT and add SORT_RO command
See #2068
Diffstat (limited to 'tests')
-rw-r--r-- | tests/RedisTest.php | 59 |
1 files changed, 32 insertions, 27 deletions
diff --git a/tests/RedisTest.php b/tests/RedisTest.php index ea036ebc..2a5085ca 100644 --- a/tests/RedisTest.php +++ b/tests/RedisTest.php @@ -1364,41 +1364,46 @@ class Redis_Test extends TestSuite public function testSortDesc() { - $this->setupSort(); + $this->setupSort(); - // sort by age and get IDs - $byAgeDesc = ['4','2','1','3']; - $this->assertEquals($byAgeDesc, $this->redis->sort('person:id', ['by' => 'person:age_*', 'sort' => 'desc'])); + // sort by age and get IDs + $byAgeDesc = ['4','2','1','3']; + $this->assertEquals($byAgeDesc, $this->redis->sort('person:id', ['by' => 'person:age_*', 'sort' => 'desc'])); - // sort by age and get names - $byAgeDesc = ['Dave', 'Bob', 'Alice', 'Carol']; - $this->assertEquals($byAgeDesc, $this->redis->sort('person:id', ['by' => 'person:age_*', 'get' => 'person:name_*', 'sort' => 'desc'])); + // sort by age and get names + $byAgeDesc = ['Dave', 'Bob', 'Alice', 'Carol']; + $this->assertEquals($byAgeDesc, $this->redis->sort('person:id', ['by' => 'person:age_*', 'get' => 'person:name_*', 'sort' => 'desc'])); - $this->assertEquals(array_slice($byAgeDesc, 0, 2), $this->redis->sort('person:id', ['by' => 'person:age_*', 'get' => 'person:name_*', 'limit' => [0, 2], 'sort' => 'desc'])); - $this->assertEquals(array_slice($byAgeDesc, 1, 2), $this->redis->sort('person:id', ['by' => 'person:age_*', 'get' => 'person:name_*', 'limit' => [1, 2], 'sort' => 'desc'])); + $this->assertEquals(array_slice($byAgeDesc, 0, 2), $this->redis->sort('person:id', ['by' => 'person:age_*', 'get' => 'person:name_*', 'limit' => [0, 2], 'sort' => 'desc'])); + $this->assertEquals(array_slice($byAgeDesc, 1, 2), $this->redis->sort('person:id', ['by' => 'person:age_*', 'get' => 'person:name_*', 'limit' => [1, 2], 'sort' => 'desc'])); - // sort by salary and get ages - $agesBySalaryDesc = ['41', '25', '27', '34']; - $this->assertEquals($agesBySalaryDesc, $this->redis->sort('person:id', ['by' => 'person:salary_*', 'get' => 'person:age_*', 'sort' => 'desc'])); + // sort by salary and get ages + $agesBySalaryDesc = ['41', '25', '27', '34']; + $this->assertEquals($agesBySalaryDesc, $this->redis->sort('person:id', ['by' => 'person:salary_*', 'get' => 'person:age_*', 'sort' => 'desc'])); - // sort non-alpha doesn't change all-string lists - $list = ['def', 'abc', 'ghi']; - $this->redis->del('list'); - foreach($list as $i) { - $this->redis->lPush('list', $i); - } + // sort non-alpha doesn't change all-string lists + $list = ['def', 'abc', 'ghi']; + $this->redis->del('list'); + foreach($list as $i) { + $this->redis->lPush('list', $i); + } - // SORT list → [ghi, abc, def] - if (version_compare($this->version, "2.5.0") < 0) { - $this->assertEquals(array_reverse($list), $this->redis->sort('list', ['sort' => 'desc'])); - } else { - // TODO rewrite, from 2.6.0 release notes: - // SORT now will refuse to sort in numerical mode elements that can't be parsed - // as numbers + // SORT list ALPHA → [abc, def, ghi] + $this->assertEquals(['ghi', 'def', 'abc'], $this->redis->sort('list', ['sort' => 'desc', 'alpha' => TRUE])); } - // SORT list ALPHA → [abc, def, ghi] - $this->assertEquals(['ghi', 'def', 'abc'], $this->redis->sort('list', ['sort' => 'desc', 'alpha' => TRUE])); + /* This test is just to make sure SORT and SORT_RO are both callable */ + public function testSortHandler() { + $this->redis->del('list'); + + $this->redis->rpush('list', 'c', 'b', 'a'); + + $methods = ['sort']; + if ($this->minVersionCheck('7.0.0')) $methods[] = 'sort_ro'; + + foreach ($methods as $method) { + $this->assertEquals(['a', 'b', 'c'], $this->redis->$method('list', ['sort' => 'asc', 'alpha' => true])); + } } // LINDEX |