package APKPM::Model;
use warnings;
use strict;

use Redis;

sub redis_status {
	my $redis = Redis->new;

	my $status;
	foreach my $p ( qw(ZTEDSLAM ZTEMSAN CPE) ) {
		foreach my $k ( $redis->keys("$p.*") ) {
			$status->{$k} = eval { $redis->scard($k) } || $redis->get($k);
			if ( $k =~ m/^(ZTE\w+)\.(\d+\.\d+\.\d+\.\d+)\.(\w+)/ ) {
				#$status->{$1}->{$2}->{$3} = $status->{$k};
				$status->{poll}->{$1}->{$3} += $status->{$k};
			} elsif ( $k =~ m/^CPE\.(.+)/ ) {
				$status->{poll}->{CPE}->{$1} = $status->{$k};
			}
		}
	}

	return $status;
}

1;
