Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 99fc69f

Browse files
Refctor.
1 parent 9b0923d commit 99fc69f

File tree

13 files changed

+133
-89
lines changed

13 files changed

+133
-89
lines changed

‎Pipfile

Lines changed: 5 additions & 3 deletions
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

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

‎README.md

Lines changed: 1 addition & 1 deletion
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

Lines changed: 6 additions & 0 deletions
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

Lines changed: 4 additions & 2 deletions
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

Lines changed: 10 additions & 8 deletions
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 <toddbirchard@gmail.com>"]
@@ -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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 14 additions & 10 deletions
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+
)

‎redis_python_tutorial/data/__init__.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
1-
21
"""Set and manipulate data in Redis."""
3-
import time
2+
fromtimeimport 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

Lines changed: 1 addition & 1 deletion
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')}'")

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /