diff --git a/internal/core/metadata/application/device.go b/internal/core/metadata/application/device.go index c3f429a4cc..86d47dc99b 100644 --- a/internal/core/metadata/application/device.go +++ b/internal/core/metadata/application/device.go @@ -181,7 +181,7 @@ func AllDevices(offset int, limit int, labels []string, dic *di.Container) (devi dbClient := container.DBClientFrom(dic.Get) deviceModels, err := dbClient.AllDevices(offset, limit, labels) if err == nil { - totalCount, err = dbClient.DeviceTotalCount() + totalCount, err = dbClient.DeviceCountByLabels(labels) } if err != nil { return devices, totalCount, errors.NewCommonEdgeXWrapper(err) diff --git a/internal/core/metadata/application/deviceprofile.go b/internal/core/metadata/application/deviceprofile.go index 734b266da9..6b71855fc9 100644 --- a/internal/core/metadata/application/deviceprofile.go +++ b/internal/core/metadata/application/deviceprofile.go @@ -108,7 +108,7 @@ func AllDeviceProfiles(offset int, limit int, labels []string, dic *di.Container dbClient := container.DBClientFrom(dic.Get) dps, err := dbClient.AllDeviceProfiles(offset, limit, labels) if err == nil { - totalCount, err = dbClient.DeviceProfileTotalCount() + totalCount, err = dbClient.DeviceProfileCountByLabels(labels) } if err != nil { return deviceProfiles, totalCount, errors.NewCommonEdgeXWrapper(err) diff --git a/internal/core/metadata/application/deviceservice.go b/internal/core/metadata/application/deviceservice.go index 1a3df04a9c..e7007b8357 100644 --- a/internal/core/metadata/application/deviceservice.go +++ b/internal/core/metadata/application/deviceservice.go @@ -135,7 +135,7 @@ func AllDeviceServices(offset int, limit int, labels []string, ctx context.Conte dbClient := container.DBClientFrom(dic.Get) services, err := dbClient.AllDeviceServices(offset, limit, labels) if err == nil { - totalCount, err = dbClient.DeviceServiceTotalCount() + totalCount, err = dbClient.DeviceServiceCountByLabels(labels) } if err != nil { return deviceServices, totalCount, errors.NewCommonEdgeXWrapper(err) diff --git a/internal/core/metadata/application/provisionwatcher.go b/internal/core/metadata/application/provisionwatcher.go index 9186c29cd4..5b77ccd4af 100644 --- a/internal/core/metadata/application/provisionwatcher.go +++ b/internal/core/metadata/application/provisionwatcher.go @@ -104,7 +104,7 @@ func AllProvisionWatchers(offset int, limit int, labels []string, dic *di.Contai dbClient := container.DBClientFrom(dic.Get) pwModels, err := dbClient.AllProvisionWatchers(offset, limit, labels) if err == nil { - totalCount, err = dbClient.ProvisionWatcherTotalCount() + totalCount, err = dbClient.ProvisionWatcherCountByLabels(labels) } if err != nil { return provisionWatchers, totalCount, errors.NewCommonEdgeXWrapper(err) diff --git a/internal/core/metadata/controller/http/device_test.go b/internal/core/metadata/controller/http/device_test.go index f742bfe823..74fa10ffce 100644 --- a/internal/core/metadata/controller/http/device_test.go +++ b/internal/core/metadata/controller/http/device_test.go @@ -570,7 +570,8 @@ func TestAllDevices(t *testing.T) { dic := mockDic() dbClientMock := &dbMock.DBClient{} - dbClientMock.On("DeviceTotalCount").Return(expectedDeviceTotalCount, nil) + dbClientMock.On("DeviceCountByLabels", []string(nil)).Return(expectedDeviceTotalCount, nil) + dbClientMock.On("DeviceCountByLabels", testDeviceLabels).Return(expectedDeviceTotalCount, nil) dbClientMock.On("AllDevices", 0, 10, []string(nil)).Return(devices, nil) dbClientMock.On("AllDevices", 0, 5, testDeviceLabels).Return([]models.Device{devices[0], devices[1]}, nil) dbClientMock.On("AllDevices", 1, 2, []string(nil)).Return([]models.Device{devices[1], devices[2]}, nil) diff --git a/internal/core/metadata/controller/http/deviceprofile_test.go b/internal/core/metadata/controller/http/deviceprofile_test.go index 135fee6ef3..f9e158efe9 100644 --- a/internal/core/metadata/controller/http/deviceprofile_test.go +++ b/internal/core/metadata/controller/http/deviceprofile_test.go @@ -845,7 +845,8 @@ func TestAllDeviceProfiles(t *testing.T) { dic := mockDic() dbClientMock := &dbMock.DBClient{} - dbClientMock.On("DeviceProfileTotalCount").Return(expectedTotalProfileCount, nil) + dbClientMock.On("DeviceProfileCountByLabels", []string(nil)).Return(expectedTotalProfileCount, nil) + dbClientMock.On("DeviceProfileCountByLabels", testDeviceProfileLabels).Return(expectedTotalProfileCount, nil) dbClientMock.On("AllDeviceProfiles", 0, 10, []string(nil)).Return(deviceProfiles, nil) dbClientMock.On("AllDeviceProfiles", 0, 5, testDeviceProfileLabels).Return([]models.DeviceProfile{deviceProfiles[0], deviceProfiles[1]}, nil) dbClientMock.On("AllDeviceProfiles", 1, 2, []string(nil)).Return([]models.DeviceProfile{deviceProfiles[1], deviceProfiles[2]}, nil) diff --git a/internal/core/metadata/controller/http/deviceservice_test.go b/internal/core/metadata/controller/http/deviceservice_test.go index e657ffcaa1..4bbd62f757 100644 --- a/internal/core/metadata/controller/http/deviceservice_test.go +++ b/internal/core/metadata/controller/http/deviceservice_test.go @@ -400,7 +400,8 @@ func TestAllDeviceServices(t *testing.T) { dic := mockDic() dbClientMock := &dbMock.DBClient{} - dbClientMock.On("DeviceServiceTotalCount").Return(expectedTotalDeviceServiceCount, nil) + dbClientMock.On("DeviceServiceCountByLabels", []string(nil)).Return(expectedTotalDeviceServiceCount, nil) + dbClientMock.On("DeviceServiceCountByLabels", testDeviceServiceLabels).Return(expectedTotalDeviceServiceCount, nil) dbClientMock.On("AllDeviceServices", 0, 10, []string(nil)).Return(deviceServices, nil) dbClientMock.On("AllDeviceServices", 0, 5, testDeviceServiceLabels).Return([]models.DeviceService{deviceServices[0], deviceServices[1]}, nil) dbClientMock.On("AllDeviceServices", 1, 2, []string(nil)).Return([]models.DeviceService{deviceServices[1], deviceServices[2]}, nil) diff --git a/internal/core/metadata/controller/http/provisionwatcher_test.go b/internal/core/metadata/controller/http/provisionwatcher_test.go index 6dd7273d26..5a9f09dfe3 100644 --- a/internal/core/metadata/controller/http/provisionwatcher_test.go +++ b/internal/core/metadata/controller/http/provisionwatcher_test.go @@ -485,7 +485,8 @@ func TestProvisionWatcherController_AllProvisionWatchers(t *testing.T) { dic := mockDic() dbClientMock := &mocks.DBClient{} - dbClientMock.On("ProvisionWatcherTotalCount").Return(expectedTotalPWCount, nil) + dbClientMock.On("ProvisionWatcherCountByLabels", []string(nil)).Return(expectedTotalPWCount, nil) + dbClientMock.On("ProvisionWatcherCountByLabels", testProvisionWatcherLabels).Return(expectedTotalPWCount, nil) dbClientMock.On("AllProvisionWatchers", 0, 10, []string(nil)).Return(provisionWatchers, nil) dbClientMock.On("AllProvisionWatchers", 0, 5, testProvisionWatcherLabels).Return([]models.ProvisionWatcher{provisionWatchers[0], provisionWatchers[1]}, nil) dbClientMock.On("AllProvisionWatchers", 1, 2, []string(nil)).Return([]models.ProvisionWatcher{provisionWatchers[1], provisionWatchers[2]}, nil) diff --git a/internal/core/metadata/infrastructure/interfaces/db.go b/internal/core/metadata/infrastructure/interfaces/db.go index 1c8cceedb6..43b3e4dc6b 100644 --- a/internal/core/metadata/infrastructure/interfaces/db.go +++ b/internal/core/metadata/infrastructure/interfaces/db.go @@ -23,7 +23,7 @@ type DBClient interface { DeviceProfilesByModel(offset int, limit int, model string) ([]model.DeviceProfile, errors.EdgeX) DeviceProfilesByManufacturer(offset int, limit int, manufacturer string) ([]model.DeviceProfile, errors.EdgeX) DeviceProfilesByManufacturerAndModel(offset int, limit int, manufacturer string, model string) ([]model.DeviceProfile, uint32, errors.EdgeX) - DeviceProfileTotalCount() (uint32, errors.EdgeX) + DeviceProfileCountByLabels(labels []string) (uint32, errors.EdgeX) DeviceProfileCountByManufacturer(manufacturer string) (uint32, errors.EdgeX) DeviceProfileCountByModel(model string) (uint32, errors.EdgeX) @@ -35,7 +35,7 @@ type DBClient interface { DeviceServiceNameExists(name string) (bool, errors.EdgeX) AllDeviceServices(offset int, limit int, labels []string) ([]model.DeviceService, errors.EdgeX) UpdateDeviceService(ds model.DeviceService) errors.EdgeX - DeviceServiceTotalCount() (uint32, errors.EdgeX) + DeviceServiceCountByLabels(labels []string) (uint32, errors.EdgeX) AddDevice(d model.Device) (model.Device, errors.EdgeX) DeleteDeviceById(id string) errors.EdgeX @@ -48,7 +48,7 @@ type DBClient interface { AllDevices(offset int, limit int, labels []string) ([]model.Device, errors.EdgeX) DevicesByProfileName(offset int, limit int, profileName string) ([]model.Device, errors.EdgeX) UpdateDevice(d model.Device) errors.EdgeX - DeviceTotalCount() (uint32, errors.EdgeX) + DeviceCountByLabels(labels []string) (uint32, errors.EdgeX) DeviceCountByProfileName(profileName string) (uint32, errors.EdgeX) DeviceCountByServiceName(serviceName string) (uint32, errors.EdgeX) @@ -60,7 +60,7 @@ type DBClient interface { AllProvisionWatchers(offset int, limit int, labels []string) ([]model.ProvisionWatcher, errors.EdgeX) DeleteProvisionWatcherByName(name string) errors.EdgeX UpdateProvisionWatcher(pw model.ProvisionWatcher) errors.EdgeX - ProvisionWatcherTotalCount() (uint32, errors.EdgeX) + ProvisionWatcherCountByLabels(labels []string) (uint32, errors.EdgeX) ProvisionWatcherCountByServiceName(name string) (uint32, errors.EdgeX) ProvisionWatcherCountByProfileName(name string) (uint32, errors.EdgeX) } diff --git a/internal/core/metadata/infrastructure/interfaces/mocks/DBClient.go b/internal/core/metadata/infrastructure/interfaces/mocks/DBClient.go index 5d7f6e5171..e268bfcc67 100644 --- a/internal/core/metadata/infrastructure/interfaces/mocks/DBClient.go +++ b/internal/core/metadata/infrastructure/interfaces/mocks/DBClient.go @@ -370,6 +370,29 @@ func (_m *DBClient) DeviceByName(name string) (models.Device, errors.EdgeX) { return r0, r1 } +// DeviceCountByLabels provides a mock function with given fields: labels +func (_m *DBClient) DeviceCountByLabels(labels []string) (uint32, errors.EdgeX) { + ret := _m.Called(labels) + + var r0 uint32 + if rf, ok := ret.Get(0).(func([]string) uint32); ok { + r0 = rf(labels) + } else { + r0 = ret.Get(0).(uint32) + } + + var r1 errors.EdgeX + if rf, ok := ret.Get(1).(func([]string) errors.EdgeX); ok { + r1 = rf(labels) + } else { + if ret.Get(1) != nil { + r1 = ret.Get(1).(errors.EdgeX) + } + } + + return r0, r1 +} + // DeviceCountByProfileName provides a mock function with given fields: profileName func (_m *DBClient) DeviceCountByProfileName(profileName string) (uint32, errors.EdgeX) { ret := _m.Called(profileName) @@ -485,6 +508,29 @@ func (_m *DBClient) DeviceProfileByName(name string) (models.DeviceProfile, erro return r0, r1 } +// DeviceProfileCountByLabels provides a mock function with given fields: labels +func (_m *DBClient) DeviceProfileCountByLabels(labels []string) (uint32, errors.EdgeX) { + ret := _m.Called(labels) + + var r0 uint32 + if rf, ok := ret.Get(0).(func([]string) uint32); ok { + r0 = rf(labels) + } else { + r0 = ret.Get(0).(uint32) + } + + var r1 errors.EdgeX + if rf, ok := ret.Get(1).(func([]string) errors.EdgeX); ok { + r1 = rf(labels) + } else { + if ret.Get(1) != nil { + r1 = ret.Get(1).(errors.EdgeX) + } + } + + return r0, r1 +} + // DeviceProfileCountByManufacturer provides a mock function with given fields: manufacturer func (_m *DBClient) DeviceProfileCountByManufacturer(manufacturer string) (uint32, errors.EdgeX) { ret := _m.Called(manufacturer) @@ -554,29 +600,6 @@ func (_m *DBClient) DeviceProfileNameExists(name string) (bool, errors.EdgeX) { return r0, r1 } -// DeviceProfileTotalCount provides a mock function with given fields: -func (_m *DBClient) DeviceProfileTotalCount() (uint32, errors.EdgeX) { - ret := _m.Called() - - var r0 uint32 - if rf, ok := ret.Get(0).(func() uint32); ok { - r0 = rf() - } else { - r0 = ret.Get(0).(uint32) - } - - var r1 errors.EdgeX - if rf, ok := ret.Get(1).(func() errors.EdgeX); ok { - r1 = rf() - } else { - if ret.Get(1) != nil { - r1 = ret.Get(1).(errors.EdgeX) - } - } - - return r0, r1 -} - // DeviceProfilesByManufacturer provides a mock function with given fields: offset, limit, manufacturer func (_m *DBClient) DeviceProfilesByManufacturer(offset int, limit int, manufacturer string) ([]models.DeviceProfile, errors.EdgeX) { ret := _m.Called(offset, limit, manufacturer) @@ -705,43 +728,20 @@ func (_m *DBClient) DeviceServiceByName(name string) (models.DeviceService, erro return r0, r1 } -// DeviceServiceNameExists provides a mock function with given fields: name -func (_m *DBClient) DeviceServiceNameExists(name string) (bool, errors.EdgeX) { - ret := _m.Called(name) - - var r0 bool - if rf, ok := ret.Get(0).(func(string) bool); ok { - r0 = rf(name) - } else { - r0 = ret.Get(0).(bool) - } - - var r1 errors.EdgeX - if rf, ok := ret.Get(1).(func(string) errors.EdgeX); ok { - r1 = rf(name) - } else { - if ret.Get(1) != nil { - r1 = ret.Get(1).(errors.EdgeX) - } - } - - return r0, r1 -} - -// DeviceServiceTotalCount provides a mock function with given fields: -func (_m *DBClient) DeviceServiceTotalCount() (uint32, errors.EdgeX) { - ret := _m.Called() +// DeviceServiceCountByLabels provides a mock function with given fields: labels +func (_m *DBClient) DeviceServiceCountByLabels(labels []string) (uint32, errors.EdgeX) { + ret := _m.Called(labels) var r0 uint32 - if rf, ok := ret.Get(0).(func() uint32); ok { - r0 = rf() + if rf, ok := ret.Get(0).(func([]string) uint32); ok { + r0 = rf(labels) } else { r0 = ret.Get(0).(uint32) } var r1 errors.EdgeX - if rf, ok := ret.Get(1).(func() errors.EdgeX); ok { - r1 = rf() + if rf, ok := ret.Get(1).(func([]string) errors.EdgeX); ok { + r1 = rf(labels) } else { if ret.Get(1) != nil { r1 = ret.Get(1).(errors.EdgeX) @@ -751,20 +751,20 @@ func (_m *DBClient) DeviceServiceTotalCount() (uint32, errors.EdgeX) { return r0, r1 } -// DeviceTotalCount provides a mock function with given fields: -func (_m *DBClient) DeviceTotalCount() (uint32, errors.EdgeX) { - ret := _m.Called() +// DeviceServiceNameExists provides a mock function with given fields: name +func (_m *DBClient) DeviceServiceNameExists(name string) (bool, errors.EdgeX) { + ret := _m.Called(name) - var r0 uint32 - if rf, ok := ret.Get(0).(func() uint32); ok { - r0 = rf() + var r0 bool + if rf, ok := ret.Get(0).(func(string) bool); ok { + r0 = rf(name) } else { - r0 = ret.Get(0).(uint32) + r0 = ret.Get(0).(bool) } var r1 errors.EdgeX - if rf, ok := ret.Get(1).(func() errors.EdgeX); ok { - r1 = rf() + if rf, ok := ret.Get(1).(func(string) errors.EdgeX); ok { + r1 = rf(name) } else { if ret.Get(1) != nil { r1 = ret.Get(1).(errors.EdgeX) @@ -870,20 +870,20 @@ func (_m *DBClient) ProvisionWatcherByName(name string) (models.ProvisionWatcher return r0, r1 } -// ProvisionWatcherCountByProfileName provides a mock function with given fields: name -func (_m *DBClient) ProvisionWatcherCountByProfileName(name string) (uint32, errors.EdgeX) { - ret := _m.Called(name) +// ProvisionWatcherCountByLabels provides a mock function with given fields: labels +func (_m *DBClient) ProvisionWatcherCountByLabels(labels []string) (uint32, errors.EdgeX) { + ret := _m.Called(labels) var r0 uint32 - if rf, ok := ret.Get(0).(func(string) uint32); ok { - r0 = rf(name) + if rf, ok := ret.Get(0).(func([]string) uint32); ok { + r0 = rf(labels) } else { r0 = ret.Get(0).(uint32) } var r1 errors.EdgeX - if rf, ok := ret.Get(1).(func(string) errors.EdgeX); ok { - r1 = rf(name) + if rf, ok := ret.Get(1).(func([]string) errors.EdgeX); ok { + r1 = rf(labels) } else { if ret.Get(1) != nil { r1 = ret.Get(1).(errors.EdgeX) @@ -893,8 +893,8 @@ func (_m *DBClient) ProvisionWatcherCountByProfileName(name string) (uint32, err return r0, r1 } -// ProvisionWatcherCountByServiceName provides a mock function with given fields: name -func (_m *DBClient) ProvisionWatcherCountByServiceName(name string) (uint32, errors.EdgeX) { +// ProvisionWatcherCountByProfileName provides a mock function with given fields: name +func (_m *DBClient) ProvisionWatcherCountByProfileName(name string) (uint32, errors.EdgeX) { ret := _m.Called(name) var r0 uint32 @@ -916,20 +916,20 @@ func (_m *DBClient) ProvisionWatcherCountByServiceName(name string) (uint32, err return r0, r1 } -// ProvisionWatcherTotalCount provides a mock function with given fields: -func (_m *DBClient) ProvisionWatcherTotalCount() (uint32, errors.EdgeX) { - ret := _m.Called() +// ProvisionWatcherCountByServiceName provides a mock function with given fields: name +func (_m *DBClient) ProvisionWatcherCountByServiceName(name string) (uint32, errors.EdgeX) { + ret := _m.Called(name) var r0 uint32 - if rf, ok := ret.Get(0).(func() uint32); ok { - r0 = rf() + if rf, ok := ret.Get(0).(func(string) uint32); ok { + r0 = rf(name) } else { r0 = ret.Get(0).(uint32) } var r1 errors.EdgeX - if rf, ok := ret.Get(1).(func() errors.EdgeX); ok { - r1 = rf() + if rf, ok := ret.Get(1).(func(string) errors.EdgeX); ok { + r1 = rf(name) } else { if ret.Get(1) != nil { r1 = ret.Get(1).(errors.EdgeX) diff --git a/internal/pkg/infrastructure/redis/client.go b/internal/pkg/infrastructure/redis/client.go index e67fc7d7e6..669b6183b1 100644 --- a/internal/pkg/infrastructure/redis/client.go +++ b/internal/pkg/infrastructure/redis/client.go @@ -816,12 +816,12 @@ func (c *Client) UpdateProvisionWatcher(pw model.ProvisionWatcher) errors.EdgeX return updateProvisionWatcher(conn, pw) } -// DeviceProfileTotalCount returns the total count of Device Profiles stored in the database -func (c *Client) DeviceProfileTotalCount() (uint32, errors.EdgeX) { +// DeviceProfileCountByLabels returns the total count of Device Profiles with labels specified. If no label is specified, the total count of all device profiles will be returned. +func (c *Client) DeviceProfileCountByLabels(labels []string) (uint32, errors.EdgeX) { conn := c.Pool.Get() defer conn.Close() - count, edgeXerr := getMemberNumber(conn, ZCARD, DeviceProfileCollection) + count, edgeXerr := getMemberCountByLabels(conn, ZREVRANGE, DeviceProfileCollection, labels) if edgeXerr != nil { return 0, errors.NewCommonEdgeXWrapper(edgeXerr) } @@ -855,12 +855,12 @@ func (c *Client) DeviceProfileCountByModel(model string) (uint32, errors.EdgeX) return count, nil } -// DeviceServiceTotalCount returns the total count of Device Services stored in the database -func (c *Client) DeviceServiceTotalCount() (uint32, errors.EdgeX) { +// DeviceServiceCountByLabels returns the total count of Device Services with labels specified. If no label is specified, the total count of all device services will be returned. +func (c *Client) DeviceServiceCountByLabels(labels []string) (uint32, errors.EdgeX) { conn := c.Pool.Get() defer conn.Close() - count, edgeXerr := getMemberNumber(conn, ZCARD, DeviceServiceCollection) + count, edgeXerr := getMemberCountByLabels(conn, ZREVRANGE, DeviceServiceCollection, labels) if edgeXerr != nil { return 0, errors.NewCommonEdgeXWrapper(edgeXerr) } @@ -868,12 +868,12 @@ func (c *Client) DeviceServiceTotalCount() (uint32, errors.EdgeX) { return count, nil } -// DeviceTotalCount returns the total count of Devices stored in the database -func (c *Client) DeviceTotalCount() (uint32, errors.EdgeX) { +// DeviceCountByLabels returns the total count of Devices with labels specified. If no label is specified, the total count of all devices will be returned. +func (c *Client) DeviceCountByLabels(labels []string) (uint32, errors.EdgeX) { conn := c.Pool.Get() defer conn.Close() - count, edgeXerr := getMemberNumber(conn, ZCARD, DeviceCollection) + count, edgeXerr := getMemberCountByLabels(conn, ZREVRANGE, DeviceCollection, labels) if edgeXerr != nil { return 0, errors.NewCommonEdgeXWrapper(edgeXerr) } @@ -907,12 +907,12 @@ func (c *Client) DeviceCountByServiceName(serviceName string) (uint32, errors.Ed return count, nil } -// ProvisionWatcherTotalCount returns the total count of Provision Watcher stored in the database -func (c *Client) ProvisionWatcherTotalCount() (uint32, errors.EdgeX) { +// ProvisionWatcherCountByLabels returns the total count of Provision Watchers with labels specified. If no label is specified, the total count of all provision watchers will be returned. +func (c *Client) ProvisionWatcherCountByLabels(labels []string) (uint32, errors.EdgeX) { conn := c.Pool.Get() defer conn.Close() - count, edgeXerr := getMemberNumber(conn, ZCARD, ProvisionWatcherCollection) + count, edgeXerr := getMemberCountByLabels(conn, ZREVRANGE, ProvisionWatcherCollection, labels) if edgeXerr != nil { return 0, errors.NewCommonEdgeXWrapper(edgeXerr) } diff --git a/internal/pkg/infrastructure/redis/queries.go b/internal/pkg/infrastructure/redis/queries.go index b1e70b9292..2b8aa36eb1 100644 --- a/internal/pkg/infrastructure/redis/queries.go +++ b/internal/pkg/infrastructure/redis/queries.go @@ -191,6 +191,25 @@ func getMemberCountByScoreRange(conn redis.Conn, key string, start int, end int) return uint32(count), nil } +// getMemberCountByLabels return the record count of key with labels specified. +func getMemberCountByLabels(conn redis.Conn, command string, key string, labels []string) (uint32, errors.EdgeX) { + if len(labels) == 0 { //if no labels specified, simply return the count of record for the key + return getMemberNumber(conn, ZCARD, key) + } + + idsSlice := make([][]string, len(labels)) + for i, label := range labels { //iterate each labels to retrieve Ids associated with labels + idsWithLabel, err := redis.Strings(conn.Do(command, CreateKey(key, common.Label, label), 0, -1)) + if err != nil { + return 0, errors.NewCommonEdgeX(errors.KindDatabaseError, fmt.Sprintf("query object ids by label %s from database failed", label), err) + } + idsSlice[i] = idsWithLabel + } + //find common Ids among two-dimension Ids slice associated with labels + commonIds := pkgCommon.FindCommonStrings(idsSlice...) + return uint32(len(commonIds)), nil +} + func getMemberNumber(conn redis.Conn, command string, key string) (uint32, errors.EdgeX) { count, err := redis.Int(conn.Do(command, key)) if err != nil {