All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.github.tonivade.resp.command.DefaultSession Maven / Gradle / Ivy

Go to download

Netty implementation of REdis Serialization Protocol, and a simple framework to implement command based protocols

There is a newer version: 0.24.0
Show newest version
/*
 * Copyright (c) 2015-2019, Antonio Gabriel Muñoz Conejo 
 * Distributed under the terms of the MIT License
 */
package com.github.tonivade.resp.command;

import com.github.tonivade.purefun.type.Option;
import com.github.tonivade.resp.StateHolder;
import com.github.tonivade.resp.protocol.RedisToken;

import io.netty.channel.ChannelHandlerContext;

public class DefaultSession implements Session {

  private final String id;

  private final ChannelHandlerContext ctx;

  private final StateHolder state = new StateHolder();

  public DefaultSession(String id, ChannelHandlerContext ctx) {
    this.id = id;
    this.ctx = ctx;
  }

  @Override
  public String getId() {
    return id;
  }

  @Override
  public void publish(RedisToken msg) {
    ctx.writeAndFlush(msg);
  }

  @Override
  public void close() {
    ctx.close();
  }

  @Override
  public void destroy() {
    state.clear();
  }

  @Override
  public  Option getValue(String key) {
    return state.getValue(key);
  }

  @Override
  public  Option removeValue(String key) {
    return state.removeValue(key);
  }

  @Override
  public void putValue(String key, Object value) {
    state.putValue(key, value);
  }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy