本文整理匯總了Java中redis.clients.jedis.Pipeline.hset方法的典型用法代碼示例。如果您正苦於以下問題:Java Pipeline.hset方法的具體用法?Java Pipeline.hset怎麽用?Java Pipeline.hset使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類redis.clients.jedis.Pipeline
的用法示例。
在下文中一共展示了Pipeline.hset方法的14個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: rename
import redis.clients.jedis.Pipeline; //導入方法依賴的package包/類
@Override
public void rename(String fileLengthKey, String fileDataKey, String oldField, String newField, List<byte[]> values, long
fileLength) {
long blockSize = 0;
Jedis jedis = null;
try {
jedis = jedisPool.getResource();
Pipeline pipelined = jedis.pipelined();
//add new file length
pipelined.hset(fileLengthKey.getBytes(), newField.getBytes(), Longs.toByteArray(fileLength));
//add new file content
blockSize = getBlockSize(fileLength);
for (int i = 0; i < blockSize; i++) {
pipelined.hset(fileDataKey.getBytes(), getBlockName(newField, i), compressFilter(values.get(i)));
}
values.clear();
pipelined.sync();
} finally {
jedis.close();
deleteFile(fileLengthKey, fileDataKey, oldField, blockSize);
}
}
示例2: saveFile
import redis.clients.jedis.Pipeline; //導入方法依賴的package包/類
@Override
public void saveFile(String fileLengthKey, String fileDataKey, String fileName, List<byte[]> values, long fileLength) {
Jedis jedis = null;
try {
jedis = jedisPool.getResource();
Pipeline pipelined = jedis.pipelined();
pipelined.hset(fileLengthKey.getBytes(), fileName.getBytes(), Longs.toByteArray(fileLength));
Long blockSize = getBlockSize(fileLength);
for (int i = 0; i < blockSize; i++) {
pipelined.hset(fileDataKey.getBytes(), getBlockName(fileName, i), compressFilter(values.get(i)));
if (i % Constants.SYNC_COUNT == 0) {
pipelined.sync();
pipelined = jedis.pipelined();
}
}
values.clear();
pipelined.sync();
} finally {
jedis.close();
}
}
示例3: rename
import redis.clients.jedis.Pipeline; //導入方法依賴的package包/類
@Override
public void rename(String fileLengthKey, String fileDataKey, String oldField, String newField, List<byte[]> values, long
fileLength) {
Jedis jedis = openJedis();
Pipeline pipelined = jedis.pipelined();
//add new file length
pipelined.hset(fileLengthKey.getBytes(), newField.getBytes(), Longs.toByteArray(fileLength));
//add new file content
Long blockSize = getBlockSize(fileLength);
for (int i = 0; i < blockSize; i++) {
pipelined.hset(fileDataKey.getBytes(), getBlockName(newField, i), compressFilter(values.get(i)));
}
pipelined.sync();
jedis.close();
values.clear();
deleteFile(fileLengthKey, fileDataKey, oldField, blockSize);
}
示例4: saveFile
import redis.clients.jedis.Pipeline; //導入方法依賴的package包/類
@Override
public void saveFile(String fileLengthKey, String fileDataKey, String fileName, List<byte[]> values, long fileLength) {
Jedis jedis = openJedis();
Pipeline pipelined = jedis.pipelined();
pipelined.hset(fileLengthKey.getBytes(), fileName.getBytes(), Longs.toByteArray(fileLength));
Long blockSize = getBlockSize(fileLength);
for (int i = 0; i < blockSize; i++) {
pipelined.hset(fileDataKey.getBytes(), getBlockName(fileName, i), compressFilter(values.get(i)));
if (i % Constants.SYNC_COUNT == 0) {
pipelined.sync();
pipelined = jedis.pipelined();
}
}
pipelined.sync();
jedis.close();
values.clear();
}
示例5: doUpsertHash
import redis.clients.jedis.Pipeline; //導入方法依賴的package包/類
private void doUpsertHash(Record record, List<ErrorRecord> tempRecords, Pipeline pipeline, String key, Field value)
throws StageException {
if (value != null && value.getType().isOneOf(Field.Type.MAP, Field.Type.LIST_MAP)) {
Map<String, Field> values = value.getValueAsMap();
for (Map.Entry<String, Field> entry : values.entrySet()) {
String fieldName = entry.getKey();
String val = entry.getValue().getValueAsString();
pipeline.hset(key, fieldName, val);
tempRecords.add(new ErrorRecord(record, "Hash", key, val));
}
} else {
LOG.error(Errors.REDIS_04.getMessage(), value.getType(), "value should be Map");
errorRecordHandler.onError(
new OnRecordErrorException(
record,
Errors.REDIS_04,
value.getType(),
"value should be Map"
)
);
}
}
示例6: registerFakeSession
import redis.clients.jedis.Pipeline; //導入方法依賴的package包/類
private void registerFakeSession(int count, User user) {
//Clean all sessions
Jedis jedis = JedisFactory.getJedis();
Pipeline pipeline = jedis.pipelined();
Set<byte[]> strs = jedis.keys("*".getBytes());
for ( byte[] key : strs ) {
pipeline.del(key);
}
pipeline.sync();
UserId userId = user.get_id();
SessionKey sessionKey = SessionKey.createSessionKeyFromRandomString();
user.setSessionKey(sessionKey);
//Store it with machineid to redis
jedis = JedisFactory.getJedis();
pipeline = jedis.pipelined();
for ( int i=0; i<count; i++ ) {
pipeline.hset(sessionKey.toString(), SessionManager.H_MACHINE_KEY, "localhost:10000");
pipeline.hset(userId.toString(), SessionManager.H_MACHINE_KEY, "localhost:10000");
pipeline.hset(userId.toString(), SessionManager.H_SESSION_KEY, sessionKey.toString());
}
pipeline.sync();
}
示例7: setUp
import redis.clients.jedis.Pipeline; //導入方法依賴的package包/類
@Before
public void setUp() throws Exception {
//input redis data
//this action is not needed. just for understanding.
JedisPool jedisPool = new JedisPool("127.0.0.1", 6379);
Jedis jedis = jedisPool.getResource();
Pipeline pipeline = jedis.pipelined();
pipeline.hset(Const.REDIS_SERVICE_CAPACITY_DAILY, "300", "10000");
pipeline.hset(Const.REDIS_SERVICE_CAPACITY_MINUTELY, "300", "2000");
pipeline.hset(Const.REDIS_APP_RATELIMIT_DAILY, "100", "10000");
pipeline.hset(Const.REDIS_APP_RATELIMIT_MINUTELY, "100", "1500");
pipeline.sync();
jedis.close();
}
示例8: doOrderNotSafe
import redis.clients.jedis.Pipeline; //導入方法依賴的package包/類
/**
* 當無競爭情況時下單
*
* @param bracketMap bracket
* @param jedis redis連接
*/
public void doOrderNotSafe(Map<String, String> bracketMap, String userId, String bracketId, Jedis jedis) {
int size = bracketMap.size();
String sha;
if (this.scriptSHA.get(size) == null) {
StringBuilder updateBuilder = new StringBuilder();
for (int i = 1; i <= size; i++) {
updateBuilder.append(" redis.call('decrby',KEYS[").append(i).append("],ARGV[").append(i).append("])");
}
sha = jedis.scriptLoad(updateBuilder.substring(1));
this.scriptSHA.put(3 + size, sha);
} else {
sha = this.scriptSHA.get(3 + size);
}
List<String> keyList = new ArrayList<>();
List<String> paramList = new ArrayList<>();
for (String key : bracketMap.keySet()) {
keyList.add(Const.FOOD_STOCKS + key);
paramList.add(bracketMap.get(key));
}
Pipeline pipeline = jedis.pipelined();
pipeline.evalsha(sha, keyList, paramList);
pipeline.hdel(Const.BRACKET_ID_BUFFER, bracketId);
pipeline.hset(Const.ORDER_ID_BUFFER, userId, bracketId);
pipeline.sync();
}
示例9: updateUserSessionMap
import redis.clients.jedis.Pipeline; //導入方法依賴的package包/類
/**
* Update the user's session map in Redis.
*
* @param userSessionKey
* @param isAI
* @return
*/
@Override
public boolean updateUserSessionMap(SessionKey userSessionKey,
SessionKey roomSessionKey, boolean isAI, Pipeline pipeline) {
pipeline.hset(userSessionKey.toString(), H_ROOM_SESSION_KEY, roomSessionKey.toString());
// pipeline.hset(userSessionKey.toString(), H_ISAI, V_FALSE);
return true;
}
示例10: cleanUpPlayer
import redis.clients.jedis.Pipeline; //導入方法依賴的package包/類
public static void cleanUpPlayer(String player, Pipeline rsc) {
rsc.srem("proxy:" + RedisBungee.getApi().getServerId() + ":usersOnline", player);
rsc.hdel("player:" + player, "server", "ip", "proxy");
long timestamp = System.currentTimeMillis();
rsc.hset("player:" + player, "online", String.valueOf(timestamp));
rsc.publish("redisbungee-data", RedisBungee.getGson().toJson(new DataManager.DataManagerMessage<>(
UUID.fromString(player), DataManager.DataManagerMessage.Action.LEAVE,
new DataManager.LogoutPayload(timestamp))));
}
示例11: cacheDataRaw
import redis.clients.jedis.Pipeline; //導入方法依賴的package包/類
private void cacheDataRaw(Pipeline pipeline, KeyType key, ValueType data) {
try {
// Transform typed key -> redis key (field in redis hash), and encode data -> string
pipeline.hset(cacheKey, keyTypeToRedisKey.apply(key), valueTypeSerializationHelper.encode(data));
// Encode typed key -> string to remove from missing set.
pipeline.srem(cacheMissingKey(), keyTypeSerializationHelper.encode(key));
} catch(Exception jpe) {
Throwables.propagate(jpe);
}
}
示例12: hashSet
import redis.clients.jedis.Pipeline; //導入方法依賴的package包/類
private void hashSet(Jedis jedis, String cacheKey, String hfield, CacheWrapper<Object> result) throws Exception {
byte[] key=KEY_SERIALIZER.serialize(cacheKey);
byte[] field=KEY_SERIALIZER.serialize(hfield);
byte[] val=serializer.serialize(result);
int hExpire;
if(hashExpire < 0) {
hExpire=result.getExpire();
} else {
hExpire=hashExpire;
}
if(hExpire == 0) {
jedis.hset(key, field, val);
} else if(hExpire > 0) {
if(hashExpireByScript) {
String redisInstance = jedis.getClient().getHost()+":"+jedis.getClient().getPort();
byte[] sha=HASH_SET_SCRIPT_SHA.get(redisInstance);
if(null == sha) {
sha=jedis.scriptLoad(hashSetScript);
HASH_SET_SCRIPT_SHA.put(redisInstance, sha);
}
List<byte[]> keys=new ArrayList<byte[]>();
keys.add(key);
keys.add(field);
List<byte[]> args=new ArrayList<byte[]>();
args.add(val);
args.add(KEY_SERIALIZER.serialize(String.valueOf(hExpire)));
try {
jedis.evalsha(sha, keys, args);
} catch(Exception ex) {
logger.error(ex.getMessage(), ex);
try {
sha=jedis.scriptLoad(hashSetScript);
HASH_SET_SCRIPT_SHA.put(redisInstance, sha);
jedis.evalsha(sha, keys, args);
} catch(Exception ex1) {
logger.error(ex1.getMessage(), ex1);
}
}
} else {
Pipeline p=jedis.pipelined();
p.hset(key, field, val);
p.expire(key, hExpire);
p.sync();
}
}
}
示例13: Battle
import redis.clients.jedis.Pipeline; //導入方法依賴的package包/類
/**
* Create a new instance of Battle object.
* @param battleRoom
*/
public Battle(BattleRoom battleRoom, String gameServerId) {
this.battleRoom = battleRoom;
this.gameServerId = gameServerId;
Room roomLeft = battleRoom.getRoomLeft();
Room roomRight = battleRoom.getRoomRight();
roomType = roomLeft.getRoomType();
List<UserInfo> users1 = roomLeft.getUserInfoList();
this.userLeftList = makeUserList(users1, roomLeft.getRoomSessionKey(),
roomLeft.getCurrentUserCount(), BattleCamp.LEFT.id(), roomLeft.getRoomType());
List<UserInfo> users2 = roomRight.getUserInfoList();
this.userRightList = makeUserList(users2, roomRight.getRoomSessionKey(),
roomRight.getCurrentUserCount(), BattleCamp.RIGHT.id(), roomRight.getRoomType());
this.battleUserNumber = this.userLeftList.size() + this.userRightList.size();
//Choose the mapId
this.battleMap = chooseBattleMap(roomLeft.getMapId(), roomRight.getMapId());
//Save to Redis
String gameServerValue = null;
if ( this.gameServerId != null ) {
gameServerValue = this.gameServerId;
} else {
gameServerValue = Constant.EMPTY;
}
Pipeline pipeline = JedisFactory.getJedis().pipelined();
Collection<BattleUser> battleUsers = battleUserMap.values();
for (Iterator iter = battleUsers.iterator(); iter.hasNext();) {
BattleUser battleUser = (BattleUser) iter.next();
pipeline.hset(battleUser.getUserSessionKey().toString(), BATTLE_SERVER_KEY, gameServerValue);
pipeline.hset(battleUser.getUserSessionKey().toString(), BATTLE_SESSION_KEY,
this.battleRoom.getSessionKey().toString());
}
pipeline.sync();
//Setup relationship here
if ( this.battleRoom.getRoomRight().getRoomType() != RoomType.PVE_ROOM ) {
setupRelation();
}
/**
* Store the battle room type.
*/
battleRoomType = this.battleRoom.getRoomLeft().getRoomType();
}
示例14: createPlayer
import redis.clients.jedis.Pipeline; //導入方法依賴的package包/類
protected static void createPlayer(ProxiedPlayer player, Pipeline pipeline, boolean fireEvent) {
createPlayer(player.getPendingConnection(), pipeline, fireEvent);
if (player.getServer() != null)
pipeline.hset("player:" + player.getUniqueId().toString(), "server", player.getServer().getInfo().getName());
}