Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 13 additions & 5 deletions radio/utility.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,19 @@
import redis
from django.conf import settings


class RedisQueue(object):
"""Simple Queue with Redis Backend"""
def __init__(self, name, namespace='tp', **redis_kwargs):
"""The default connection parameters are: host='localhost', port=6379, db=0"""
self.__db= redis.Redis(**redis_kwargs)
self.key = '%s:%s' %(namespace, name)

def __init__(self, name, namespace="tp", **redis_kwargs):
"""The default connection parameters are: host='localhost', port=6379, db=0"""
self.__db = redis.Redis(
host=settings.REDIS_HOST,
port=settings.REDIS_PORT,
db=settings.REDIS_DB,
**redis_kwargs
)
self.key = "%s:%s" % (namespace, name)

def qsize(self):
"""Return the approximate size of the queue."""
Expand All @@ -20,7 +28,7 @@ def put(self, item):
self.__db.rpush(self.key, item)

def get(self, block=True, timeout=None):
"""Remove and return an item from the queue.
"""Remove and return an item from the queue.

If optional args block is true and timeout is None (the default), block
if necessary until an item is available."""
Expand Down
4 changes: 2 additions & 2 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
aioredis==1.3.1
asgiref==3.3.4
asgiref==3.5.2
async-timeout==3.0.1
attrs==21.2.0
autobahn
Automat==20.2.0
certifi==2021.5.30
cffi==1.14.6
channels==3.0.4
channels==3.0.5
channels-redis==3.3.0
chardet==4.0.0
charset-normalizer==2.0.4
Expand Down
14 changes: 9 additions & 5 deletions trunk_player/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,20 +165,25 @@
MEDIA_URL = '/media/'
MEDIA_ROOT = os.path.join(BASE_DIR, "audio_files")

REDIS_HOST = "127.0.0.1"
REDIS_PORT = "6379"
REDIS_URL = "redis://" + REDIS_HOST + ":" + REDIS_PORT
REDIS_DB = "1"

# Channel settings
CHANNEL_LAYERS = {
"default": {
"BACKEND": "channels_redis.core.RedisChannelLayer",
"CONFIG": {
"hosts": [os.environ.get('REDIS_URL', 'redis://127.0.0.1:6379')],
"hosts": [os.environ.get('REDIS_URL', REDIS_URL)],
}
},
}

CACHES = {
"default": {
"BACKEND": "django_redis.cache.RedisCache",
"LOCATION": "redis://127.0.0.1:6379/1",
"LOCATION": REDIS_URL + "/1",
"OPTIONS": {
"CLIENT_CLASS": "django_redis.client.DefaultClient",
}
Expand All @@ -189,7 +194,7 @@
# 0 will disable the limit
ANONYMOUS_TIME = int(os.environ.get("ANONYMOUS_TIME", '43200')) # 1 Month (60min * 24hours * 30days)

# This Agency must exist in radio.Agency
# This Agency must exist in radio.Agency
RADIO_DEFAULT_UNIT_AGENCY = 0

SITE_ID = 1
Expand Down Expand Up @@ -248,7 +253,7 @@

USE_RAW_ID_FIELDS = os.getenv("USE_RAW_ID_FIELDS", 'False').lower() in ('true', '1', 't')

# Load our local settings
# Load our local settings
try:
LOCAL_SETTINGS
except NameError:
Expand All @@ -257,4 +262,3 @@
except ImportError:
pass
# print("Failed to open settings_local.py")