Wednesday, 26 October 2022

redis default pwd, default port, default connection to celery

celery connection to redis in python or  django:

 https://docs.celeryq.dev/en/stable/getting-started/backends-and-brokers/redis.html#configuration

https://stackoverflow.com/questions/68090167/how-to-connect-celery-with-redis

in django set up the following in settings.py:

CELERY_BROKER_URL='redis://localhost:6379',
CELERY_RESULT_BACKEND='redis://localhost:6379'
These two entries give your Celery application instance 
enough information to know where to send messages and where to record the 
results of scheduled jobs
CELERY_BROKER_URL = send message
CELERY_RESULT_BACKEND = record results
in python:

app.conf.broker_url = 'redis://localhost:6379/0'


the url format is :

redis://:password@hostname:port/db_number

all fields after the scheme are optional, and will default to localhost on port 6379, using database 0.



redis (cache db) :

default tcp port 6379

start with a different port : 

https://stackoverflow.com/questions/27895165/how-to-start-redis-server-on-a-different-port-than-the-default-port-6379-in-ubun

redis-server --port 6380


default database : 0

https://www.digitalocean.com/community/cheatsheets/how-to-manage-redis-databases-and-keys

Redis databases are numbered from 0 to 15 and, by default, you connect to database 0 when you connect to your Redis instance. 

to change :

select 15



default pwd: redis requires no pwd by default 

to enable pwd :

https://stackoverflow.com/questions/7537905/how-to-set-password-for-redis


01) open redis configuration file


sudo vi /etc/redis/redis.conf

find requirepass field under SECURITY section and uncomment that field.Then set your password instead of "foobared"


# requirepass foobared

It should be like,


requirepass YOUR_PASSWORD

Then restart redis and start redis-cli.


If you need to check whether you have set the password correctly, you can run below commads in redis-cli.


sithara@sithara-X555UJ ~ $ redis-cli

127.0.0.1:6379> set key1 18

(error) NOAUTH Authentication required.

127.0.0.1:6379> auth admin

OK

127.0.0.1:6379> get key1

(nil)

127.0.0.1:6379> exit



sithara@sithara-X555UJ ~ $ redis-cli

127.0.0.1:6379> set key1 18

(error) NOAUTH Authentication required.

127.0.0.1:6379> auth admin

OK

127.0.0.1:6379> set key2 check

OK

127.0.0.1:6379> get key2

"check"

127.0.0.1:6379> get key1

(nil)

127.0.0.1:6379> set key1 20

OK

127.0.0.1:6379> get key1

"20"

127.0.0.1:6379> exit




No comments:

Post a Comment