Snc Redis bundle set password in config.yml - symfony

I set a password on my local redis server, but it gives the following error:
"NOAUTH Authentication required."
How can I configure a Redis password in config.yml?

You can specify it in your dsn config.
snc_redis:
clients:
default:
type: predis
alias: default
dsn: 'redis://%redis_session_secret%#%redis_host%:%redis_port%'

For me this DSN format worked:
redis://127.0.0.1?password=yourpass
snc_redis:
clients:
default:
type: predis
alias: default
dsn: 'redis://127.0.0.1?password=yourpass'
Found in Wiki https://github.com/nrk/predis/wiki/Connection-Parameters

Related

Nonexistent parameter in Swiftmailer

In an attempt to configure both a memory & a spool mailer in a Symfony 4.3 application I followed the docs to create this configuration:
swiftmailer:
default_mailer: memory
mailers:
memory:
sender_address: 'admin#bogus.info'
transport: smtp
username: admin#bogus.info
password: 123Abcd
host: localhost
spool: { type: 'memory' }
spooler:
sender_address: 'admin#bogus.info'
transport: smtp
username: admin#bogus.info
password: 123Abcd
host: localhost
spool:
type: file
path: '%kernel.project_dir%/var/spool'
And in services.yaml:
App\Services\Emailer:
$spoolMailer: '%swiftmailer.mailer.spooler%'
$defaultMailer: '%swiftmailer.default_mailer%'
$senderAddress: '%swiftmailer.mailer.memory_mailer.sender_address%'
$projectDir: '%kernel.project_dir%'
But with those four parameters in the service the following occurs with php bin/console debug:container:
The service "App\Services\Emailer" has a dependency on a non-existent
parameter "swiftmailer.mailer.spooler"...
Why does this configuration not work?
The service "App\Services\Emailer" has a dependency on a non-existent parameter "swiftmailer.mailer.spooler"...
Surrounding parameters with the % symbol allows you to pass values to your services.
As you want to inject a service, you should prefix your parameter with the # symbol.
Also, to get the default mailer service, you have to inject #swiftmailer.mailer
EDIT: Proper way to retrieve the sender address: %swiftmailer.mailer.memory.sender_address%
Updated service definition :
App\Services\Emailer:
$spoolMailer: '#swiftmailer.mailer.spooler'
$defaultMailer: '#swiftmailer.mailer'
$senderAddress: '%swiftmailer.mailer.memory.sender_address%'
$projectDir: '%kernel.project_dir%'

FosElasticaBundle: how to dump the actual JSON passed to ElasticSearch?

I am using FosElasticaBundle in a Symfony project. I configured my mappings but I get exception "expected a simple value for field [_id] but found [START_OBJECT]]".
I'd like to see the actual JSON created by FosElasticaBundle so I can directly test it against my ElasticSearch server, and understand more about the exception.
According to FosElastica documentation, everything should be logged when debug mode is enabled (i.e. in DEV environment) but I can't see this happening; I only see Doctrine queries, but no JSON.
How can I dump the JSON created by FosElasticaBundle?
Update: mappings
# FOSElasticaBundle
fos_elastica:
clients:
default: { host: %elasticsearch_host%, port: %elasticsearch_port%, logger: false }
indexes:
app:
types:
user:
mappings:
name: ~
surname: ~
persistence:
driver: orm
model: AppBundle\Entity\User
provider: ~
listener: ~
finder: ~
I think you should only set your logger to true instead of false
fos_elastica:
clients:
default:
host: %elasticsearch_host%
port: %elasticsearch_port%
logger: true <---- set true here
...

Codeception - can't use DB module, because of invalid configuration

I've added DB module to acceptance suite.
And I've put:
modules:
config:
Db:
dsn: 'sqlite:storage/database.sqlite'
user:
password:
dump: tests/_data/dump.sql
in codeception.yml
Then i need to build:
cept build gives me:
[Codeception\Exception\ModuleConfig]
Db module is not configured!
Options: dsn, user, password are required
Please, update the configuration and set all the required fields
It's the same when I set user and password for dummy values.
I think sqlite doesn't need user and password - I can't get it work. I would appreciate any help, I'm clearly missing something.
You should set the user and password to empty values '' instead of nothing:
Db:
dsn: 'sqlite:storage/database.sqlite'
user: ''
password: ''
dump: tests/_data/dump.sql
try
modules:
enabled: [Db]
config:
Db:
dsn: 'sqlite:storage/database.sqlite'
user:
password:
dump: tests/_data/dump.sql
Db module requires user and password, these have filled

Connect Doctrine to memcached pool

Perhaps anybody know, how to connect Doctrine to memcached pool, to use it as a cache driver?
I've check official bundle documentation, and lot of another sources, but didn't find any examples of such connection.
Also due to source code, I could not find any options to use pool, but perhaps I miss something.
Didn't test, but the following should work:
in app/config/parameters.yml, set/add
parameters:
memcached.servers:
- { host: 127.0.0.1, port: 11211 }
- { host: 127.0.0.2, port: 11211 }
in app/config/config.yml set/add
services:
memcache:
# class 'Memcache' or 'Memcached', depending on which PHP module you use
class: Memcache
calls:
- [ addServers, [ %memcached.servers% ]]
doctrine.cache.memcached:
class: Doctrine\Common\Cache\MemcachedCache
calls:
- [setMemcached, [#memcached]]
in app/config/config_prod.yml, set
doctrine:
orm:
metadata_cache_driver:
type: service
id: doctrine.cache.memcached
query_cache_driver:
type: service
id: doctrine.cache.memcached
result_cache_driver:
type: service
id: doctrine.cache.memcached
As I said, I can't test it, but this is the combination of several known-to-work techniques.
UPDATE: solution updated based on CrazySquirrel's findings.
Thanks lxg for your ideas. I've build right configuration using your ideas. Please find correct service definition below:
application config:
result_cache_driver:
type: service
id: doctrine.cache.memcached
service.yml
memcached:
class: Memcached
calls:
- [ addServers, [ %memcached_servers% ]]
doctrine.cache.memcached:
class: Doctrine\Common\Cache\MemcachedCache
calls:
- [setMemcached, [#memcached]]

Redis with Symfony2 causes problems between sites on my server

I'm using symfony2 snc-redis bundle for caching.
On my server, redis has been installed and working correctly.
My problem is; when i try to clear or flush db with redis, all sites on my server that using redis, crashes. Giving internal server error because of prod env.
I'v tried to change redis configuration ports in my config.yml for every single site on my server but i think didn't work.
My sample snc-redis configuration:
snc_redis:
clients:
default:
type: predis
alias: default
dsn: redis://localhost
logging: %kernel.debug%
cache:
type: predis
alias: cache
dsn: redis://localhost/1
logging: true
cluster:
type: predis
alias: cluster
dsn:
- redis://127.0.0.1/5
- redis://127.0.0.2/6
- redis://pw#/var/run/redis/redis-1.sock/7
- redis://127.0.0.1:6379/8
options:
profile: 2.4
connection_timeout: 10
connection_persistent: true
read_write_timeout: 30
iterable_multibulk: false
throw_errors: true
cluster: Snc\RedisBundle\Client\Predis\Connection\PredisCluster
monolog:
type: predis
alias: monolog
dsn: redis://localhost/1
logging: false
options:
connection_persistent: true
session:
client: default
prefix: foo
use_as_default: true
doctrine:
metadata_cache:
client: cache
entity_manager: default
document_manager: default
result_cache:
client: cache
entity_manager: [default, read]
document_manager: [default, slave1, slave2]
namespace: "dcrc:"
query_cache:
client: cache
entity_manager: default
monolog:
client: monolog
key: monolog
swiftmailer:
client: default
key: swiftmailer
monolog:
handlers:
main:
type: service
id: monolog.handler.redis
level: debug
What i'm doing wrong? How can i get it work correctly and will not cause crashing.
My Redis Bundle for Symfon2:
Snc\RedisBundle\SncRedisBundle()
https://github.com/snc/SncRedisBundle
You can define prefix for each site like this:
snc_redis:
clients:
default:
dsn: "redis://localhost:6379"
options:
prefix : "site_name"
type: phpredis
alias: default
logging: %kernel.debug%
Note: You must to be considered to put this prefix to all clients ;)
Did you try to change client alias for every site ?

Resources