Skip to content

Commit 99fc69f

Browse files
committed
Refctor.
1 parent 9b0923d commit 99fc69f

13 files changed

+133
-89
lines changed

Pipfile

+5-3
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,13 @@ name = "pypi"
33
url = "https://pypi.org/simple"
44
verify_ssl = true
55

6-
[dev-packages]
7-
86
[packages]
97
redis = "*"
108
loguru = "*"
9+
python-dotenv = "*"
10+
11+
[dev-packages]
12+
pytest = "*"
1113

1214
[requires]
13-
python_version = "3.7"
15+
python_version = "3.8"

Pipfile.lock

+83-3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Redis Python Tutorial
22

3-
![Python](https://img.shields.io/badge/Python-v^3.7-blue.svg?logo=python&longCache=true&logoColor=white&colorB=5e81ac&style=flat-square&colorA=4c566a)
3+
![Python](https://img.shields.io/badge/Python-v3.8-blue.svg?logo=python&longCache=true&logoColor=white&colorB=5e81ac&style=flat-square&colorA=4c566a)
44
![Redis](https://img.shields.io/badge/Redis-v3.2.1-red.svg?longCache=true&style=flat-square&logo=redis&logoColor=white&colorA=4c566a&colorB=bf616a)
55
![Loguru](https://img.shields.io/badge/Loguru-v0.4.1-blue.svg?longCache=true&logo=python&style=flat-square&logoColor=white&colorB=5e81ac&colorA=4c566a)
66
![GitHub Last Commit](https://img.shields.io/github/last-commit/google/skia.svg?style=flat-square&colorA=4c566a&colorB=a3be8c&logo=GitHub)

config.py

+6
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
"""Construct Redis connection URI."""
22
from os import environ
3+
from dotenv import load_dotenv
4+
5+
6+
# Load environment variables
7+
basedir = path.abspath(path.dirname(__file__))
8+
load_dotenv(path.join(basedir, '.env'))
39

410
redis_host = environ.get('REDIS_HOST')
511
redis_password = environ.get('REDIS_PASSWORD')

main.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
"""Entry point."""
2-
from redis_python_tutorial import init_redis_app
2+
from redis_python_tutorial import init_app
3+
4+
app = init_app()
35

46
if __name__ == "__main__":
5-
init_redis_app()
7+
app

pyproject.toml

+10-8
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[tool.poetry]
2-
name = "redis-python-tutorial"
2+
name = "redis_python_tutorial"
33
version = "0.1.0"
44
description = ""
55
authors = ["Todd Birchard <[email protected]>"]
@@ -9,14 +9,16 @@ readme = "README.md"
99
homepage = "https://hackersandslackers.com/redis-py-python/"
1010
repository = "https://github.com/hackersandslackers/redis-python-tutorial/"
1111
documentation = "https://hackersandslackers.com/redis-py-python/"
12-
keywords = ["Redis",
13-
"Cache",
14-
"Queue",
15-
"Sessions",
16-
"NoSQL"]
12+
keywords = [
13+
"Redis",
14+
"Cache",
15+
"Queue",
16+
"Memory",
17+
"NoSQL"
18+
]
1719

1820
[tool.poetry.dependencies]
19-
python = "^3.7"
21+
python = "3.8"
2022
redis = "*"
2123
loguru = "*"
2224
python-dotenv = "*"
@@ -26,7 +28,7 @@ requires = ["poetry>=0.12"]
2628
build-backend = "poetry.masonry.api"
2729

2830
[tool.poetry.scripts]
29-
run = "main:init_redis_app"
31+
run = "main:app"
3032

3133
[tool.poetry.urls]
3234
issues = "https://github.com/hackersandslackers/redis-python-tutorial/issues"

redis_python_tutorial/__init__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
from redis_python_tutorial.data.zset import sorted_set_values_demo
99

1010

11-
def init_redis_app():
11+
def init_app():
1212
"""Entry point function."""
1313
r.flushdb()
1414
init_db_with_values(r)

redis_python_tutorial/client.py

+14-10
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,17 @@
11
"""Create Redis client."""
22
import redis
3-
from config import (redis_host,
4-
redis_password,
5-
redis_port,
6-
redis_db)
3+
from config import (
4+
redis_host,
5+
redis_password,
6+
redis_port,
7+
redis_db
8+
)
79

8-
r = redis.StrictRedis(host=redis_host,
9-
password=redis_password,
10-
port=redis_port,
11-
db=redis_db,
12-
charset="utf-8",
13-
decode_responses=True,)
10+
r = redis.StrictRedis(
11+
host=redis_host,
12+
password=redis_password,
13+
port=redis_port,
14+
db=redis_db,
15+
charset="utf-8",
16+
decode_responses=True
17+
)
+2-3
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
1-
21
"""Set and manipulate data in Redis."""
3-
import time
2+
from time import time
43
from config import redis_expiration
54

65

76
def init_db_with_values(r):
87
"""Set single key/value pairs."""
98
r.set('ip_address', '0.0.0.0.')
10-
r.set('timestamp', int(time.time()))
9+
r.set('timestamp', int(time()))
1110
r.set('user_agent', 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_3)')
1211
r.set('current_page', 'account', redis_expiration)
1312
return r.keys()

redis_python_tutorial/data/set.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44

55
def set_values_demo(r):
6-
"""Execute unions and intersets between sets."""
6+
"""Execute unions and intersects between sets."""
77
# Add item to set 1
88
r.sadd('my_set_1', 'Y')
99
logger.info(f"my_set_1: {r.smembers('my_set_1')}'")

redis_python_tutorial/logging.py

+6-4
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@
33
from loguru import logger
44

55

6-
logger.add(sys.stderr,
7-
format="{message}",
8-
filter="redis_python_tutorial",
9-
level="INFO")
6+
logger.remove()
7+
logger.add(
8+
sys.stderr,
9+
format="{message}",
10+
level="INFO"
11+
)

requirements.txt

-10
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,3 @@
1-
atomicwrites==1.4.0
2-
attrs==19.3.0
31
loguru==0.5.1
4-
more-itertools==8.2.0
5-
packaging==20.1
6-
pluggy==0.13.1
7-
py==1.8.1
8-
pyparsing==2.4.6
9-
pytest==6.0.1
102
python-dotenv==0.14.0
113
redis==3.5.3
12-
six==1.14.0
13-
wcwidth==0.1.8

setup.py

-43
This file was deleted.

0 commit comments

Comments
 (0)