-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Add redis db alias for easy accessing redis db #25600
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
eddieruan-alibaba
merged 19 commits into
sonic-net:master
from
eddieruan-alibaba:eruan-alias
Mar 23, 2026
Merged
Changes from all commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
46e69fb
Add db alias
eddieruan-alibaba bf11dc7
Fix a typo
eddieruan-alibaba b90acdb
Merge branch 'master' into eruan-alias
eddieruan-alibaba ded2378
Merge branch 'master' into eruan-alias
eddieruan-alibaba 065b037
Merge branch 'master' into eruan-alias
eddieruan-alibaba 245ae97
Merge branch 'master' into eruan-alias
eddieruan-alibaba ca667ff
Merge branch 'sonic-net:master' into eruan-alias
eddieruan-alibaba e013d7e
Merge branch 'sonic-net:master' into eruan-alias
eddieruan-alibaba baef466
Merge branch 'sonic-net:master' into eruan-alias
eddieruan-alibaba 2a112f2
Merge branch 'sonic-net:master' into eruan-alias
eddieruan-alibaba 14a89f3
Merge branch 'sonic-net:master' into eruan-alias
eddieruan-alibaba 2dd2e02
Remove redis-sysmondb alias
eddieruan-alibaba 09b4de2
Merge branch 'sonic-net:master' into eruan-alias
eddieruan-alibaba 397b31f
Take care review comments from Aseem and Selva
eddieruan-alibaba c16932c
Update sonic-gnmi submodule to include UDS auth bypass (#26155)
hdwhdw d355fb3
Remove exit based on Aseem's comments
eddieruan-alibaba a52d37b
Add DCO sign-off for previous commit
eddieruan-alibaba db62f11
Reorg codes based on Ashwin's comments
eddieruan-alibaba 0a2a3ff
Update pythonscript name
eddieruan-alibaba File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,47 @@ | ||
| #!/usr/bin/env python3 | ||
| import sys | ||
|
|
||
| # Expect DB names as command-line arguments | ||
| db_names = sys.argv[1:] | ||
|
|
||
| if not db_names: | ||
| print('ERROR:No database names provided as arguments', file=sys.stderr) | ||
| sys.exit(1) | ||
|
|
||
| try: | ||
| import swsscommon.swsscommon | ||
|
|
||
| SonicDBConfig = None | ||
|
|
||
| if hasattr(swsscommon.swsscommon, 'SonicDBConfig'): | ||
| SonicDBConfig = swsscommon.swsscommon.SonicDBConfig | ||
|
|
||
| if SonicDBConfig is None: | ||
| print('ERROR:SonicDBConfig not found in swsscommon module', file=sys.stderr) | ||
| sys.exit(1) | ||
|
|
||
| # Initialize config (some versions require this) | ||
| try: | ||
| SonicDBConfig.loadSonicDBConfig() | ||
| except AttributeError: | ||
| pass # Some versions don't have this method | ||
| except Exception: | ||
| pass # Ignore if config file is missing | ||
|
|
||
| # Iterate over provided arguments | ||
| for db in db_names: | ||
| try: | ||
| db_id = SonicDBConfig.getDbId(db) | ||
| db_port = SonicDBConfig.getDbPort(db) | ||
| # Output format: DB_NAME:DB_ID:DB_PORT | ||
| print(f'{db}:{db_id}:{db_port}') | ||
| except Exception as e: | ||
| # Print error to stderr (will be captured by bash) | ||
| print(f'ERROR:Failed to get config for {db}: {e}', file=sys.stderr) | ||
|
|
||
| except ImportError as e: | ||
| print(f'ERROR:swsscommon module not found: {e}', file=sys.stderr) | ||
| sys.exit(1) | ||
| except Exception as e: | ||
| print(f'ERROR:Unexpected error: {e}', file=sys.stderr) | ||
| sys.exit(1) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.