package com.fufan.mtsaas.tools;

import redis.clients.jedis.Jedis;

public class UserUnlockTool {
    public static void main(String[] args) {
        // if (args.length < 1) {
        // System.out.println("使用方法: java UserUnlockTool <用户ID>");
        // System.out.println("示例: java UserUnlockTool 18827555020");
        // return;
        // }

         String userId = args[0];
         unlockUser(userId);
//        unlockUser("18827555020");
    }

    public static void unlockUser(String userId) {
        Jedis jedis = null;
        try {
            // 连接Redis
            jedis = new Jedis("localhost", 6379);
            // 如果有密码，取消下面这行的注释
            jedis.auth("123456");
            jedis.select(6);

            // 删除登录失败记录
            String lockKey = "user:login:fail:" + userId;
            String lockTimeKey = "user:login:lock:time:" + userId;

            jedis.del(lockKey);
            jedis.del(lockTimeKey);

            System.out.println("用户 " + userId + " 解锁成功！");

        } catch (Exception e) {
            System.out.println("解锁失败：" + e.getMessage());
            e.printStackTrace();
        } finally {
            if (jedis != null) {
                jedis.close();
            }
        }
    }
}
