Redis缓存空间优化实践详解(redis缓存优化)干货满满

随心笔谈1年前 (2023)发布 admin
110 0

 public byte[] toByteArray() throws Exception {
MessageBufferPacker packer=MessagePack.newDefaultBufferPacker();
toByteArray(packer);
packer.close();
return packer.toByteArray();
}

public void toByteArray(MessageBufferPacker packer) throws Exception {
if (testStatus==null) {
packer.packNil();
}else{
packer.packString(testStatus);
}

if (userPin==null) {
packer.packNil();
}else{
packer.packString(userPin);
}

if (investor==null) {
packer.packNil();
}else{
packer.packString(investor);
}

if (testQueryTime==null) {
packer.packNil();
}else{
packer.packLong(testQueryTime.getTime());
}

if (createTime==null) {
packer.packNil();
}else{
packer.packLong(createTime.getTime());
}

if (bizInfo==null) {
packer.packNil();
}else{
packer.packString(bizInfo);
}

if (otherTime==null) {
packer.packNil();
}else{
packer.packLong(otherTime.getTime());
}

if (userAmount==null) {
packer.packNil();
}else{
packer.packString(userAmount.toString());
}

if (userRate==null) {
packer.packNil();
}else{
packer.packString(userRate.toString());
}

if (applyAmount==null) {
packer.packNil();
}else{
packer.packString(applyAmount.toString());
}

if (type==null) {
packer.packNil();
}else{
packer.packString(type);
}

if (checkTime==null) {
packer.packNil();
}else{
packer.packString(checkTime);
}

if (preTestStatus==null) {
packer.packNil();
}else{
packer.packString(preTestStatus);
}
}

public void fromByteArray(byte[] byteArray) throws Exception {
MessageUnpacker unpacker=MessagePack.newDefaultUnpacker(byteArray);
fromByteArray(unpacker);
unpacker.close();
}

public void fromByteArray(MessageUnpacker unpacker) throws Exception {
if (!unpacker.tryUnpackNil()){
this.setTestStatus(unpacker.unpackString());
}
if (!unpacker.tryUnpackNil()){
this.setUserPin(unpacker.unpackString());
}
if (!unpacker.tryUnpackNil()){
this.setInvestor(unpacker.unpackString());
}
if (!unpacker.tryUnpackNil()){
this.setTestQueryTime(new Date(unpacker.unpackLong()));
}
if (!unpacker.tryUnpackNil()){
this.setCreateTime(new Date(unpacker.unpackLong()));
}
if (!unpacker.tryUnpackNil()){
this.setBizInfo(unpacker.unpackString());
}
if (!unpacker.tryUnpackNil()){
this.setOtherTime(new Date(unpacker.unpackLong()));
}
if (!unpacker.tryUnpackNil()){
this.setUserAmount(new BigDecimal(unpacker.unpackString()));
}
if (!unpacker.tryUnpackNil()){
this.setUserRate(new BigDecimal(unpacker.unpackString()));
}
if (!unpacker.tryUnpackNil()){
this.setApplyAmount(new BigDecimal(unpacker.unpackString()));
}
if (!unpacker.tryUnpackNil()){
this.setType(unpacker.unpackString());
}
if (!unpacker.tryUnpackNil()){
this.setCheckTime(unpacker.unpackString());
}
if (!unpacker.tryUnpackNil()){
this.setPreTestStatus(unpacker.unpackString());
}
}

© 版权声明

相关文章