func xscan(db *ledis.DB, tp string, count int) ([][]byte, error) { switch strings.ToUpper(tp) { case KVName: return db.Scan(KV, nil, count, false, "") case HashName: return db.Scan(HASH, nil, count, false, "") case ListName: return db.Scan(LIST, nil, count, false, "") case SetName: return db.Scan(SET, nil, count, false, "") case ZSetName: return db.Scan(ZSET, nil, count, false, "") default: return nil, fmt.Errorf("invalid key type %s", tp) } }
func xttl(db *ledis.DB, tp string, key []byte) (int64, error) { switch strings.ToUpper(tp) { case KVName: return db.TTL(key) case HashName: return db.HTTL(key) case ListName: return db.LTTL(key) case SetName: return db.STTL(key) case ZSetName: return db.ZTTL(key) default: return 0, fmt.Errorf("invalid key type %s", tp) } }
func xdel(db *ledis.DB, tp string, key []byte) error { var err error switch strings.ToUpper(tp) { case KVName: _, err = db.Del(key) case HashName: _, err = db.HClear(key) case ListName: _, err = db.LClear(key) case SetName: _, err = db.SClear(key) case ZSetName: _, err = db.ZClear(key) default: err = fmt.Errorf("invalid key type %s", tp) } return err }
func xdump(db *ledis.DB, tp string, key []byte) ([]byte, error) { var err error var data []byte switch strings.ToUpper(tp) { case KVName: data, err = db.Dump(key) case HashName: data, err = db.HDump(key) case ListName: data, err = db.LDump(key) case SetName: data, err = db.SDump(key) case ZSetName: data, err = db.ZDump(key) default: err = fmt.Errorf("invalid key type %s", tp) } return data, err }