Perl Project Improvement(2)Redis and Multi-Threads and Error Handler for System

PerlProjectImprovement(2)RedisandMulti-ThreadsandErrorHandlerforSystem

1RedisCommandandKnowledge

AlwaysopenthisURLforreferencesofallthecommand

http://redis.io/commands

Hereishowweconnectandexecutesomecommand

>cd~/tool/redis-stable/

>src/redis-cli-hstage-sillycat-002.sillycat.amazonaws.com-p6379

OperationonhashvalueonRedis

>hsetsource_11in_process1

>hgetsource_11in_process

>hdelsource_11in_process

IamusingtheseforRedis

usestrict;

usewarnings;

useRedis;

packagelib::RedisClientHandler;

subinit{

my$configService=&loadService('configService');

my$logger=&loadLogger();

my$host=$configService->{redisHost};

my$port=$configService->{redisPort};

$logger->debug("initRedisconnection-----");

$logger->debug("host=".$host);

$logger->debug("port=".$port);

$logger->debug("--------------------------");

my$redis=Redis->new(server=>$host.":".$port);

$logger->debug("RedisSerivceinitsuccess".+$redis);

my$register=IOC::Registry->instance();

my$container=$register->getRegisteredContainer('JobsProducer');

$container->register(IOC::Service->new('redisService'

=>sub{$redis}));

return1;

}

IamusingsetinRedis

subpopTask{

die"Wrongarguments"if@_!=1;

#services

my$logger=&loadLogger();

my$redisService=&loadService('redisService');

#params

my$key=$_[0];

my$task=$redisService->spop($key);

return$task;

}

subpushTask{

die"Wrongarguments"if@_!=2;

#services

my$logger=&loadLogger();

my$redisService=&loadService('redisService');

#params

my$key=$_[0];

my$task=$_[1];

$redisService->sadd($key,$task);

return1;

}

subcheckTask{

die"Wrongarguments"if@_!=2;

#services

my$logger=&loadLogger();

my$redisService=&loadService('redisService');

#params

my$key=$_[0];

my$task=$_[1];

return$redisService->sismember($key,$task);

}

Directlyuseintegerthereaswell

subincrCount{

die"Wrongarguments"if@_!=1;

#services

my$logger=&loadLogger();

my$redisService=&loadService('redisService');

#parmas

my$key=$_[0];

$redisService->incr($key);

return1;

}

subdelCount{

die"Wrongarguments"if@_!=1;

my$logger=&loadLogger();

my$redisService=&loadService('redisService');

my$key=$_[0];

$redisService->del($key);

return1;

}

subgetCount{

die"Wrongarguments"if@_!=1;

#services

my$logger=&loadLogger();

my$redisService=&loadService('redisService');

#params

my$key=$_[0];

return$redisService->get($key);

}

MultipleThreadDBIx

http://search.cpan.org/~darnold/DBIx-Threaded-0.10/lib/DBIx/Threaded.pm

http://search.cpan.org/~dwheeler/DBIx-Connector-0.53/lib/DBIx/Connector.pm

cpanDBIx::Connector

MultipleThreadisusingaswell,andthenIswitchedmymysqldriver.

usethreads;

usethreads::shared;

useTime::Piece;

usestrict;

usewarnings;

useDBI;

useData::Dumper;

useDBIx::Connector;

ErrorHandlerforSystem

http://affy.blogspot.com/p5be/ch13.htm

http://www.perlmonks.org/?node_id=486200

http://perldoc.perl.org/functions/system.html

References:

http://search.cpan.org/~dwheeler/DBIx-Connector-0.53/lib/DBIx/Connector.pm

相关推荐