private String getComparatorKeyName() { return "redisson_sortedset_comparator:{" + getName() + "}"; }
private String getComparatorKeyName() { return "redisson_sortedset_comparator:{" + getName() + "}"; }
@Override public boolean trySetComparator(Comparator<? super V> comparator) { String className = comparator.getClass().getName(); final String comparatorSign = className + ":" + calcClassSign(className); Boolean res = commandExecutor.evalWrite(getName(), StringCodec.INSTANCE, RedisCommands.EVAL_BOOLEAN, "if redis.call('llen', KEYS[1]) == 0 then " + "redis.call('set', KEYS[2], ARGV[1]); " + "return 1; " + "else " + "return 0; " + "end", Arrays.<Object>asList(getName(), getComparatorKeyName()), comparatorSign); if (res) { this.comparator = comparator; } return res; }
@Override public boolean trySetComparator(Comparator<? super V> comparator) { String className = comparator.getClass().getName(); final String comparatorSign = className + ":" + calcClassSign(className); Boolean res = commandExecutor.evalWrite(getName(), StringCodec.INSTANCE, RedisCommands.EVAL_BOOLEAN, "if redis.call('llen', KEYS[1]) == 0 then " + "redis.call('set', KEYS[2], ARGV[1]); " + "return 1; " + "else " + "return 0; " + "end", Arrays.<Object>asList(getName(), getComparatorKeyName()), comparatorSign); if (res) { this.comparator = comparator; } return res; }
public RedissonSortedSet(Codec codec, CommandExecutor commandExecutor, String name, Redisson redisson) { super(codec, commandExecutor, name); this.commandExecutor = commandExecutor; comparatorHolder = redisson.getBucket(getComparatorKeyName(), StringCodec.INSTANCE); lock = redisson.getLock("redisson_sortedset_lock:{" + getName() + "}"); list = (RedissonList<V>) redisson.getList(getName(), codec); loadComparator(); }
protected RedissonSortedSet(CommandExecutor commandExecutor, String name, RedissonClient redisson) { super(commandExecutor, name); this.commandExecutor = commandExecutor; this.redisson = redisson; comparatorHolder = redisson.getBucket(getComparatorKeyName(), StringCodec.INSTANCE); lock = redisson.getLock("redisson_sortedset_lock:{" + getName() + "}"); list = (RedissonList<V>) redisson.getList(getName()); loadComparator(); }
protected RedissonSortedSet(CommandExecutor commandExecutor, String name, RedissonClient redisson) { super(commandExecutor, name); this.commandExecutor = commandExecutor; this.redisson = redisson; comparatorHolder = redisson.getBucket(getComparatorKeyName(), StringCodec.INSTANCE); lock = redisson.getLock("redisson_sortedset_lock:{" + getName() + "}"); list = (RedissonList<V>) redisson.getList(getName()); loadComparator(); }
public RedissonSortedSet(Codec codec, CommandExecutor commandExecutor, String name, Redisson redisson) { super(codec, commandExecutor, name); this.commandExecutor = commandExecutor; comparatorHolder = redisson.getBucket(getComparatorKeyName(), StringCodec.INSTANCE); lock = redisson.getLock("redisson_sortedset_lock:{" + getName() + "}"); list = (RedissonList<V>) redisson.getList(getName(), codec); loadComparator(); }
@Override public boolean add(V value) { lock.lock(); try { checkComparator(); BinarySearchResult<V> res = binarySearch(value, codec); if (res.getIndex() < 0) { int index = -(res.getIndex() + 1); ByteBuf encodedValue = encode(value); commandExecutor.evalWrite(getName(), RedisCommands.EVAL_VOID, "local len = redis.call('llen', KEYS[1]);" + "if tonumber(ARGV[1]) < len then " + "local pivot = redis.call('lindex', KEYS[1], ARGV[1]);" + "redis.call('linsert', KEYS[1], 'before', pivot, ARGV[2]);" + "return;" + "end;" + "redis.call('rpush', KEYS[1], ARGV[2]);", Arrays.<Object>asList(getName()), index, encodedValue); return true; } else { return false; } } finally { lock.unlock(); } }
@Override public boolean add(V value) { lock.lock(); try { checkComparator(); BinarySearchResult<V> res = binarySearch(value, codec); if (res.getIndex() < 0) { int index = -(res.getIndex() + 1); ByteBuf encodedValue = encode(value); commandExecutor.evalWrite(getName(), RedisCommands.EVAL_VOID, "local len = redis.call('llen', KEYS[1]);" + "if tonumber(ARGV[1]) < len then " + "local pivot = redis.call('lindex', KEYS[1], ARGV[1]);" + "redis.call('linsert', KEYS[1], 'before', pivot, ARGV[2]);" + "return;" + "end;" + "redis.call('rpush', KEYS[1], ARGV[2]);", Arrays.<Object>asList(getName()), index, encodedValue); return true; } else { return false; } } finally { lock.unlock(); } }
private String getComparatorKeyName() { return "redisson_sortedset_comparator:{" + getName() + "}"; }
@Override public boolean trySetComparator(Comparator<? super V> comparator) { String className = comparator.getClass().getName(); final String comparatorSign = className + ":" + calcClassSign(className); Boolean res = commandExecutor.evalWrite(getName(), StringCodec.INSTANCE, RedisCommands.EVAL_BOOLEAN, "if redis.call('llen', KEYS[1]) == 0 then " + "redis.call('set', KEYS[2], ARGV[1]); " + "return 1; " + "else " + "return 0; " + "end", Arrays.<Object>asList(getName(), getComparatorKeyName()), comparatorSign); if (res) { this.comparator = comparator; } return res; }
protected RedissonSortedSet(CommandExecutor commandExecutor, String name, RedissonClient redisson) { super(commandExecutor, name); this.commandExecutor = commandExecutor; this.redisson = redisson; comparatorHolder = redisson.getBucket(getComparatorKeyName(), StringCodec.INSTANCE); lock = redisson.getLock("redisson_sortedset_lock:{" + getName() + "}"); list = (RedissonList<V>) redisson.getList(getName()); loadComparator(); }
public RedissonSortedSet(Codec codec, CommandExecutor commandExecutor, String name, Redisson redisson) { super(codec, commandExecutor, name); this.commandExecutor = commandExecutor; comparatorHolder = redisson.getBucket(getComparatorKeyName(), StringCodec.INSTANCE); lock = redisson.getLock("redisson_sortedset_lock:{" + getName() + "}"); list = (RedissonList<V>) redisson.getList(getName(), codec); loadComparator(); }
@Override public boolean add(V value) { lock.lock(); try { checkComparator(); BinarySearchResult<V> res = binarySearch(value, codec); if (res.getIndex() < 0) { int index = -(res.getIndex() + 1); ByteBuf encodedValue = encode(value); commandExecutor.evalWrite(getName(), RedisCommands.EVAL_VOID, "local len = redis.call('llen', KEYS[1]);" + "if tonumber(ARGV[1]) < len then " + "local pivot = redis.call('lindex', KEYS[1], ARGV[1]);" + "redis.call('linsert', KEYS[1], 'before', pivot, ARGV[2]);" + "return;" + "end;" + "redis.call('rpush', KEYS[1], ARGV[2]);", Arrays.<Object>asList(getName()), index, encodedValue); return true; } else { return false; } } finally { lock.unlock(); } }