Skip to content

Commit 268bd7e

Browse files
authored
Merge pull request #9 from python-discord/release/0.2.0
Prepare the release of version 0.2.0 of Async RedisCache
2 parents b3a224b + 6b05bae commit 268bd7e

19 files changed

+961
-118
lines changed

.github/workflows/lint_test.yaml

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ jobs:
4343
${{ hashFiles('Pipfile') }}"
4444

4545
- name: Prepend PATH
46-
run: echo '::add-path::${{ env.PYTHONUSERBASE }}/bin'
46+
run: echo '${{ env.PYTHONUSERBASE }}/bin' >> $GITHUB_PATH
4747

4848
- name: Install pipenv
4949
run: pip install pipenv
@@ -57,4 +57,13 @@ jobs:
5757
run: python -m flake8
5858

5959
- name: Run unittest
60-
run: python -m unittest
60+
run: |
61+
python -m coverage run -m unittest
62+
python -m coverage report -m
63+
64+
# This step will publish the coverage reports coveralls.io and
65+
# print a "job" link in the output of the GitHub Action
66+
- name: Publish coverage report to coveralls.io
67+
env:
68+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
69+
run: python -m coveralls

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@
33
build/
44
dist/
55
*.egg-info
6+
.coverage

MANIFEST.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
recursive-exclude tests *
2+
recursive-include async_rediscache/redis_scripts *.lua

Pipfile

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,13 @@ flake8-string-format = "~=0.3.0"
1313
flake8-tidy-imports = "~=4.1.0"
1414
flake8-todo = "~=0.7"
1515
pep8-naming = "~=0.11.0"
16+
"coverage[toml]" = "~=5.3"
17+
coveralls = "~=2.2.0"
18+
time-machine = "~=1.3.0"
1619

1720
[packages]
1821
aioredis = "~=1.3.1"
19-
fakeredis = "~=1.4.3"
22+
"fakeredis[lua]" = "~=1.4.4"
2023

2124
[requires]
2225
python_version = "3.8"

Pipfile.lock

Lines changed: 195 additions & 16 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
[![Coverage Status](https://coveralls.io/repos/github/python-discord/async-rediscache/badge.svg?branch=master)](https://coveralls.io/github/python-discord/async-rediscache?branch=master)
2+
![Lint & Test](https://github.com/python-discord/async-rediscache/workflows/Lint%20&%20Test/badge.svg)
3+
![Release to PyPI](https://github.com/python-discord/async-rediscache/workflows/Release%20to%20PyPI/badge.svg)
4+
15
# Asynchronous Redis Cache
26
This package offers several data types to ease working with a Redis cache in an asynchronous workflow. The package is currently in development and it's not recommended to start using it in production at this point.
37

async_rediscache/redis_scripts/__init__.py

Whitespace-only changes.
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
local value = redis.call('HGET', KEYS[1], KEYS[2]);
2+
if not value then value = "i|0" end
3+
4+
local get_prefix = function (redis_value)
5+
local prefix_end = redis_value:find("|")
6+
return prefix_end, redis_value:sub(1, prefix_end-1)
7+
end
8+
9+
local value_prefix_end, value_prefix = get_prefix(value)
10+
if not value_prefix_end then
11+
return string.format("ValueError|received malformed value from keys %s %s: `%s`", KEYS[1], KEYS[1], value)
12+
end
13+
14+
local increment = ARGV[1]
15+
local incr_prefix_end, incr_prefix = get_prefix(increment)
16+
if not incr_prefix_end then
17+
return string.format("ValueError|received malformed increment value: `%s`", increment)
18+
end
19+
20+
local valid_prefixes = "if"
21+
local valid_values = valid_prefixes:match(value_prefix) and valid_prefixes:match(incr_prefix)
22+
if not valid_values then
23+
return string.format("TypeError|cannot increment value `%s` with `%s`.", value, ARGV[1])
24+
end
25+
26+
local new_value = value:sub(value_prefix_end+1) + increment:sub(incr_prefix_end+1)
27+
local result
28+
if incr_prefix..value_prefix == "ii" then
29+
result = string.format("i|%d", new_value)
30+
else
31+
result = string.format("f|%s", tostring(new_value))
32+
end
33+
34+
redis.call("HSET", KEYS[1], KEYS[2], result)
35+
return result
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
local popped_value = redis.call('HGET', KEYS[1], KEYS[2])
2+
redis.call('HDEL', KEYS[1], KEYS[2])
3+
return popped_value
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
local queue_size = redis.call("LLEN", KEYS[2])
2+
local client_tasks = redis.call("LRANGE", KEYS[2], 0, queue_size)
3+
4+
-- For Lua version compatibility, try picking the right version of unpack
5+
local unpack_function
6+
if unpack == nil then
7+
unpack_function = table.unpack
8+
else
9+
unpack_function = unpack
10+
end
11+
12+
if queue_size > 0 then
13+
redis.call("RPUSH", KEYS[1], unpack_function(client_tasks))
14+
end
15+
16+
redis.call("DEL", KEYS[2])
17+
return queue_size
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
local number_rescheduled = redis.call("LREM", KEYS[2], 1, ARGV[1])
2+
if number_rescheduled == 0 then
3+
return redis.error_reply("Task not found in pending tasks queue.")
4+
end
5+
6+
redis.call("LPUSH", KEYS[1], ARGV[1])

0 commit comments

Comments
 (0)