File tree 13 files changed +133
-89
lines changed
13 files changed +133
-89
lines changed Original file line number Diff line number Diff line change @@ -3,11 +3,13 @@ name = "pypi"
3
3
url = " https://pypi.org/simple"
4
4
verify_ssl = true
5
5
6
- [dev-packages ]
7
-
8
6
[packages ]
9
7
redis = " *"
10
8
loguru = " *"
9
+ python-dotenv = " *"
10
+
11
+ [dev-packages ]
12
+ pytest = " *"
11
13
12
14
[requires ]
13
- python_version = " 3.7 "
15
+ python_version = " 3.8 "
Original file line number Diff line number Diff line change 1
1
# Redis Python Tutorial
2
2
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 )
4
4
![ 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 )
5
5
![ 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 )
6
6
![ GitHub Last Commit] ( https://img.shields.io/github/last-commit/google/skia.svg?style=flat-square&colorA=4c566a&colorB=a3be8c&logo=GitHub )
Original file line number Diff line number Diff line change 1
1
"""Construct Redis connection URI."""
2
2
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' ))
3
9
4
10
redis_host = environ .get ('REDIS_HOST' )
5
11
redis_password = environ .get ('REDIS_PASSWORD' )
Original file line number Diff line number Diff line change 1
1
"""Entry point."""
2
- from redis_python_tutorial import init_redis_app
2
+ from redis_python_tutorial import init_app
3
+
4
+ app = init_app ()
3
5
4
6
if __name__ == "__main__" :
5
- init_redis_app ()
7
+ app
Original file line number Diff line number Diff line change 1
1
[tool .poetry ]
2
- name = " redis-python-tutorial "
2
+ name = " redis_python_tutorial "
3
3
version = " 0.1.0"
4
4
description = " "
5
5
authors = [" Todd Birchard <toddbirchard@gmail.com>" ]
@@ -9,14 +9,16 @@ readme = "README.md"
9
9
homepage = " https://hackersandslackers.com/redis-py-python/"
10
10
repository = " https://github.com/hackersandslackers/redis-python-tutorial/"
11
11
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
+ ]
17
19
18
20
[tool .poetry .dependencies ]
19
- python = " ^3.7 "
21
+ python = " 3.8 "
20
22
redis = " *"
21
23
loguru = " *"
22
24
python-dotenv = " *"
@@ -26,7 +28,7 @@ requires = ["poetry>=0.12"]
26
28
build-backend = " poetry.masonry.api"
27
29
28
30
[tool .poetry .scripts ]
29
- run = " main:init_redis_app "
31
+ run = " main:app "
30
32
31
33
[tool .poetry .urls ]
32
34
issues = " https://github.com/hackersandslackers/redis-python-tutorial/issues"
Original file line number Diff line number Diff line change 8
8
from redis_python_tutorial .data .zset import sorted_set_values_demo
9
9
10
10
11
- def init_redis_app ():
11
+ def init_app ():
12
12
"""Entry point function."""
13
13
r .flushdb ()
14
14
init_db_with_values (r )
Original file line number Diff line number Diff line change 1
1
"""Create Redis client."""
2
2
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
+ )
7
9
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
+ )
Original file line number Diff line number Diff line change 1
-
2
1
"""Set and manipulate data in Redis."""
3
- import time
2
+ from time import time
4
3
from config import redis_expiration
5
4
6
5
7
6
def init_db_with_values (r ):
8
7
"""Set single key/value pairs."""
9
8
r .set ('ip_address' , '0.0.0.0.' )
10
- r .set ('timestamp' , int (time . time ()))
9
+ r .set ('timestamp' , int (time ()))
11
10
r .set ('user_agent' , 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_3)' )
12
11
r .set ('current_page' , 'account' , redis_expiration )
13
12
return r .keys ()
Original file line number Diff line number Diff line change 3
3
4
4
5
5
def set_values_demo (r ):
6
- """Execute unions and intersets between sets."""
6
+ """Execute unions and intersects between sets."""
7
7
# Add item to set 1
8
8
r .sadd ('my_set_1' , 'Y' )
9
9
logger .info (f"my_set_1: { r .smembers ('my_set_1' )} '" )
Original file line number Diff line number Diff line change 3
3
from loguru import logger
4
4
5
5
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
+ )
Original file line number Diff line number Diff line change 1
- atomicwrites == 1.4.0
2
- attrs == 19.3.0
3
1
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
10
2
python-dotenv == 0.14.0
11
3
redis == 3.5.3
12
- six == 1.14.0
13
- wcwidth == 0.1.8
Load Diff This file was deleted.
You can’t perform that action at this time.
0 commit comments