com.jn.agileway.redis.locks.LockRandomValueBuilder Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of agileway-redis Show documentation
Show all versions of agileway-redis Show documentation
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
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 - 2025 Weber Informatics LLC | Privacy Policy