Skip to content

Commit 12c3110

Browse files
committed
minor progress
1 parent b6bee63 commit 12c3110

File tree

6 files changed

+71
-61
lines changed

6 files changed

+71
-61
lines changed

.gitignore

+7
Original file line numberDiff line numberDiff line change
@@ -128,4 +128,11 @@ dmypy.json
128128
# Pyre type checker
129129
.pyre/
130130

131+
# OSX
131132
.DS_Store
133+
134+
# PyCharm
135+
.idea
136+
137+
# Etc
138+
ignoreme.py

poetry.lock

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

pyproject.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ requires = ["poetry>=0.12"]
2929
build-backend = "poetry.masonry.api"
3030

3131
[tool.poetry.scripts]
32-
init = "wsgi:main"
32+
run = "wsgi:main"
3333

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

redis_python_tutorial/__init__.py

+4-59
Original file line numberDiff line numberDiff line change
@@ -1,63 +1,8 @@
1-
"""Application entry point."""
2-
import sys
3-
import redis
4-
import json
5-
from loguru import logger
6-
import time
7-
from config import (redis_host,
8-
redis_password,
9-
redis_port,
10-
redis_db,
11-
redis_expiration)
12-
13-
r = redis.StrictRedis(host=redis_host,
14-
password=redis_password,
15-
port=redis_port,
16-
db=redis_db,
17-
charset="utf-8",
18-
decode_responses=True)
19-
20-
21-
logger.add(sys.stderr,
22-
format="{time} {level} {message}",
23-
filter="redis_python_tutorial",
24-
level="INFO")
1+
from redis_python_tutorial.client import r
2+
from redis_python_tutorial.data import set_single_values, set_nested_values
253

264

275
def main():
286
"""Create records in Redis."""
29-
set_single_values()
30-
set_nested_values()
31-
32-
33-
def set_single_values():
34-
"""Set single key/value pairs."""
35-
r.set('ip_address', '0.0.0.0.')
36-
r.set('timestamp', int(time.time()))
37-
r.set('user_agent', 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_3)')
38-
r.set('current_page', 'account', redis_expiration)
39-
logger.info(r.keys())
40-
41-
42-
def set_nested_values():
43-
"""Set a nested dictionary."""
44-
record = {
45-
"name": "Hackers and Slackers",
46-
"type": "Mediocre tutorials",
47-
"address": {
48-
"street": "42 E 69th Street",
49-
"city": "New York",
50-
"state": "NY",
51-
"zip": 10009,
52-
},
53-
"profiles": {
54-
"website": "https://hackersandslackers.com/",
55-
"twitter": "https://twitter.com/hackersslackers",
56-
"facebook": "https://www.facebook.com/groups/hackersnslackers"
57-
},
58-
"owner": {
59-
"name": "Todd Birchard",
60-
"email": "todd@example.com"
61-
}
62-
}
63-
r.hmset('business', json.dumps(record))
7+
set_single_values(r)
8+
set_nested_values(r)

redis_python_tutorial/client.py

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import redis
2+
from config import (redis_host,
3+
redis_password,
4+
redis_port,
5+
redis_db)
6+
7+
r = redis.StrictRedis(host=redis_host,
8+
password=redis_password,
9+
port=redis_port,
10+
db=redis_db,
11+
charset="utf-8",
12+
decode_responses=True)

redis_python_tutorial/data.py

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
"""Application entry point."""
2+
import time
3+
from config import redis_expiration
4+
from loguru import logger
5+
import sys
6+
7+
8+
logger.add(sys.stderr,
9+
format="{time} {level} {message}",
10+
filter="redis_python_tutorial",
11+
level="INFO")
12+
13+
14+
def set_single_values(r):
15+
"""Set single key/value pairs."""
16+
r.set('ip_address', '0.0.0.0.')
17+
r.set('timestamp', int(time.time()))
18+
r.set('user_agent', 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_3)')
19+
r.set('current_page', 'account', redis_expiration)
20+
logger.info(r.keys())
21+
22+
23+
def set_nested_values(r):
24+
"""Set a dictionary."""
25+
record = {
26+
"name": "Hackers and Slackers",
27+
"description": "Mediocre tutorials",
28+
"website": "https://hackersandslackers.com/",
29+
"github": "https://github.com/hackersandslackers"
30+
}
31+
r.hmset('business', record)

0 commit comments

Comments
 (0)