package cn.reghao.tnb.sb.zk.redis.ds;

import io.lettuce.core.ScriptOutputType;
import io.lettuce.core.api.sync.RedisCommands;

import java.util.HashSet;
import java.util.Set;

/**
 * Redis 命令操作
 *
 * @author reghao
 * @date 2019-08-04 04:02:10
 */
public class RedisCommand {
    private final RedisCommands<String, String> commands;

    public RedisCommand(RedisCommands<String, String> commands) {
        this.commands = commands;
    }

    public boolean eval(String lua, String[] keys, String[] values) {
        long ret = commands.eval(lua, ScriptOutputType.INTEGER, keys, values);
        return ret == 1;
    }

    public Set<String> keys(String pattern) {
        return new HashSet<>(commands.keys(pattern));
    }

    public void publish(String channel, String message) {
        commands.publish(channel, message);
    }
}
