Search in sources :

Example 1 with RedisClient

use of com.generallycloud.baseio.codec.redis.future.RedisClient in project baseio by generallycloud.

the class TestRedisClient method main.

public static void main(String[] args) throws Exception {
    SocketChannelContext context = new NioSocketChannelContext(new ServerConfiguration(6379));
    SocketChannelConnector connector = new SocketChannelConnector(context);
    context.setIoEventHandleAdaptor(new RedisIOEventHandle());
    context.addSessionEventListener(new LoggerSocketSEListener());
    context.setProtocolFactory(new RedisProtocolFactory());
    SocketSession session = connector.connect();
    RedisClient client = new RedisClient(session);
    String value = client.set("name222", "hello redis!");
    System.out.println("__________________res______" + value);
    value = client.get("name222");
    System.out.println("__________________res______" + value);
    value = client.set("debug", "PONG");
    System.out.println("__________________res______" + value);
    value = client.get("debug");
    System.out.println("__________________res______" + value);
    value = client.ping();
    System.out.println("__________________res______" + value);
    ThreadUtil.sleep(100);
    CloseUtil.close(connector);
}
Also used : RedisClient(com.generallycloud.baseio.codec.redis.future.RedisClient) SocketChannelConnector(com.generallycloud.baseio.connector.SocketChannelConnector) RedisIOEventHandle(com.generallycloud.baseio.codec.redis.future.RedisIOEventHandle) LoggerSocketSEListener(com.generallycloud.baseio.component.LoggerSocketSEListener) SocketSession(com.generallycloud.baseio.component.SocketSession) RedisProtocolFactory(com.generallycloud.baseio.codec.redis.RedisProtocolFactory) ServerConfiguration(com.generallycloud.baseio.configuration.ServerConfiguration) SocketChannelContext(com.generallycloud.baseio.component.SocketChannelContext) NioSocketChannelContext(com.generallycloud.baseio.component.NioSocketChannelContext) NioSocketChannelContext(com.generallycloud.baseio.component.NioSocketChannelContext)

Aggregations

RedisProtocolFactory (com.generallycloud.baseio.codec.redis.RedisProtocolFactory)1 RedisClient (com.generallycloud.baseio.codec.redis.future.RedisClient)1 RedisIOEventHandle (com.generallycloud.baseio.codec.redis.future.RedisIOEventHandle)1 LoggerSocketSEListener (com.generallycloud.baseio.component.LoggerSocketSEListener)1 NioSocketChannelContext (com.generallycloud.baseio.component.NioSocketChannelContext)1 SocketChannelContext (com.generallycloud.baseio.component.SocketChannelContext)1 SocketSession (com.generallycloud.baseio.component.SocketSession)1 ServerConfiguration (com.generallycloud.baseio.configuration.ServerConfiguration)1 SocketChannelConnector (com.generallycloud.baseio.connector.SocketChannelConnector)1