-1

I have application which I deployed on heroku server. I have a file

counter.txt which count the values.

It works fine on local host but when I run our app on heroku it value become zero after second time when I open our application online.

Any solution that keep my counter value as it is. and the vaule not become zero plz help me.

1 Answers1

0

Heroku constantly runs the code in the container, and every time the generated files will be erased. You need to use a database like postgres or redis to store the values. Heroku has free addons for these databases.

Your code will contain something like this

import os
import redis

r = redis.Redis(host=os.getenv('REDIS_URL'), port=6379, db=0)

r.set('foo', counter)

counter = r.get('foo')

See https://pypi.org/project/redis/ and https://devcenter.heroku.com/articles/heroku-redis documentation.

Urka
  • 65
  • 1
  • 7