confd
confd copied to clipboard
-watch is no work for redis backend
I use -watch
for redis backend ,but it's no work for me. I update the key in redis backend, but there is no confd logs and the conf file which is generated by confd is not updated.
- confd version is
0.16.0
- redis version :
3.2.11
# /usr/local/bin/confd -version
confd 0.16.0 (Git SHA: 7217b0ca, Go Version: go1.10.2)
# sha256sum /usr/local/bin/confd
255d2559f3824dd64df059bdc533fd6b697c070db603c76aaf8d1d5e6b0cc334 /usr/local/bin/confd
- confd.toml
# cat /etc/confd/confd.toml
backend = "redis"
confdir = "/etc/confd"
log-level = "debug"
interval = 5
nodes = [
"127.0.0.1:16379",
]
scheme = "http"
watch = true
- myconfig.toml
[template]
src = "myconfig.conf.tmpl"
dest = "/etc/confd/file/myconfig.conf"
keys = [
"/myapp/database/url",
"/myapp/database/user",
]
- template: myconfig.conf.tmpl
[myconfig]
database_url = {{getv "/myapp/database/url"}}
database_user = {{getv "/myapp/database/user"}}
- confd log
# /usr/local/bin/confd -config-file confd.toml
2018-10-18T16:51:15+08:00 localhost /usr/local/bin/confd[22040]: INFO Backend set to redis
2018-10-18T16:51:15+08:00 localhost /usr/local/bin/confd[22040]: INFO Starting confd
2018-10-18T16:51:15+08:00 localhost /usr/local/bin/confd[22040]: INFO Backend source(s) set to 127.0.0.1:16379
2018-10-18T16:51:15+08:00 localhost /usr/local/bin/confd[22040]: DEBUG Redis Separator: "/"
2018-10-18T16:51:15+08:00 localhost /usr/local/bin/confd[22040]: DEBUG Trying to connect to redis node 127.0.0.1:16379
2018-10-18T16:51:15+08:00 localhost /usr/local/bin/confd[22040]: DEBUG Loading template resources from confdir /etc/confd
2018-10-18T16:51:15+08:00 localhost /usr/local/bin/confd[22040]: DEBUG Found template: /etc/confd/conf.d/myconfig.toml
2018-10-18T16:51:15+08:00 localhost /usr/local/bin/confd[22040]: DEBUG Loading template resource from /etc/confd/conf.d/myconfig.toml
2018-10-18T16:51:15+08:00 localhost /usr/local/bin/confd[22040]: DEBUG Retrieving keys from store
2018-10-18T16:51:15+08:00 localhost /usr/local/bin/confd[22040]: DEBUG Key prefix set to /
2018-10-18T16:51:15+08:00 localhost /usr/local/bin/confd[22040]: DEBUG Testing existing redis connection.
2018-10-18T16:51:15+08:00 localhost /usr/local/bin/confd[22040]: DEBUG Key Map: map[string]string{"/myapp/database/url":"exam", "/myapp/database/user":"rob"}
2018-10-18T16:51:15+08:00 localhost /usr/local/bin/confd[22040]: DEBUG Got the following map from store: map[/myapp/database/url:exam /myapp/database/user:rob]
2018-10-18T16:51:15+08:00 localhost /usr/local/bin/confd[22040]: DEBUG Using source template /etc/confd/templates/myconfig.conf.tmpl
2018-10-18T16:51:15+08:00 localhost /usr/local/bin/confd[22040]: DEBUG Compiling source template /etc/confd/templates/myconfig.conf.tmpl
2018-10-18T16:51:15+08:00 localhost /usr/local/bin/confd[22040]: DEBUG Comparing candidate config to /etc/confd/file/myconfig.conf
2018-10-18T16:51:15+08:00 localhost /usr/local/bin/confd[22040]: DEBUG Target config /etc/confd/file/myconfig.conf in sync
2018-10-18T16:51:15+08:00 localhost /usr/local/bin/confd[22040]: DEBUG Trying to connect to redis node 127.0.0.1:16379
2018-10-18T16:51:15+08:00 localhost /usr/local/bin/confd[22040]: DEBUG Redis Subscription: psubscribe __keyspace@0__:/* 1
+1
After updating the redis data, executing the redis publish command can trigger the watch mechanism, which can solve the problem, but the operation document is not clear enough, I hope it can be added. I get it from the code : https://github.com/kelseyhightower/confd/blob/v0.16.0/backends/redis/client.go#L285
Can you please provide an example for the publish statement? whats the channel name? is that actually a bug? I think it should be sufficient to set the interval.
I just faced the same issue. My problem was that the keyspace events are turned off by default for redis. I turned it on by executing the following command on the redis instance:
redis-cli config set notify-keyspace-events KEA
(see https://redis.io/topics/notifications)
Afterwards it worked like a charm for me even without executing the redis publish command.
Hope this helps even after this long while