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

com.jn.agileway.redis.locks.LockRandomValueBuilder Maven / Gradle / Ivy

Go to download

Provides a large number of convenient redis tools: distributed locks, distributed count, distributed cache, distributed id generator, jdk collection implements, the enhanced RedisTemplate based on a specified key prefix and the agileway-codec module

There is a newer version: 5.0.4
Show newest version
package com.jn.agileway.redis.locks;

import com.jn.langx.Builder;
import com.jn.langx.util.concurrent.threadlocal.GlobalThreadLocalMap;
import com.jn.langx.util.net.Nets;
import com.jn.langx.util.os.Platform;

import java.net.InetAddress;

public class LockRandomValueBuilder implements Builder {
    private static final String randomValuePrefix;

    static {
        String mac;
        String ip = "localhost";
        String pid;
        InetAddress inetAddress = Nets.getCurrentAddress();
        if (inetAddress != null) {
            ip = Nets.toAddressString(inetAddress);
        }
        mac = Nets.getFirstValidMac();
        pid = Platform.processId;

        randomValuePrefix = ip + "_" + mac + "_" + pid;
    }

    public String build() {
        long random = GlobalThreadLocalMap.getRandom().nextLong();
        return randomValuePrefix + "_" + System.currentTimeMillis() + "_" + random;
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy