1 Star 1 Fork 1

Deament / skyCloud

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
README.md 2.83 KB
一键复制 编辑 原始数据 按行查看 历史
Deament 提交于 2020-08-29 09:42 . update README.md.

正在开发中

redis 文档

http://doc.redisfans.com/

离线下载地址

基本结构

<modules>
        <!-- 基础包-->
        <module>common</module>
        <!-- 核心包 依赖common-->
        <module>core</module>
        <!--服务端 依赖core-->
        <module>server</module>
        <!--客户端 依赖core -->
        <module>client</module>
    </modules>

启动

com.gitee.deament.server.MyServer --》右键启动

核心类

com.gitee.deament.server.config.SystemConfig 包含了数据和非数据的信息存储

基本架构

netty

辨别会话 channel

public class MyServerInitailizer extends ChannelInitializer<SocketChannel> {
    @Override
    protected void initChannel(SocketChannel socketChannel) throws Exception {
        ChannelPipeline channelPipeline= socketChannel.pipeline();
        channelPipeline.addLast(new HttpServerCodec());
        channelPipeline.addLast(new ChunkedWriteHandler());
        channelPipeline.addLast(new HttpObjectAggregator(8192));
        channelPipeline.addLast(new WebSocketServerProtocolHandler("/ws"));
        channelPipeline.addLast(new CommandHander());// 核心处理类
    }
}

编写一个命令处理

@CliHander(command = "HDEL")
public class HDELcli extends AbstractCli {
    @Override
    public void executeCli(ChannelHandlerContext channelHandlerContext, String command) {

        List<String> values = getValues(command);
        if (values.size() < 3) {
            channelHandlerContext.channel().writeAndFlush(new TextWebSocketFrame("ERR wrong number of arguments for 'HDEL' command"));
        }
        int db = ConnectData.SELECT_DB_STORAGE.getUseDB(channelHandlerContext.channel().id().asLongText());
        Value<Map<String, String>> hashData = SystemConfig.dbData.getHashData(db, values.get(0));
        StringBuilder msg = new StringBuilder();
        for (int i = 2; i < values.size(); i++) {
            String result = hashData.getValue().remove(values.get(i));
            if (result == null) {
                msg.append("0\r\n");
            } else {
                msg.append("1\r\n");
            }
        }
        channelHandlerContext.channel().writeAndFlush(new TextWebSocketFrame(msg.toString()));

    }
}

@CliHander 接收命令的首个单词 如 命令 HDEL hash key ,以第一个单词作为命令处理分类, AbstractCli 抽象的方法,需要实现执行命令的具体步骤

ConnectData 类是连接的信息和数据无关

SystemConfig.dbData 存储数据的地方

结构与redis服务器类似 先要AUTH 执行认证密码后 再执行命令操作

测试(临时)

skyCloud\server\src\test\resources\static\webSocketTest.html(需启动后端)

Java
1
https://gitee.com/SYDeament/skyCloud.git
git@gitee.com:SYDeament/skyCloud.git
SYDeament
skyCloud
skyCloud
master

搜索帮助