本文整理汇总了Java中org.springframework.data.redis.core.HashOperations类的典型用法代码示例。如果您正苦于以下问题:Java HashOperations类的具体用法?Java HashOperations怎么用?Java HashOperations使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
HashOperations类属于org.springframework.data.redis.core包,在下文中一共展示了HashOperations类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: doUserLogin
import org.springframework.data.redis.core.HashOperations; //导入依赖的package包/类
public User doUserLogin(User user) throws Exception {
User loginUser = new User();
try {
HashOperations<String,Object,Object> hashOperations = redisTemplate.opsForHash();
Map<Object, Object> userMap = hashOperations.entries(user.getUserName());
System.out.println("userpassword:" + user.getPassword());
System.out.println("userpassword:" + userMap.get("password"));
if (user.getPassword().equals(userMap.get("password")) &&
user.getVerifyCode().equals(userMap.get("verifyCode"))) {
//登陆成功返回用户名
System.out.println("登陆成功");
loginUser.setUserName((String) userMap.get("userName"));
loginUser.setNickName((String) userMap.get("nickName"));
//登陆成功清除验证码
hashOperations.put(loginUser.getUserName(),"verifyCode","");
}
}catch(Exception e){
//发生错误时强制关闭实例
e.printStackTrace();
}
return loginUser;
}
示例2: getGroupPush
import org.springframework.data.redis.core.HashOperations; //导入依赖的package包/类
@Override
public List<ShieldStatusEntity> getGroupPush(long groupId, List<String> userIdList) {
final String groupSetKey = RedisKeys.concat(RedisKeys.GROUP_INFO, groupId, RedisKeys.SETTING_INFO);
HashOperations<String, String, String> groupMapOps = redisTemplate.opsForHash();
List<String> statusList = groupMapOps.multiGet(groupSetKey, userIdList);
List<ShieldStatusEntity> shieldStatusList = new ArrayList<>();
for (int i = 0; i < userIdList.size(); i++) {
String status = statusList.get(i);
String userId = userIdList.get(i);
ShieldStatusEntity shieldStatus = new ShieldStatusEntity();
shieldStatus.setUserId(Long.valueOf(userId));
shieldStatus.setShieldStatus(status == null?DBConstant.GROUP_STATUS_ONLINE: DBConstant.GROUP_STATUS_SHIELD);
shieldStatus.setUserToken(userTokenService.getToken(userId));
shieldStatusList.add(shieldStatus);
}
return shieldStatusList;
}
示例3: clearUserCounter
import org.springframework.data.redis.core.HashOperations; //导入依赖的package包/类
/**
* 消息用户计数
* @param userCountReq 会话信息
* @return 更新结果
* @since 1.0
*/
@PostMapping("/clearUserCounter")
public BaseModel<?> clearUserCounter(@RequestBody ClearUserCountReq userCountReq) {
HashOperations<String, String, String> hashOptions = redisTemplate.opsForHash();
if (userCountReq.getSessionType() == IMBaseDefine.SessionType.SESSION_TYPE_SINGLE) {
// Clear P2P msg Counter
final String userKey = RedisKeys.concat(RedisKeys.USER_UNREAD, userCountReq.getUserId());
hashOptions.delete(userKey, String.valueOf(userCountReq.getPeerId()));
} else if (userCountReq.getSessionType() == IMBaseDefine.SessionType.SESSION_TYPE_GROUP) {
// Clear Group msg Counter
final String groupSetKey = RedisKeys.concat(RedisKeys.GROUP_INFO, userCountReq.getPeerId(), RedisKeys.SETTING_INFO);
final String countValue = hashOptions.get(groupSetKey, RedisKeys.COUNT);
final String userUnreadKey = RedisKeys.concat(RedisKeys.GROUP_UNREAD, userCountReq.getUserId());
hashOptions.put(userUnreadKey, String.valueOf(userCountReq.getPeerId()), countValue);
} else {
logger.warn("参数不正: SessionType={}", userCountReq.getSessionType());
}
return null;
}
示例4: testObj
import org.springframework.data.redis.core.HashOperations; //导入依赖的package包/类
@Test
public void testObj() throws Exception {
AccountEntity accountEntity = accountService.getAccount(1);
HashOperations<String, String, String> operations=redisTemplate.opsForHash();
operations.put("demo:account",String.valueOf(accountEntity.getId()), JSON.toJSONString(accountEntity));
Thread.sleep(1000);
boolean exists=redisTemplate.hasKey("demo:account");
Assert.assertTrue("不存在",exists);
AccountEntity accountEntityCache =JSON.parseObject(String.valueOf(operations.get("demo:account","1")) ,AccountEntity.class);
Assert.assertEquals("json",accountEntityCache.getNickName());
}
示例5: isValidate
import org.springframework.data.redis.core.HashOperations; //导入依赖的package包/类
@Override
public boolean isValidate(long groupId, long userId) {
String key = RedisKeys.concat(RedisKeys.GROUP_INFO, groupId);
if (redisTemplate.hasKey(key)) {
HashOperations<String, String, String> groupMemberHash = redisTemplate.opsForHash();
groupMemberHash.hasKey(key, String.valueOf(userId));
}
return false;
}
示例6: getToken
import org.springframework.data.redis.core.HashOperations; //导入依赖的package包/类
@Override
public String getToken(long userId) {
HashOperations<String, String, String> opsHash = redisTemplate.opsForHash();
String key = RedisKeys.concat(RedisKeys.USER_INFO, userId);
return opsHash.get(key, RedisKeys.USER_TOKEN);
}
示例7: groupInfoList
import org.springframework.data.redis.core.HashOperations; //导入依赖的package包/类
/**
* 查询组的属性
* @param groupVersionList
* @return 查询结果:群资料(版本)
* @since 1.0
*/
@GetMapping(path = "/groupInfoList")
public BaseModel<List<GroupEntity>> groupInfoList(@RequestParam("groupIdList") List<Long> groupIdList) {
SearchCriteria<IMGroup> groupSearchCriteria = new SearchCriteria<>();
groupSearchCriteria.add(JpaRestrictions.in("id", groupIdList, false));
Sort sort = new Sort(Sort.Direction.DESC, "updated");
List<IMGroup> groups = groupRepository.findAll(groupSearchCriteria, sort);
List<GroupEntity> resData = new ArrayList<>();
for (IMGroup group: groups) {
GroupEntity groupEntity = new GroupEntity();
groupEntity.setId(group.getId());
groupEntity.setAvatar(group.getAvatar());
groupEntity.setCreated(group.getCreated());
groupEntity.setCreatorId(group.getCreator());
groupEntity.setGroupType(group.getType());
groupEntity.setStatus(group.getStatus());
groupEntity.setMainName(group.getName());
groupEntity.setVersion(group.getVersion());
resData.add(groupEntity);
// fillGroupMember
String key = RedisKeys.concat(RedisKeys.GROUP_INFO, group.getId());
HashOperations<String, String, String> groupMapOps = redisTemplate.opsForHash();
Map<String, String> groupMemberMap = groupMapOps.entries(key);
List<Long> userIds = new ArrayList<>();
if (groupMemberMap != null) {
for (String memberId : groupMemberMap.keySet()) {
userIds.add(Long.valueOf(memberId));
}
}
groupEntity.setUserList(userIds);
}
BaseModel<List<GroupEntity>> groupRes = new BaseModel<>();
groupRes.setData(resData);
return groupRes;
}
示例8: getGroupPushInfo
import org.springframework.data.redis.core.HashOperations; //导入依赖的package包/类
/**
* 查询组的属性
* @param groupVersionList
* @return 查询结果:群资料(版本)
* @since 1.0
*/
@GetMapping(path = "/groupPushInfo")
@Transactional(readOnly = true)
public BaseModel<GroupPushEntity> getGroupPushInfo(@RequestParam("groupId") Long groupId) {
BaseModel<GroupPushEntity> groupRes = new BaseModel<>();
IMGroup group = groupRepository.findOne(groupId);
if (group != null) {
GroupPushEntity groupEntity = new GroupPushEntity();
groupEntity.setId(group.getId());
groupEntity.setAvatar(group.getAvatar());
groupEntity.setCreated(group.getCreated());
groupEntity.setCreatorId(group.getCreator());
groupEntity.setGroupType(group.getType());
groupEntity.setStatus(group.getStatus());
groupEntity.setMainName(group.getName());
groupEntity.setVersion(group.getVersion());
// fillGroupMember
String key = RedisKeys.concat(RedisKeys.GROUP_INFO, group.getId());
HashOperations<String, String, String> groupMapOps = redisTemplate.opsForHash();
Map<String, String> groupMemberMap = groupMapOps.entries(key);
List<String> userIdList = new ArrayList<>();
if (groupMemberMap != null) {
for (String memberId : groupMemberMap.keySet()) {
userIdList.add(memberId);
}
}
groupRes.setData(groupEntity);
// push shield status
List<ShieldStatusEntity> shieldStatusList = groupInternalService.getGroupPush(groupId, userIdList);
groupEntity.setUserList(shieldStatusList);
} else {
groupRes.setCode(1);
}
return groupRes;
}
示例9: pushShield
import org.springframework.data.redis.core.HashOperations; //导入依赖的package包/类
@PostMapping(path = "/login/pushShield")
public BaseModel<Integer> pushShield(@RequestParam("userId") long userId, @RequestParam("shieldStatus") int shieldStatus) {
String key = RedisKeys.concat(RedisKeys.USER_INFO, userId);
HashOperations<String, String, String> userMapOps = redisTemplate.opsForHash();
userMapOps.put(key, RedisKeys.USER_SHIELD, String.valueOf(shieldStatus));
return new BaseModel<Integer>();
}
示例10: queryPushShield
import org.springframework.data.redis.core.HashOperations; //导入依赖的package包/类
@GetMapping(path = "/login/queryPushShield")
public BaseModel<Integer> queryPushShield(@RequestParam("userId") long userId) {
String key = RedisKeys.concat(RedisKeys.USER_INFO, userId);
HashOperations<String, String, String> userMapOps = redisTemplate.opsForHash();
String shieldStatus = userMapOps.get(key, RedisKeys.USER_SHIELD);
BaseModel<Integer> res = new BaseModel<Integer>();
if (shieldStatus != null) {
res.setData(Integer.valueOf(shieldStatus));
}
return res;
}
示例11: opsForHash
import org.springframework.data.redis.core.HashOperations; //导入依赖的package包/类
@Override
public <HK, HV> HashOperations<K, HK, HV> opsForHash() {
try {
return redisTemplate.opsForHash();
} catch (Exception ex) {
throw new RedisBaoException(ex);
}
}
示例12: getHashOps
import org.springframework.data.redis.core.HashOperations; //导入依赖的package包/类
private HashOperations<String, Object, Object> getHashOps() {
return redisTemplate.opsForHash();
}
示例13: putHash
import org.springframework.data.redis.core.HashOperations; //导入依赖的package包/类
@Override
public void putHash(final String key, final Object hashKey, final Object hashValue) {
final HashOperations<String, Object, Object> operation = redisTemplate.opsForHash();
operation.put(getKey(key), hashKey, hashValue);
}
示例14: putAllHash
import org.springframework.data.redis.core.HashOperations; //导入依赖的package包/类
@Override
public void putAllHash(final String key, final Map<? extends Object, ? extends Object> keyValue) {
final HashOperations<String, Object, Object> operation = redisTemplate.opsForHash();
operation.putAll(getKey(key), keyValue);
}
示例15: getHash
import org.springframework.data.redis.core.HashOperations; //导入依赖的package包/类
@Override
public Object getHash(final String key, final String hashKey) {
final HashOperations<String, Object, Object> operation = redisTemplate.opsForHash();
final Object value = operation.get(getKey(key), hashKey);
return value;
}