Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
E
elp
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Incidents
Environments
Packages & Registries
Packages & Registries
Package Registry
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
崔为之
elp
Commits
50a7f9c4
Commit
50a7f9c4
authored
Nov 21, 2023
by
崔为之
💪🏽
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Update project
parent
07a805f8
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
14 additions
and
19 deletions
+14
-19
application/utils/dsn/redis.py
application/utils/dsn/redis.py
+14
-19
No files found.
application/utils/dsn/redis.py
View file @
50a7f9c4
...
...
@@ -7,7 +7,7 @@
# @Email : StudentCWZ@outlook.com
# @Date : 2023/11/7 15:47
# @File : redis.py
# @Description :
# @Description :
Defines the RedisUri class for generating a Redis connection URI.
"""
...
...
@@ -15,21 +15,16 @@ class RedisUri:
"""
A class to generate a Redis connection URI.
"""
def
__init__
(
self
,
host
=
'localhost'
,
port
=
6379
,
db
=
0
,
username
=
None
,
password
=
None
):
"""
Initializes a new instance of the RedisUri class.
:param host: The hostname of the Redis server. Default is 'localhost'.
:type host: str
:param port: The port number to connect to the Redis server. Default is 6379.
:type port: int
:param db: The database number to connect to on the Redis server. Default is 0.
:type db: int
:param username: The username for authentication to the Redis server. Default is None.
:type username: str
:param password: The password for authentication to the Redis server. Default is None.
:type password: str
Args:
host (str): The hostname of the Redis server. Default is 'localhost'.
port (int): The port number to connect on the Redis server. Default is 6379.
db (int): The database number to connect on the Redis server. Default is 0.
username (str, optional): The username for authentication to the Redis server.
password (str, optional): The password for authentication to the Redis server.
"""
self
.
host
=
host
self
.
port
=
port
...
...
@@ -41,8 +36,8 @@ class RedisUri:
"""
Creates and returns the Redis connection URI.
:return: The Redis connection URI.
:rtype: str
Returns:
str: The Redis connection URI.
"""
if
self
.
username
and
self
.
password
:
return
f
'redis://
{
self
.
username
}
:
{
self
.
password
}
@
{
self
.
host
}
:
{
self
.
port
}
/
{
self
.
db
}
'
...
...
@@ -53,17 +48,17 @@ class RedisUri:
"""
Returns a formal string representation of the RedisUri object.
:return: The formal string representation of the RedisUri object.
:rtype: str
Returns:
str: The formal string representation of the RedisUri object.
"""
return
(
f
'RedisUri(host=
{
self
.
host
}
, port=
{
self
.
port
}
, db=
{
self
.
db
}
, username=
{
self
.
username
}
, '
f
'password=
{
self
.
password
}
)'
)
def
__str__
(
self
):
"""
Returns a string representation of the RedisUri object.
Returns a string representation of the RedisUri object
, which is the Redis connection URI
.
:return: The string representation of the RedisUri object.
:rtype: str
Returns:
str: The string representation of the RedisUri object.
"""
return
self
.
create
()
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment