因为keydb 是完整兼容redis的,所以对于单机版本的兼容是很简单的,配置就行了
参考单机运行
- docker-compose 文件
version: '3'
services:
db3:
image: eqalpha/keydb
command: keydb-server /etc/keydb/keydb.conf --server-threads 10 --requirepass dalong --masterauth dalong
ports:
- 6381:6379
nchan:
image: dalongrong/openresty-tengine:debug-njs
privileged: true
cap_add:
- ALL
ports:
- "80:80"
volumes:
- "./nginx.conf:/usr/local/openresty/nginx/conf/nginx.conf"
- nginx 配置
user root;
master_process off;
worker_processes 1;
events {
worker_connections 1024;
}
error_log /opt/app.log debug;
http {
upstream my_redis_server {
nchan_redis_server db3;
nchan_redis_password dalong;
}
include mime.types;
default_type text/html;
lua_code_cache off;
lua_package_path '/opt/lua/?.lua;;';
real_ip_header X-Forwarded-For;
resolver 127.0.0.11;
server {
listen 80;
charset utf-8;
proxy_set_header X-Forwarded-For $remote_addr;
proxy_buffering off;
proxy_cache off;
proxy_set_header Connection '';
proxy_http_version 1.1;
chunked_transfer_encoding off;
default_type text/html;
location ~ /redis_sub/(\w+)$ {
access_by_lua_block {
local cjson = require("cjson")
ngx.log(ngx.ERR, "failed to get the SNI name: ", cjson.encode(ngx.var))
}
nchan_subscriber_first_message newest;
nchan_subscriber;
nchan_channel_id $1;
nchan_redis_pass my_redis_server;
}
location ~ /redis_pub/(\w+)$ {
nchan_redis_pass my_redis_server;
nchan_publisher;
nchan_channel_id $1;
}
}
}
- 测试
订阅消息
websocat ws://localhost/redis_sub/demoapp
发送消息
curl --location --request POST 'localhost/redis_pub/demoapp' \
--header 'Content-Type: application/json' \
--data-raw '{
"name":"dalong"
}'
keydb 多活复制模式&主主模式
- 问题
目前因为keydb 支持了多活复制模式&主主模式,但是因为server info 是不一样的(role:active-replica)
因为nchan 自己会判断redis 环境的状态并进行一些处理,所以对于keydb 在keydb 多活复制模式&主主模式不支持此种模式的解析
会有问题,目前在尝试修改中,如果成功了会写一些相关的说明
说明
nchan+keydb 是一个不错的集成模式(当然redis cluster 也是可选的),但是keydb 的多线程以及支持的不同玩法,对于我们部署一个
可靠以及稳定的redis 还是比较方便的,是值得使用的redis 兼容server
参考资料
https://github.com/rongfengliang/keydb-nchan
https://nchan.io/
https://docs.keydb.dev/
https://github.com/Snapchat/KeyDB