org.springframework.data.redis.connection.RedisConnection.setNX()方法的使用及代码示例

x33g5p2x  于2022-01-28 转载在 其他  
字(6.0k)|赞(0)|评价(0)|浏览(179)

本文整理了Java中org.springframework.data.redis.connection.RedisConnection.setNX方法的一些代码示例,展示了RedisConnection.setNX的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。RedisConnection.setNX方法的具体详情如下:
包路径:org.springframework.data.redis.connection.RedisConnection
类名称:RedisConnection
方法名:setNX

RedisConnection.setNX介绍

暂无

代码示例

代码示例来源:origin: spring-projects/spring-data-redis

@Override
public Boolean setNX(byte[] key, byte[] value) {
  return convertAndReturn(delegate.setNX(key, value), identityConverter);
}

代码示例来源:origin: spring-projects/spring-data-redis

private Boolean doLock(String name, RedisConnection connection) {
  return connection.setNX(createCacheLockKey(name), new byte[0]);
}

代码示例来源:origin: spring-projects/spring-data-redis

@Override
public Boolean setIfAbsent(K key, V value) {
  byte[] rawKey = rawKey(key);
  byte[] rawValue = rawValue(value);
  return execute(connection -> connection.setNX(rawKey, rawValue), true);
}

代码示例来源:origin: spring-projects/spring-data-redis

@Override
public byte[] putIfAbsent(String name, byte[] key, byte[] value, @Nullable Duration ttl) {
  Assert.notNull(name, "Name must not be null!");
  Assert.notNull(key, "Key must not be null!");
  Assert.notNull(value, "Value must not be null!");
  return execute(name, connection -> {
    if (isLockingCacheWriter()) {
      doLock(name, connection);
    }
    try {
      if (connection.setNX(key, value)) {
        if (shouldExpireWithin(ttl)) {
          connection.pExpire(key, ttl.toMillis());
        }
        return null;
      }
      return connection.get(key);
    } finally {
      if (isLockingCacheWriter()) {
        doUnlock(name, connection);
      }
    }
  });
}

代码示例来源:origin: apache/nifi

@Override
public <K, V> boolean putIfAbsent(final K key, final V value, final Serializer<K> keySerializer, final Serializer<V> valueSerializer) throws IOException {
  return withConnection(redisConnection -> {
    final Tuple<byte[],byte[]> kv = serialize(key, value, keySerializer, valueSerializer);
    boolean set = redisConnection.setNX(kv.getKey(), kv.getValue());
    if (ttl != -1L && set) {
      redisConnection.expire(kv.getKey(), ttl);
    }
    return set;
  });
}

代码示例来源:origin: apache/nifi

redisConnection.setNX(kv.getKey(), kv.getValue());

代码示例来源:origin: bill1012/AdminEAP

public Boolean doInRedis(RedisConnection connection)
      throws DataAccessException {
    RedisSerializer<String> serializer = getRedisSerializer();
    byte[] keyStr = serializer.serialize(key);
    byte[] object = serializer.serialize(value);
    return connection.setNX(keyStr, object);
  }
});

代码示例来源:origin: songxinjianqwe/EShop-SOA

@Override
  public Boolean doInRedis(RedisConnection connection) throws DataAccessException {
    return connection.setNX(keyBytes, valueBytes);
  }
});

代码示例来源:origin: 1991wangliang/tx-lcn

@Override
public Boolean setNX(byte[] key, byte[] value) {
  return redisConnection.setNX(key, value);
}

代码示例来源:origin: souyunku/SpringBootExamples

/**
 * 将 key的值保存为 value ,当且仅当 key 不存在。 若给定的 key 已经存在,则 SETNX 不做任何动作。 SETNX 是『SET if
 * Not eXists』(如果不存在,则 SET)的简写。 <br>
 * 保存成功,返回 true <br>
 * 保存失败,返回 false
 */
public static boolean saveNX(String key, String val) {
  /** 设置成功,返回 1 设置失败,返回 0 **/
  return cacheUtils.redisTemplate.execute((RedisCallback<Boolean>) connection -> {
    return connection.setNX(key.getBytes(), val.getBytes());
  });
}

代码示例来源:origin: org.springframework.data/spring-data-redis

@Override
public Boolean setNX(byte[] key, byte[] value) {
  return convertAndReturn(delegate.setNX(key, value), identityConverter);
}

代码示例来源:origin: org.springframework.data/spring-data-redis

private Boolean doLock(String name, RedisConnection connection) {
  return connection.setNX(createCacheLockKey(name), new byte[0]);
}

代码示例来源:origin: apache/servicemix-bundles

@Override
public Boolean setNX(byte[] key, byte[] value) {
  return convertAndReturn(delegate.setNX(key, value), identityConverter);
}

代码示例来源:origin: apache/servicemix-bundles

private Boolean doLock(String name, RedisConnection connection) {
  return connection.setNX(createCacheLockKey(name), new byte[0]);
}

代码示例来源:origin: nosqlcoco/springboot-weapp-demo

public Boolean doInRedis(RedisConnection connection)  
      throws DataAccessException {  
    RedisSerializer<String> serializer = redisTemplate.getStringSerializer();  
    for (Map.Entry<String, String> entry : map.entrySet()) {  
      byte[] key  = serializer.serialize(entry.getKey());  
      byte[] name = serializer.serialize(entry.getValue());  
      connection.setNX(key, name);  
    }  
    return true;  
  }  
}, false, true);

代码示例来源:origin: org.springframework.data/spring-data-redis

@Override
public Boolean setIfAbsent(K key, V value) {
  byte[] rawKey = rawKey(key);
  byte[] rawValue = rawValue(value);
  return execute(connection -> connection.setNX(rawKey, rawValue), true);
}

代码示例来源:origin: 3zamn/kingMicro

public Boolean doInRedis(RedisConnection connection) throws DataAccessException {
    RedisSerializer<String> serializer = redisTemplate.getStringSerializer();
    byte[] key = serializer.serialize(k);
    byte[] name = serializer.serialize(v);
    return connection.setNX(key, name);
  }
});

代码示例来源:origin: apache/servicemix-bundles

@Override
public Boolean setIfAbsent(K key, V value) {
  byte[] rawKey = rawKey(key);
  byte[] rawValue = rawValue(value);
  return execute(connection -> connection.setNX(rawKey, rawValue), true);
}

代码示例来源:origin: org.springframework.data/spring-data-redis

@Override
public byte[] putIfAbsent(String name, byte[] key, byte[] value, @Nullable Duration ttl) {
  Assert.notNull(name, "Name must not be null!");
  Assert.notNull(key, "Key must not be null!");
  Assert.notNull(value, "Value must not be null!");
  return execute(name, connection -> {
    if (isLockingCacheWriter()) {
      doLock(name, connection);
    }
    try {
      if (connection.setNX(key, value)) {
        if (shouldExpireWithin(ttl)) {
          connection.pExpire(key, ttl.toMillis());
        }
        return null;
      }
      return connection.get(key);
    } finally {
      if (isLockingCacheWriter()) {
        doUnlock(name, connection);
      }
    }
  });
}

代码示例来源:origin: apache/servicemix-bundles

@Override
public byte[] putIfAbsent(String name, byte[] key, byte[] value, @Nullable Duration ttl) {
  Assert.notNull(name, "Name must not be null!");
  Assert.notNull(key, "Key must not be null!");
  Assert.notNull(value, "Value must not be null!");
  return execute(name, connection -> {
    if (isLockingCacheWriter()) {
      doLock(name, connection);
    }
    try {
      if (connection.setNX(key, value)) {
        if (shouldExpireWithin(ttl)) {
          connection.pExpire(key, ttl.toMillis());
        }
        return null;
      }
      return connection.get(key);
    } finally {
      if (isLockingCacheWriter()) {
        doUnlock(name, connection);
      }
    }
  });
}

相关文章

微信公众号

最新文章

更多

RedisConnection类方法