本文整理汇总了Java中redis.clients.util.SafeEncoder类的典型用法代码示例。如果您正苦于以下问题:Java SafeEncoder类的具体用法?Java SafeEncoder怎么用?Java SafeEncoder使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
SafeEncoder类属于redis.clients.util包,在下文中一共展示了SafeEncoder类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: run
import redis.clients.util.SafeEncoder; //导入依赖的package包/类
public T run(int keyCount, String... keys) {
if (keys == null || keys.length == 0) {
throw new JedisClusterException("No way to dispatch this command to Redis Cluster.");
}
// For multiple keys, only execute if they all share the
// same connection slot.
if (keys.length > 1) {
int slot = JedisClusterCRC16.getSlot(keys[0]);
for (int i = 1; i < keyCount; i++) {
int nextSlot = JedisClusterCRC16.getSlot(keys[i]);
if (slot != nextSlot) {
throw new JedisClusterException(
"No way to dispatch this command to Redis Cluster " + "because keys have different slots.");
}
}
}
return runWithRetries(SafeEncoder.encode(keys[0]), this.maxAttempts, false, false);
}
示例2: build
import redis.clients.util.SafeEncoder; //导入依赖的package包/类
@Override
@SuppressWarnings("unchecked")
public Set<String> build(Object data) {
if (null == data) {
return Collections.emptySet();
}
List<byte[]> l = (List<byte[]>) data;
final Set<String> result = new LinkedHashSet<String>(l.size(), 1);
for (final byte[] barray : l) {
if (barray == null) {
result.add(null);
} else {
result.add(SafeEncoder.encode(barray));
}
}
return result;
}
示例3: getByteParams
import redis.clients.util.SafeEncoder; //导入依赖的package包/类
public byte[][] getByteParams(byte[] key, byte[]... args) {
ArrayList<byte[]> byteParams = new ArrayList<byte[]>();
byteParams.add(key);
if (contains(NX)) {
byteParams.add(SafeEncoder.encode(NX));
}
if (contains(XX)) {
byteParams.add(SafeEncoder.encode(XX));
}
if (contains(CH)) {
byteParams.add(SafeEncoder.encode(CH));
}
for (byte[] arg : args) {
byteParams.add(arg);
}
return byteParams.toArray(new byte[byteParams.size()][]);
}
示例4: scan
import redis.clients.util.SafeEncoder; //导入依赖的package包/类
@Override
public ScanResult<byte[]> scan(final byte[] cursor, final ScanParams params) {
String matchPattern = null;
if (params == null || (matchPattern = params.match()) == null || matchPattern.isEmpty()) {
throw new IllegalArgumentException(BinaryJedisCluster.class.getSimpleName()
+ " only supports SCAN commands with non-empty MATCH patterns");
}
if (JedisClusterHashTagUtil.isClusterCompliantMatchPattern(matchPattern)) {
return new JedisClusterCommand<ScanResult<byte[]>>(connectionHandler, maxAttempts) {
@Override
public ScanResult<byte[]> execute(Jedis connection) {
return connection.scan(cursor, params);
}
}.runBinary(SafeEncoder.encode(matchPattern));
} else {
throw new IllegalArgumentException(BinaryJedisCluster.class.getSimpleName()
+ " only supports SCAN commands with MATCH patterns containing hash-tags ( curly-brackets enclosed strings )");
}
}
示例5: geohash
import redis.clients.util.SafeEncoder; //导入依赖的package包/类
@Test
public void geohash() {
prepareGeoData();
List<String> hashes = jedis.geohash("foo", "a", "b", "notexist");
assertEquals(3, hashes.size());
assertEquals("s0dnu20t9j0", hashes.get(0));
assertEquals("s093jd0k720", hashes.get(1));
assertNull(hashes.get(2));
// binary
List<byte[]> bhashes = jedis.geohash(bfoo, bA, bB, bNotexist);
assertEquals(3, bhashes.size());
assertArrayEquals(SafeEncoder.encode("s0dnu20t9j0"), bhashes.get(0));
assertArrayEquals(SafeEncoder.encode("s093jd0k720"), bhashes.get(1));
assertNull(bhashes.get(2));
}
示例6: set
import redis.clients.util.SafeEncoder; //导入依赖的package包/类
/**
* Sets an object
* @param conn the Jedis connection
* @param key the key name
* @param object the Java object to store
* @param flag an existential modifier
* @param path optional single path in the object, defaults to root
*/
public static void set(Jedis conn, String key, Object object, ExistenceModifier flag, Path... path) {
List<byte[]> args = new ArrayList(4);
args.add(SafeEncoder.encode(key));
args.add(SafeEncoder.encode(getSingleOptionalPath(path).toString()));
args.add(SafeEncoder.encode(gson.toJson(object)));
if (ExistenceModifier.DEFAULT != flag) {
args.add(flag.getRaw());
}
String status = conn.getClient()
.sendCommand(Command.SET, args.toArray(new byte[args.size()][]))
.getStatusCodeReply();
conn.close();
assertReplyOK(status);
}
示例7: set
import redis.clients.util.SafeEncoder; //导入依赖的package包/类
/**
* 设置ç
*
* @param field
* @param value
* @return
*/
public boolean set(String field, Object value) {
boolean result = false;
if (value == null) { return false; }
//返回值(1:新字段被设置,0:已经存在值被更新)
try {
if (isCluster(groupName)) {
result = getBinaryJedisClusterCommands(groupName).hset(key,
SafeEncoder.encode(field), valueSerialize(value)) >= 0;
} else {
result = getBinaryJedisCommands(groupName).hset(key, SafeEncoder.encode(field),
valueSerialize(value)) >= 0;
}
//设置超时时间
if (result) { setExpireIfNot(expireTime); }
return result;
} finally {
getJedisProvider(groupName).release();
}
}
示例8: zscan
import redis.clients.util.SafeEncoder; //导入依赖的package包/类
public ScanResult<Tuple> zscan(final byte[] key, final byte[] cursor, final ScanParams params) {
checkIsInMultiOrPipeline();
client.zscan(key, cursor, params);
List<Object> result = client.getObjectMultiBulkReply();
byte[] newcursor = (byte[]) result.get(0);
List<Tuple> results = new ArrayList<Tuple>();
List<byte[]> rawResults = (List<byte[]>) result.get(1);
Iterator<byte[]> iterator = rawResults.iterator();
while (iterator.hasNext()) {
results.add(new Tuple(iterator.next(), Double.valueOf(SafeEncoder.encode(iterator.next()))));
}
return new ScanResult<Tuple>(newcursor, results);
}
示例9: sscan
import redis.clients.util.SafeEncoder; //导入依赖的package包/类
@Override
public ScanResult<String> sscan(final String key, final String cursor, final ScanParams params) {
checkIsInMultiOrPipeline();
client.sscan(key, cursor, params);
List<Object> result = client.getObjectMultiBulkReply();
String newcursor = new String((byte[]) result.get(0));
List<String> results = new ArrayList<String>();
List<byte[]> rawResults = (List<byte[]>) result.get(1);
for (byte[] bs : rawResults) {
results.add(SafeEncoder.encode(bs));
}
return new ScanResult<String>(newcursor, results);
}
示例10: zscan
import redis.clients.util.SafeEncoder; //导入依赖的package包/类
@Override
public ScanResult<Tuple> zscan(final String key, final String cursor, final ScanParams params) {
checkIsInMultiOrPipeline();
client.zscan(key, cursor, params);
List<Object> result = client.getObjectMultiBulkReply();
String newcursor = new String((byte[]) result.get(0));
List<Tuple> results = new ArrayList<Tuple>();
List<byte[]> rawResults = (List<byte[]>) result.get(1);
Iterator<byte[]> iterator = rawResults.iterator();
while (iterator.hasNext()) {
results.add(new Tuple(SafeEncoder.encode(iterator.next()),
Double.valueOf(SafeEncoder.encode(iterator.next()))));
}
return new ScanResult<Tuple>(newcursor, results);
}
示例11: removeObjectsWithGroup
import redis.clients.util.SafeEncoder; //导入依赖的package包/类
public static boolean removeObjectsWithGroup(String groupName, String... keys) {
byte[][] byteKeys = SafeEncoder.encodeMany(keys);
try {
if (JedisProviderFactory.isCluster(groupName)) {
return JedisProviderFactory.getMultiKeyBinaryJedisClusterCommands(groupName)
.del(byteKeys) == 1;
} else {
return JedisProviderFactory.getMultiKeyBinaryCommands(groupName).del(byteKeys) == 1;
}
} finally {
JedisProviderFactory.getJedisProvider(groupName).release();
}
}
示例12: psubscribe
import redis.clients.util.SafeEncoder; //导入依赖的package包/类
public void psubscribe(final String... patterns) {
final byte[][] ps = new byte[patterns.length][];
for (int i = 0; i < ps.length; i++) {
ps[i] = SafeEncoder.encode(patterns[i]);
}
psubscribe(ps);
}
示例13: zunionstore
import redis.clients.util.SafeEncoder; //导入依赖的package包/类
public void zunionstore(final String dstkey, final ZParams params, final String... sets) {
final byte[][] bsets = new byte[sets.length][];
for (int i = 0; i < bsets.length; i++) {
bsets[i] = SafeEncoder.encode(sets[i]);
}
zunionstore(SafeEncoder.encode(dstkey), params, bsets);
}
示例14: zscan
import redis.clients.util.SafeEncoder; //导入依赖的package包/类
public ScanResult<Tuple> zscan(final String key, final String cursor, final ScanParams params) {
checkIsInMultiOrPipeline();
client.zscan(key, cursor, params);
List<Object> result = client.getObjectMultiBulkReply();
String newcursor = new String((byte[]) result.get(0));
List<Tuple> results = new ArrayList<Tuple>();
List<byte[]> rawResults = (List<byte[]>) result.get(1);
Iterator<byte[]> iterator = rawResults.iterator();
while (iterator.hasNext()) {
results.add(new Tuple(SafeEncoder.encode(iterator.next()), Double.valueOf(SafeEncoder
.encode(iterator.next()))));
}
return new ScanResult<Tuple>(newcursor, results);
}
示例15: scriptExistsBinary
import redis.clients.util.SafeEncoder; //导入依赖的package包/类
@Test
public void scriptExistsBinary() {
jedis.scriptLoad(SafeEncoder.encode("return redis.call('get','foo')"));
List<Long> exists = jedis.scriptExists(
SafeEncoder.encode("ffffffffffffffffffffffffffffffffffffffff"),
SafeEncoder.encode("6b1bf486c81ceb7edf3c093f4c48582e38c0e791"));
assertEquals(new Long(0), exists.get(0));
assertEquals(new Long(1), exists.get(1));
}