nchan 集成keydb简单测试&一些说明

因为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

posted on   荣锋亮  阅读(198)  评论(0编辑  收藏  举报

相关博文:
阅读排行:
· 全程不用写代码,我用AI程序员写了一个飞机大战
· DeepSeek 开源周回顾「GitHub 热点速览」
· 记一次.NET内存居高不下排查解决与启示
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· .NET10 - 预览版1新功能体验(一)
历史上的今天:
2019-03-18 使用k8s && minio 进行 postgres 数据库自动备份
2018-03-18 使用npm link 创建本地模块

导航

< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5
点击右上角即可分享
微信分享提示