Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8698031
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T01:39:19+00:00 2026-06-13T01:39:19+00:00

To be more specific, I have created a custom Redis module: MyRedis MyRedis.py import

  • 0

To be more specific, I have created a custom Redis module: MyRedis

MyRedis.py

import redis
r = redis.StrictRedis(host='localhost', port=6379, db=0)

def get_func(k):
    """ A custom get function """
    return r.get(k)

# ...
# more functions ...
# ...

Note that the connection is established when the module is loaded.
My question is:
Is this the correct way to write the module, or should I include the r = redis.StrictRedis(...) connection establishing line within each function, like so:

def get_func(k):
    """ A custom get function """
    r = redis.StrictRedis(host='localhost', port=6379, db=0)
    return r.get(k)

In a web app, is a module loaded only once, as in a “regular” backend app? Or is it loaded once per connection?
If it’s loaded only once, this means that if the Redis server crashes for some reason, once it’s started again there will be no connections, which suggests the second snippet is the correct one.
So how do python modules behave in a web app?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T01:39:20+00:00Added an answer on June 13, 2026 at 1:39 am

    However the SAPI behaves. If it’s CGI, it’s loaded for each request. For mod_wsgi, it’s loaded once for each process. For others, see their documentation.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I do have something more specific in mind, however: Each web service method needs
I have a chart in Highcharts (to be more specific: it's a Highstocks chart,
I have more than one Event Listener that calls a specific function, and I
I have created a custom WPF user control which is intended to be used
To be more specific I do not know what the exact values will be.
Surely an ordered set is a more-specific case of a set, so why does
Exists a way to call .net assemblies more specific .dll files in java? I
How to find out the more specific error situations like whether the error is
I am editing the question to make it more specific. I want to run
I'm reviving this question, and making it more specific: Is there a .NET framework

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.