Authored by whb

框架

Showing 50 changed files with 4782 additions and 0 deletions

Too many changes to show.

To preserve performance only 50 of 50+ files are displayed.

<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>QF1.0</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
</buildSpec>
<natures>
</natures>
</projectDescription>
... ...
[memcached]
servers.proxys = 127.0.0.1:11211
[redis]
servers.proxys = 127.0.0.1:6379
\ No newline at end of file
... ...
[memcached]
servers.proxys = 192.168.100.111:11211,192.168.100.111:11212,192.168.100.111:11213,192.168.100.112:11211,192.168.100.112:11212,192.168.100.112:11213,192.168.100.241:11211,192.168.100.241:11212,192.168.100.241:11213
[redis]
servers.proxys = 192.168.100.112:6379
queue.proxys = 192.168.200.206:6379
\ No newline at end of file
... ...
[memcached]
servers.proxys = 127.0.0.1:11211,127.0.0.1:11212
[redis]
servers.proxys = 127.0.0.1:6379
queue.proxys = 127.0.0.1:6379
\ No newline at end of file
... ...
[mysql]
erp_admin.username = root
erp_admin.password=123456
erp_admin.writers = 127.0.0.1:3306
erp_admin.readers = 127.0.0.1:3306
erp_orders.username = root
erp_orders.password=123456
erp_orders.writers = 127.0.0.1:3306
erp_orders.readers = 127.0.0.1:3306
yohood.username = root
yohood.password=123456
yohood.writers = 127.0.0.1:3306
yohood.readers = 127.0.0.1:3306
yoho_sms.username = root
yoho_sms.password=123456
yoho_sms.writers = 127.0.0.1:3306
yoho_sms.readers = 127.0.0.1:3306
yh_inbox.username = root
yh_inbox.password=123456
yh_inbox.writers = 127.0.0.1:3306
yh_inbox.readers = 127.0.0.1:3306
yh_channel.username = root
yh_channel.password=123456
yh_channel.writers = 127.0.0.1:3306
yh_channel.readers = 127.0.0.1:3306
erp_order_logs.username = root
erp_order_logs.password=123456
erp_order_logs.writers = 127.0.0.1:3306
erp_order_logs.readers = 127.0.0.1:3306
erp_order_stockcheck.username = root
erp_order_stockcheck.password=123456
erp_order_stockcheck.writers = 127.0.0.1:3306
erp_order_stockcheck.readers = 127.0.0.1:3306
erp_passport.username = root
erp_passport.password=123456
erp_passport.writers = 127.0.0.1:3306
erp_passport.readers = 127.0.0.1:3306
erp_assist.dbname = erp_assist
erp_assist.username = root
erp_assist.password=123456
erp_assist.writers = 127.0.0.1:3306
erp_assist.readers = 127.0.0.1:3306
erp_storehouse.dbname = erp_storehouse
erp_storehouse.username = root
erp_storehouse.password=123456
erp_storehouse.writers = 127.0.0.1:3306
erp_storehouse.readers = 127.0.0.1:3306
erp_finance.dbname = erp_finance
erp_finance.username = root
erp_finance.password=123456
erp_finance.writers = 127.0.0.1:3306
erp_finance.readers = 127.0.0.1:3306
erp_logistics.dbname = erp_logistics
erp_logistics.username = root
erp_logistics.password=123456
erp_logistics.writers = 127.0.0.1:3306
erp_logistics.readers = 127.0.0.1:3306
erp_supplier.username=root
erp_supplier.password=123456
erp_supplier.writers=127.0.0.1:3306
erp_supplier.readers=127.0.0.1:3306
erp_storage.username=root
erp_storage.password=123456
erp_storage.writers=127.0.0.1:3306
erp_storage.readers=127.0.0.1:3306
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
yh_shops.username = root
yh_shops.password=123456
yh_shops.writers = 127.0.0.1:3306
yh_shops.readers = 127.0.0.1:3306
yh_orders.username = root
yh_orders.password=123456
yh_orders.writers = 127.0.0.1:3306
yh_orders.readers = 127.0.0.1:3306
yh_lottery.username = root
yh_lottery.password=123456
yh_lottery.writers = 127.0.0.1:3306
yh_lottery.readers = 127.0.0.1:3306
yhb_promotion.username = root
yhb_promotion.password=123456
yhb_promotion.writers = 127.0.0.1:3306
yhb_promotion.readers = 127.0.0.1:3306
yoho_passport.username = root
yoho_passport.password=123456
yoho_passport.writers = 127.0.0.1:3306
yoho_passport.readers = 127.0.0.1:3306
yh_logistics.username = root
yh_logistics.password=123456
yh_logistics.writers = 127.0.0.1:3306
yh_logistics.readers = 127.0.0.1:3306
erp_product.username = root
erp_product.password=123456
erp_product.writers = 127.0.0.1:3306
erp_product.readers = 127.0.0.1:3306
yh_cms.username = root
yh_cms.password=123456
yh_cms.writers = 127.0.0.1:3306
yh_cms.readers = 127.0.0.1:3306
yh_unions.username = root
yh_unions.password=123456
yh_unions.writers = 127.0.0.1:3306
yh_unions.readers = 127.0.0.1:3306
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
sx_admin.username = root
sx_admin.password=123456
sx_admin.writers = 127.0.0.1:3306
sx_admin.readers = 127.0.0.1:3306
sx_passport.username = root
sx_passport.password=123456
sx_passport.writers = 127.0.0.1:3306
sx_passport.readers = 127.0.0.1:3306
sx_assist.dbname = erp_assist
sx_assist.username = root
sx_assist.password=123456
sx_assist.writers = 127.0.0.1:3306
sx_assist.readers = 127.0.0.1:3306
sx_operations.username = root
sx_operations.password=123456
sx_operations.writers = 127.0.0.1:3306
sx_operations.readers = 127.0.0.1:3306
sx_goods.username = root
sx_goods.password=123456
sx_goods.writers = 127.0.0.1:3306
sx_goods.readers = 127.0.0.1:3306
xungou.username = root
xungou.password=123456
xungou.writers = 127.0.0.1:3306
xungou.readers = 127.0.0.1:3306
erp_supplier.username = root
erp_supplier.password=123456
erp_supplier.writers = 127.0.0.1:3306
erp_supplier.readers = 127.0.0.1:3306
sx_gather.username = root
sx_gather.password=123456
sx_gather.writers = 127.0.0.1:3306
sx_gather.readers = 127.0.0.1:3306
erp_logistics.username = root
erp_logistics.password=123456
erp_logistics.writers = 127.0.0.1:3306
erp_logistics.readers = 127.0.0.1:3306
erp_storehouse.username = root
erp_storehouse.password=123456
erp_storehouse.writers = 127.0.0.1:3306
erp_storehouse.readers = 127.0.0.1:3306
erp_workorder.username=root
erp_workorder.password=123456
erp_workorder.writers=127.0.0.1:3306
erp_workorder.readers=127.0.0.1:3306
yh_orders.username = root
yh_orders.password=123456
yh_orders.writers = 127.0.0.1:3306
yh_orders.readers = 127.0.0.1:3306
yh_operations.username=root
yh_operations.password=123456
yh_operations.writers=127.0.0.1:3306
yh_operations.readers=127.0.0.1:3306
yh_passport.username = root
yh_passport.password=123456
yh_passport.writers = 127.0.0.1:3306
yh_passport.readers = 127.0.0.1:3306
yh_coupons.username = root
yh_coupons.password=123456
yh_coupons.writers = 127.0.0.1:3306
yh_coupons.readers = 127.0.0.1:3306
yh_subscribe.username=root
yh_subscribe.password=123456
yh_subscribe.writers=127.0.0.1:3306
yh_subscribe.readers=127.0.0.1:3306
yh_message.username=root
yh_message.password=123456
yh_message.writers=127.0.0.1:3306
yh_message.readers=127.0.0.1:3306
yh_setting.username = root
yh_setting.password=123456
yh_setting.writers = 127.0.0.1:3306
yh_setting.readers = 127.0.0.1:3306
[postgres]
yh_operations.username=root
yh_operations.password=123456
yh_operations.writers=127.0.0.1:3306
yh_operations.readers=127.0.0.1:3306
... ...
[mysql]
yh_system.username = erp_root
yh_system.password = erp_root
yh_system.writers = 192.168.200.204:3306
yh_system.readers = 192.168.200.204:3306
erp_admin.username = erp_root
erp_admin.password = erp_root
erp_admin.writers = 192.168.200.204:3306
erp_admin.readers = 192.168.200.204:3306
erp_orders.username = erp_root
erp_orders.password = erp_root
erp_orders.writers = 192.168.200.204:3306
erp_orders.readers = 192.168.200.204:3306
erp_order_logs.username = erp_root
erp_order_logs.password = erp_root
erp_order_logs.writers = 192.168.200.204:3306
erp_order_logs.readers = 192.168.200.204:3306
erp_passport.username = erp_root
erp_passport.password=erp_root
erp_passport.writers = 192.168.200.204:3306
erp_passport.readers = 192.168.200.204:3306
erp_stockcheck.username = erp_root
erp_stockcheck.password = erp_root
erp_stockcheck.writers = 192.168.200.204:3306
erp_stockcheck.readers = 192.168.200.204:3306
yh_logistics.username=yh_orders
yh_logistics.password=yh_ordersQAZwsx1234
yh_logistics.writers=192.168.100.213:3306
yh_logistics.readers=192.168.100.213:3306,192.168.100.214:3306
erp_assist.dbname = erp_assist
erp_assist.username = erp_root
erp_assist.password = erp_root
erp_assist.writers = 192.168.200.204:3306
erp_assist.readers = 192.168.200.204:3306
erp_storage.username=erp_root
erp_storage.password=erp_root
erp_storage.writers=192.168.200.204:3306
erp_storage.readers=192.168.200.204:3306
erp_finance.username=erp_root
erp_finance.password=erp_root
erp_finance.writers=192.168.200.204:3306
erp_finance.readers=192.168.200.204:3306
erp_logistics.username=erp_root
erp_logistics.password=erp_root
erp_logistics.writers=192.168.200.204:3306
erp_logistics.readers=192.168.200.204:3306
erp_product.username=erp_root
erp_product.password=erp_root
erp_product.writers=192.168.200.204:3306
erp_product.readers=192.168.200.204:3306
erp_storehouse.username=erp_root
erp_storehouse.password=erp_root
erp_storehouse.writers=192.168.200.204:3306
erp_storehouse.readers=192.168.200.204:3306
erp_supplier.username=erp_root
erp_supplier.password=erp_root
erp_supplier.writers=192.168.200.204:3306
erp_supplier.readers=192.168.200.204:3306
erp_crm.username=erp_crm
erp_crm.password=erp_crmQAZwsx1234
erp_crm.writers=192.168.200.204:3306
erp_crm.readers=192.168.200.204:3306
erp_workorder.username=erp_workorder
erp_workorder.password=erp_workorderQAZwsx1234
erp_workorder.writers=192.168.200.204:3306
erp_workorder.readers=192.168.200.204:3306
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
yh_channel.username=yoho_passport
yh_channel.password=yoho_passportQAZwsx1234
yh_channel.writers=192.168.100.211:3306
yh_channel.readers=192.168.100.212:3306,192.168.100.211:3306
yhb_promotion.username = yh_orders
yhb_promotion.password = yh_ordersQAZwsx1234
yhb_promotion.writers = 192.168.100.213:3306
yhb_promotion.readers = 192.168.100.213:3306,192.168.100.214:3306
yh_shops.username=yh_shops
yh_shops.password=yh_shopsQAZwsx1234
yh_shops.writers=192.168.100.215:3306
yh_shops.readers=192.168.100.215:3306,192.168.100.216:3306
yh_orders.username=yh_orders
yh_orders.password=yh_ordersQAZwsx1234
yh_orders.writers=192.168.100.213:3306
yh_orders.readers=192.168.100.213:3306
yoho_passport.username=yoho_passport
yoho_passport.password=yoho_passportQAZwsx1234
yoho_passport.writers=192.168.100.211:3306
yoho_passport.readers=192.168.100.212:3306,192.168.100.211:3306
yh_operations.username=yh_cms
yh_operations.password=yh_cmsQAZwsx1234
yh_operations.writers=192.168.100.203:3306
yh_operations.readers=192.168.100.203:3306,192.168.100.204:3306
yh_cms.username=yh_cms
yh_cms.password=yh_cmsQAZwsx1234
yh_cms.writers=192.168.100.203:3306
yh_cms.readers=192.168.100.203:3306,192.168.100.204:3306
yh_wechat.username=yh_cms
yh_wechat.password=yh_cmsQAZwsx1234
yh_wechat.writers=192.168.100.203:3306
yh_wechat.readers=192.168.100.203:3306,192.168.100.204:3306
yh_passport.username=yoho_passport
yh_passport.password=yoho_passportQAZwsx1234
yh_passport.writers=192.168.100.211:3306
yh_passport.readers=192.168.100.212:3306,192.168.100.211:3306
yh_inbox.username=yoho_passport
yh_inbox.password=yoho_passportQAZwsx1234
yh_inbox.writers=192.168.100.211:3306
yh_inbox.readers=192.168.100.212:3306,192.168.100.211:3306
yh_search.username = yh_cms
yh_search.password = yh_cmsQAZwsx1234
yh_search.writers = 192.168.100.203:3306
yh_search.readers = 192.168.100.203:3306,192.168.100.204:3306
yh_comment.username = yh_cms
yh_comment.password = yh_cmsQAZwsx1234
yh_comment.writers=192.168.100.203:3306
yh_comment.readers=192.168.100.203:3306,192.168.100.204:3306
yh_unions.username = yh_cms
yh_unions.password = yh_cmsQAZwsx1234
yh_unions.writers = 192.168.100.203:3306
yh_unions.readers = 192.168.100.203:3306,192.168.100.204:3306
yh_coupons.username = yh_orders
yh_coupons.password = yh_ordersQAZwsx1234
yh_coupons.writers = 192.168.100.213:3306
yh_coupons.readers = 192.168.100.213:3306,192.168.100.214:3306
yh_subscribe.username = yh_subscribe
yh_subscribe.password = yh_subscribeQAZwsx1234
yh_subscribe.writers = 192.168.100.203:3306
yh_subscribe.readers = 192.168.100.203:3306,192.168.100.204:3306
yoho_sms.username = yoho_passport
yoho_sms.password = yoho_passportQAZwsx1234
yoho_sms.writers = 192.168.100.211:3306
yoho_sms.readers = 192.168.100.211:3306,192.168.100.212:3306
yh_warns.username = yh_warns
yh_warns.password = yh_warnsQAZwsx1234
yh_warns.writers = 192.168.100.140:3306
yh_warns.readers = 192.168.100.140:3306
yh_message.username=yh_message
yh_message.password=yh_messageQAZwsx1234
yh_message.writers=192.168.100.140:3306
yh_message.readers=192.168.100.140:3306
erp_product206.username = reader
erp_product206.password = ^T0qI3D+x3ew
erp_product206.writers = 192.168.200.206:3308
erp_product206.readers = 192.168.200.206:3308
erp_product206.dbname = erp_product
erp_orders206.username = reader
erp_orders206.password = ^T0qI3D+x3ew
erp_orders206.writers = 192.168.200.206:3308
erp_orders206.readers = 192.168.200.206:3308
erp_orders206.dbname = erp_orders
q_pay.username=yh_orders
q_pay.password=yh_ordersQAZwsx1234
q_pay.writers=192.168.100.213:3306
q_pay.readers=192.168.100.213:3306,192.168.100.214:3306
yh_lottery.username=yh_cms
yh_lottery.password=yh_cmsQAZwsx1234
yh_lottery.writers=192.168.100.203:3306
yh_lottery.readers=192.168.100.204:3306,192.168.100.203:3306
yh_special.username = yh_cms
yh_special.password = yh_cmsQAZwsx1234
yh_special.writers=192.168.100.203:3306
yh_special.readers=192.168.100.203:3306,192.168.100.204:3306
q_msg_system.username=yoho_passport
q_msg_system.password=yoho_passportQAZwsx1234
q_msg_system.writers=192.168.100.211:3306
q_msg_system.readers=192.168.100.211:3306,192.168.100.212:3306
yh_comments.username=yh_cms
yh_comments.password=yh_cmsQAZwsx1234
yh_comments.writers=192.168.100.203:3306
yh_comments.readers=192.168.100.204:3306,192.168.100.203:3306
erp_query.username = erp_root
erp_query.password = erp_root
erp_query.writers = 192.168.200.204:3306
erp_query.readers = 192.168.200.204:3306
yh_setting.username = yh_cms
yh_setting.password = yh_cmsQAZwsx1234
yh_setting.writers = 192.168.100.203:3306
yh_setting.readers = 192.168.100.203:3306,192.168.100.204:3306
yh_events.username=yh_cms
yh_events.password=yh_cmsQAZwsx1234
yh_events.writers=192.168.100.203:3306
yh_events.readers=192.168.100.203:3306,192.168.100.204:3306
yoho_pay.username = yh_orders
yoho_pay.password = yh_ordersQAZwsx1234
yoho_pay.writers = 192.168.100.213:3306
yoho_pay.readers = 192.168.100.213:3306
yohood.username=yh_orders
yohood.password=yh_ordersQAZwsx1234
yohood.writers = 192.168.100.213:3306
yohood.readers = 192.168.100.213:3306
... ...
[mysql]
erp_admin.username = root
erp_admin.password = yoho
erp_admin.writers = 127.0.0.1:9980
erp_admin.readers = 127.0.0.1:9980
erp_orders.username = root
erp_orders.password = yoho
erp_orders.writers = 127.0.0.1:9980
erp_orders.readers = 127.0.0.1:9980
erp_order_stockcheck.username = root
erp_order_stockcheck.password = yoho
erp_order_stockcheck.writers = 127.0.0.1:9980
erp_order_stockcheck.readers = 127.0.0.1:9980
erp_passport.username = root
erp_passport.password = yoho
erp_passport.writers = 127.0.0.1:9980
erp_passport.readers = 127.0.0.1:9980
erp_assist.dbname = erp_assist
erp_assist.username = root
erp_assist.password = yoho
erp_assist.writers = 127.0.0.1:9980
erp_assist.readers = 127.0.0.1:9980
erp_storehouse.dbname = erp_storehouse
erp_storehouse.username = root
erp_storehouse.password = yoho
erp_storehouse.writers = 127.0.0.1:9980
erp_storehouse.readers = 127.0.0.1:9980
erp_finance.dbname = erp_finance
erp_finance.username = root
erp_finance.password = yoho
erp_finance.writers = 127.0.0.1:9980
erp_finance.readers = 127.0.0.1:9980
erp_logistics.dbname = erp_logistics
erp_logistics.username = root
erp_logistics.password = yoho
erp_logistics.writers = 127.0.0.1:9980
erp_logistics.readers = 127.0.0.1:9980
erp_supplier.username=root
erp_supplier.password=yoho
erp_supplier.writers=127.0.0.1:9980
erp_supplier.readers=127.0.0.1:9980
erp_product.username = root
erp_product.password = yoho
erp_product.writers = 127.0.0.1:9980
erp_product.readers = 127.0.0.1:9980
erp_storage.username=root
erp_storage.password=yoho
erp_storage.writers=127.0.0.1:9980
erp_storage.readers=127.0.0.1:9980
erp_sms.username=root
erp_sms.password=yoho
erp_sms.writers=127.0.0.1:9980
erp_sms.readers=127.0.0.1:9980
erp_crm.username = root
erp_crm.password=yoho
erp_crm.writers = 127.0.0.1:3306
erp_crm.readers = 127.0.0.1:3306
erp_workorder.username = root
erp_workorder.password=yoho
erp_workorder.writers = 127.0.0.1:9980
erp_workorder.readers = 127.0.0.1:9980
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
yh_shops.username = root
yh_shops.password = yoho
yh_shops.writers = 127.0.0.1:9980
yh_shops.readers = 127.0.0.1:9980
yh_channel.username = root
yh_channel.password = yoho
yh_channel.writers = 127.0.0.1:9980
yh_channel.readers = 127.0.0.1:9980
yoho_passport.username = root
yoho_passport.password = yoho
yoho_passport.writers = 127.0.0.1:9980
yoho_passport.readers = 127.0.0.1:9980
yhb_promotion.username = root
yhb_promotion.password = yoho
yhb_promotion.writers = 127.0.0.1:9980
yhb_promotion.readers = 127.0.0.1:9980
yh_orders.username = root
yh_orders.password = yoho
yh_orders.writers = 127.0.0.1:9980
yh_orders.readers = 127.0.0.1:9980
yh_passport.username = root
yh_passport.password = yoho
yh_passport.writers = 127.0.0.1:9980
yh_passport.readers = 127.0.0.1:9980
yh_inbox.username = root
yh_inbox.password = yoho
yh_inbox.writers = 127.0.0.1:9980
yh_inbox.readers = 127.0.0.1:9980
yh_operations.username = root
yh_operations.password = yoho
yh_operations.writers = 127.0.0.1:9980
yh_operations.readers = 127.0.0.1:9980
yh_cms.username = root
yh_cms.password = yoho
yh_cms.writers = 127.0.0.1:9980
yh_cms.readers = 127.0.0.1:9980
yh_search.username = root
yh_search.password = yoho
yh_search.writers = 127.0.0.1:9980
yh_search.readers = 127.0.0.1:9980
yh_unions.username = yh_test
yh_unions.password = yh_test
yh_unions.writers = 127.0.0.1:9980
yh_unions.readers = 127.0.0.1:9980
yh_coupons.username = yh_test
yh_coupons.password = yh_test
yh_coupons.writers = 127.0.0.1:9980
yh_coupons.readers = 127.0.0.1:9980
erp_order_logs.username = root
erp_order_logs.password = yoho
erp_order_logs.writers = 127.0.0.1:9980
erp_order_logs.readers = 127.0.0.1:9980
yh_warns.username = root
yh_warns.password = yoho
yh_warns.writers = 127.0.0.1:9980
yh_warns.readers = 127.0.0.1:9980
yh_message.username=root
yh_message.password=yoho
yh_message.writers=127.0.0.1:9980
yh_message.readers=127.0.0.1:9980
yh_comments.username=root
yh_comments.password=yoho
yh_comments.writers=127.0.0.1:9980
yh_comments.readers=127.0.0.1:9980
erp_orders206.username = root
erp_orders206.password = yoho
erp_orders206.writers = 127.0.0.1:9980
erp_orders206.readers = 127.0.0.1:9980
erp_orders206.dbname = erp_orders
yoho_sms.username = root
yoho_sms.password = yoho
yoho_sms.writers = 127.0.0.1:9980
yoho_sms.readers = 127.0.0.1:9980
q_pay.username=yh_test
q_pay.password=yh_test
q_pay.writers=127.0.0.1:9980
q_pay.readers=127.0.0.1:9980
yh_setting.username = root
yh_setting.password = yoho
yh_setting.writers = 127.0.0.1:9980
yh_setting.readers = 127.0.0.1:9980
yoho_pay.username = root
yoho_pay.password = yoho
yoho_pay.writers = 127.0.0.1:9980
yoho_pay.readers = 127.0.0.1:9980
yh_logistics.username = root
yh_logistics.password = yoho
yh_logistics.writers = 127.0.0.1:9980
yh_logistics.readers = 127.0.0.1:9980
q_msg_system.username=root
q_msg_system.password=yoho
q_msg_system.writers=127.0.0.1:9980
q_msg_system.readers=127.0.0.1:9980
yh_shopping_cart.username = root
yh_shopping_cart.password=yoho
yh_shopping_cart.writers = 127.0.0.1:9980
yh_shopping_cart.readers = 127.0.0.1:9980
\ No newline at end of file
... ...
[job]
server.proxys=127.0.0.1:4730
[worker]
server.proxys=127.0.0.1:7003,192.168.10.130:7003
\ No newline at end of file
... ...
[job]
server.proxys=127.0.0.1:4730,192.168.10.130:4730
[worker]
server.proxys=127.0.0.1:7003,192.168.10.130:7003
\ No newline at end of file
... ...
[job]
server.proxys=127.0.0.1:4730,192.168.10.130:4730
[worker]
server.proxys=127.0.0.1:7003,192.168.10.130:7003
\ No newline at end of file
... ...
[amqp]
message.host = 127.0.0.1
message.port = 5672
message.login = yhm.im
message.password = f2c302d166fc98e4abf92d7b49e206a2
\ No newline at end of file
... ...
[amqp]
message.proxys = 127.0.0.1:5672
\ No newline at end of file
... ...
[amqp]
message.proxys = 127.0.0.1:5672
\ No newline at end of file
... ...
[mongo]
;erp.username =
;erp.password =
;erp.timeout = 400
;erp.auth = true
erp.proxys = 127.0.0.1:27017
loggers.proxys = 127.0.0.1:27017
apiopenlogs.proxys = 127.0.0.1:27017
\ No newline at end of file
... ...
[mongo]
;erp.username =
;erp.password =
;erp.timeout = 400
;erp.auth = true
erp.proxys = 192.168.200.206:27017
loggers.proxys = 192.168.200.206:27017
apiopenlogs.proxys = 192.168.200.206:27017
analytics.proxys = 192.168.100.145:27017,192.168.100.146:27017
inbox.proxys = 192.168.100.145:27017,192.168.100.146:27017
\ No newline at end of file
... ...
[mongo]
;erp.username =
;erp.password =
;erp.timeout = 400
;erp.auth = true
erp.proxys = 127.0.0.1:27017
loggers.proxys = 127.0.0.1:27017
apiopenlogs.proxys = 127.0.0.1:27017
inbox.proxys=127.0.0.1:27017
... ...
[sphinx]
servers.proxys = 127.0.0.1:9312
[words]
servers.proxys = 127.0.0.1:1985
[solr]
servers.proxys = 192.168.40.131:8080
\ No newline at end of file
... ...
[sphinx]
servers.proxys = 192.168.100.44:9311,192.168.100.44:9310,192.168.100.9:9311,192.168.100.9:9310
[words]
servers.proxys = 192.168.100.130:1985,192.168.100.122:1985
\ No newline at end of file
... ...
[sphinx]
servers.proxys = 127.0.0.1:9312
[words]
servers.proxys = 127.0.0.1:1985
\ No newline at end of file
... ...
[sms]
chufa.service = http://cf.lmobile.cn/submitdata/service.asmx?wsdl
chufa.sname = dlyoho00
chufa.spwd = 12345678
chufa.scorpid =
chufa.sprdid = 1012818
[phone]
dev.phone = 15811225238
\ No newline at end of file
... ...
[sms]
chufa.service = http://cf.lmobile.cn/submitdata/service.asmx?wsdl
chufa.sname = dlyoho00
chufa.spwd = 12345678
chufa.scorpid =
chufa.sprdid = 1012818
[phone]
dev.phone = 15811225238
\ No newline at end of file
... ...
[sms]
chufa.service = http://cf.lmobile.cn/submitdata/service.asmx?wsdl
chufa.sname = dlyoho00
chufa.spwd = 12345678
chufa.scorpid =
chufa.sprdid = 1012818
[phone]
dev.phone = 15811225238
\ No newline at end of file
... ...
<?php
class Q_Action extends Yaf_Controller_Abstract
{
private $_headlink;
private $_headscript;
private $_headTitle;
private $_headmeta;
private $_qdebug;
private $_qdebugMicrotime;
/**
* Meta
* @return Q_View_Header_Meta
*/
public function _headMeta()
{
if (empty($this->_headmeta)) {
$this->_headmeta = new Q_View_Header_Meta();
$this->getView()->assign("_headmeta", $this->_headmeta);
}
return $this->_headmeta;
}
/**
* Script
* @return Q_View_Header_Script
*/
public function _headScript()
{
if (empty($this->_headscript)) {
$this->_headscript = new Q_View_Header_Script();
$this->getView()->assign("_headScript", $this->_headscript);
}
return $this->_headscript;
}
/**
*
* @return Q_View_Header_Link
*/
public function _headLink()
{
if (empty($this->_headlink)) {
$this->_headlink = new Q_View_Header_Link();
$this->getView()->assign("_headLink", $this->_headlink);
}
return $this->_headlink;
}
/**
* Title
* @return Q_View_Header_Title
*/
public function _headTitle($title = null)
{
if (empty($this->_headTitle)) {
$this->_headTitle = new Q_View_Header_Title();
$this->getView()->assign("_headTitle", $this->_headTitle);
}
return $this->_headTitle->headTitle($title);
}
public function helpHeader($code = 200, $msg = '')
{
header("content-type: text/html; charset=utf-8");
$codeStr = "";
switch ($code) {
case 404 :
$codeStr = " 404 Not Found";
break;
case 403 :
$codeStr = " 403 Forbidden";
break;
case 500 :
$codeStr = " 500 Internal Server Error";
break;
default :
$codeStr = " 200 OK";
break;
}
header("HTTP/1.0" . $codeStr);
echo $msg;
}
/**
* js 跳转 并 提示
*
* @param String $url
* @param String $expression
*/
protected function helpJsRedirect($message = '', $expression = "history.back()")
{
header("content-type: text/html; charset=utf-8");
if ($message != "") {
$message = Q_Utils_String::format()->addslash($message);
$message = str_replace("\n", "\\n", $message);
echo "<script language=\"javascript\">";
echo "alert(\"{$message}\");";
echo "</script>";
}
if ($expression != "") {
echo "<script language=\"javascript\">\n";
echo $expression . "\n";
echo "</script>";
}
exit();
}
/**
* 跳转
*
* @param String $url
* @param String $message
*/
protected function helpGo($url, $message = '')
{
if (!empty($message)) {
header("content-type: text/html; charset=utf-8");
$message = Q_Utils_String::format()->addslash($message);
$message = str_replace("\n", "\\n", $message);
echo "<script language=\"javascript\">";
echo "alert(\"{$message}\");";
echo "</script>";
}
header('Location: ' . $url);
exit();
}
/**
* refresh跳转
*
* @param String $url
* @param String $message
* @param Integer $content
*/
protected function helpRefresh($url, $message = '', $content = 0, $show = false)
{
if (!empty($message)) {
header("content-type: text/html; charset=utf-8");
$message = Q_Utils_String::format()->addslash($message);
$message = str_replace("\n", "\\n", $message);
echo "<script language=\"javascript\">";
echo "alert(\"{$message}\");";
echo "</script>";
}
echo "<script language=\"javascript\">";
echo "window.location.href='{$url}';";
echo "</script>";
if ($show == false) {
exit();
}
}
/**
* JSON输出
*
* @param String $caption
* @param Integer $code
* @param mixed $content
*/
protected function helpJsonResult($code, $message = null, $data = null)
{
header('Content-type: application/json');
echo json_encode(Q_Utils_Function::result($code, $message, $data));
Yaf_Dispatcher::getInstance()->autoRender(FALSE);
exit();
}
/**
* JSON输出
*
* @param String $caption
* @param Integer $code
* @param mixed $content
*/
protected function helpJson($data = null)
{
header('Content-type: application/json');
echo json_encode($data);
Yaf_Dispatcher::getInstance()->autoRender(FALSE);
exit();
}
/**
* JSONP Callback输出,用于远程调用
*
* @param String $caption
* @param Integer $code
* @param mixed $content
*/
protected function helpJsonCallbackResult($callbackString, $code, $message = null, $data = null)
{
echo $callbackString . "(";
echo json_encode(Q_Utils_Function::result($code, $message, $data));
echo ")";
exit();
}
/**
* 转义', "
*
* @param string $string
* @return string
*/
protected function helpAddslashes($string)
{
return get_magic_quotes_gpc() ? $string : addslashes($string);
}
/**
* refresh跳转
*
* @param String $url
* @param String $message
* @param Integer $content
*/
protected function helpRefreshNotExit($url, $message = '', $content = 0)
{
if (!empty($message)) {
header("content-type: text/html; charset=utf-8");
$message = Q_Utils_String::format()->addslash($message);
$message = str_replace("\n", "\\n", $message);
echo "<script language=\"javascript\">";
echo "alert(\"{$message}\");";
echo "</script>";
}
echo "<meta http-equiv=\"refresh\" content=\"{$content};url={$url}\">";
}
private function _g($key, $default = '')
{
return $this->getRequest()->getQuery($key, $default);
}
public function _debugStart($debug = 'xhprof')
{
if ($this->_g('_qdebug') == 'action') {
$this->_qdebugMicrotime = microtime(true);
$this->_qdebug = new Q_Debug_Xhprof_Stat();
$this->_qdebug->setUrl('http://xhprof.debug.yohobuy.com')->start();
}
}
public function _debugEnd()
{
if ($this->_g('_qdebug') == 'action') {
$this->_qdebug->end();
echo '<br /> Action Time : ' . (microtime(true) - $this->_qdebugMicrotime) . '<br />';
}
}
/**
* 开启session
*/
public function sessionStart()
{
$sessionID = session_id();
if (empty($sessionID)) {
$qinSession = new Q_Core_Session();
session_set_save_handler(
array(&$qinSession, "open"),
array(&$qinSession, "close"),
array(&$qinSession, "read"),
array(&$qinSession, "write"),
array(&$qinSession, "destroy"),
array(&$qinSession, "gc")
);
session_start();
}
}
}
\ No newline at end of file
... ...
<?php
/**
* Created by PhpStorm.
* User: liuziyang
* Date: 13-12-31
* Time: 7:12
*/
namespace Q;
class Q_Autoloader
{
public function __construct()
{
spl_autoload_register(array($this, 'register'));
}
private function register($className)
{
if (stristr($className, '\\') === FALSE) {
$classNamePath = str_replace('_', DIRECTORY_SEPARATOR, $className) . '.php';
} else {
$parts = explode('\\', $className);
$classNamePath = implode(DIRECTORY_SEPARATOR, $parts) . '.php';
}
$includePath = explode(':', get_include_path());
foreach ($includePath as $path) {
$classPath = $path . DIRECTORY_SEPARATOR . $classNamePath;
if (file_exists($classPath)) {
//Yaf_Loader::import($classPath);
require_once($classPath);
return;
}
}
}
public function tree($directory)
{
$mydir = dir($directory);
while ($file = $mydir->read()) {
if ((is_dir($directory . DIRECTORY_SEPARATOR . $file)) AND ($file != ".") AND ($file != "..")) {
$this->tree("$directory/$file");
} elseif ($file != "." AND $file != "..") {
echo $directory . DIRECTORY_SEPARATOR . $file;
}
}
$mydir->close();
}
public static function loader()
{
new Q_Autoloader();
}
}
Q_Autoloader::loader();
\ No newline at end of file
... ...
<?php
class Q_Cache
{
private static $_cache;
/**
* @var array
*/
private static $options = array(
'mode' => Q_Server_Core::SERVER_MODE_PROXY,
'select' => Q_Server_Core::SERVER_SELECT_MODE_STATIC
);
/**
* @static
* @param string $driver
* @param array $options
* @param string $node
* @return mixed
* @throws Q_Exception
*/
public static function factory($driver = 'Memcached', array $options = array(), $nodeName = 'servers')
{
$driver = ucfirst($driver);
$className = 'Q_Cache_' . $driver;
if (!class_exists($className)) {
throw new Q_Exception(' Cache Not ' . $className);
}
$options = array_merge(self::$options, $options);
$servers = Q_Server::factory('cache', strtolower($driver), $nodeName, $options);
$persistentID = empty($options['persistent_id']) ? '' : $options['persistent_id'];
return new $className($servers, $persistentID);
}
}
\ No newline at end of file
... ...
<?php
abstract class Q_Cache_Abstract implements Q_Cache_Interface
{
/**
*
* 域 & 前缀
* @var String
*/
protected $domain = 'qf.domain';
/**
* 接点
*
* @var String
*/
protected $class = 'default';
/**
* Server List
*
* @var Array
*/
protected $servers = array();
/**
* 前缀
* @var string
*/
protected $keyPrefix = '';
/**
* Tag
* @var string
*/
protected $tagName = '';
/**
* Memcached Obj
*
* @var Memcached
*/
protected $_cache;
/**
*
* tag 前缀
* @return String
*/
protected function getTagPrefix($rw_mode = false)
{
if (empty($this->tagName)) {
return '';
}
$key = $this->tagKey($this->tagName);
$_tag_val = $this->_cache->get($key);
if (empty($_tag_val) && $rw_mode == true) {
$_tag_val = md5(microtime() . mt_rand() . uniqid());
$this->_cache->set($key, $_tag_val, 0);
}
return empty($_tag_val) ? '' : $_tag_val . '.';
}
/**
*
* Tag key
* @param String $tagName
* @return String
*/
protected function tagKey($tagName)
{
return 'cache.tag.' . md5($tagName);
}
/**
* 初始化数据
*/
protected function _unset()
{
$this->tagName = '';
$this->domain = 'qf.domain';
$this->class = 'default';
$this->keyPrefix = '';
}
}
\ No newline at end of file
... ...
<?php
/**
* 后端缓存
*
* example:
* <pre>
*
* </pre>
*
* @name Q_Cache_Backend
* @version $index ( 2011-9-12 上午12:27:24 )
* @package Q.Cache.Backend
* @author liuziyang peter.zyliu@gmail.com
* @since 1.0 2011
*/
class Q_Cache_Backend
{
/**
* 判断是否开启了apc.enabled选项
*
* 用来取代 isEnabed
*
* @return boolean
* @since 0.2.1
*/
public static function isEnabled()
{
return (bool)ini_get("apc.enabled");
}
/**
*
* 获取缓存
* @param String $key
* @return boolean
*/
static public function load($key)
{
return apc_fetch($key);
}
/**
*
* 存入缓存
* @param String $key
* @param Mixed $value
* @param Integer $expire
* @return boolean
*/
static public function save($key, $value, $expire = 7200)
{
return apc_store($key, $value, $expire);
}
/**
*
* 清除
* @param String $key
* @return boolean
*/
static public function remove($key)
{
return apc_delete($key);
}
/**
* 缓存文件
* @static
* @param $fileName
* @return bool
*/
static public function compileFile($fileName, $atomic = true)
{
return apc_compile_file($fileName, $atomic);
}
/**
* 删除缓存文件
* @static
* @param $fileName
* @return bool|string[]
*/
static public function deleteFile($fileName)
{
return apc_delete_file($fileName);
}
/**
* 添加一个缓存
* @static
* @param $key
* @param $var
* @param $ttl
* @return bool
*/
static public function add($key, $var, $ttl = 0)
{
return apc_add($key, $var, $ttl);
}
/**
* 将数据转成二进制文件存储
* @static
* @param array $files
* @param array $user_vars
* @return bool|null|string
*/
static public function binDump(array $files, array $user_vars)
{
return apc_bin_dump($files, $user_vars);
}
/**
* 载入文件转成二进制文件存储
* @static
* @param array $files
* @param array $user_vars
* @param $filename
* @param $context
* @param int $flags
* @return bool|int
*/
static public function binDumpFile(array $files, array $user_vars, $filename, $context, $flags = 0)
{
return apc_bin_dumpfile($files, $user_vars, $filename, $flags, $context);
}
/**
* 加载二级制数据
* @static
* @param $data
* @param $flags
* @return bool APC_BIN_VERIFY_MD5 | APC_BIN_VERIFY_CRC32
*/
static public function binLoad($data, $flags)
{
return apc_bin_load($data, $flags);
}
/**
* 加载二级制文件
* @static
* @param $filename
* @param $context
* @param $flags
* @return bool APC_BIN_VERIFY_CRC32 | APC_BIN_VERIFY_MD5
*/
static public function binLoadFile($filename, $context, $flags)
{
return apc_bin_loadfile($filename, $context, $flags);
}
static public function cas($key, $old, $new)
{
return apc_cas($key, $old, $new);
}
static public function dec($key, &$success, $step = 1)
{
return apc_dec($key, $step, $success);
}
static public function define($key, array $constants, $case_sensitive = true)
{
return apc_define_constants($key, $constants, $case_sensitive);
}
/**
* 检查APC中是否存在某个或者某些key
* @static
* @param $keys
* @return bool|string[]
*/
static public function exists($keys)
{
return apc_exists($keys);
}
static public function inc($key, &$success, $step = 1)
{
return apc_inc($key, $step, $success);
}
static public function loadConstants($key, $case_sensitive = true)
{
return apc_load_constants($key, $case_sensitive);
}
}
\ No newline at end of file
... ...
<?php
class Q_Cache_Exception extends Q_Exception {
}
\ No newline at end of file
... ...
<?php
interface Q_Cache_Interface {
public function tag($tagName);
}
\ No newline at end of file
... ...
<?php
class Q_Cache_Memcached extends Q_Cache_Abstract
{
public function __construct(array $servers, $persistentID = '')
{
if (empty($servers)) {
throw new Q_Cache_Exception(__CLASS__ . ' : Servers Is Null');
}
$this->_unset();
$prefix = $this->_prefix();
$this->servers = $servers;
#初始化memcached
$this->initCache($persistentID);
$this->setPrefix($prefix);
}
private function initCache($persistentID = '')
{
if (empty($this->_cache)) {
$this->_cache = new Memcached($persistentID);
if (count($this->_cache->getServerList()) < 1) {
$this->_cache->addServers($this->servers);
$this->_cache->setOption(Memcached::OPT_CONNECT_TIMEOUT, 150); //在非阻塞模式下这里设置的值就是socket连接的超时时间
}
}
return $this->_cache;
}
/**
* 获取系统前缀
* @return string
*/
public function _prefix()
{
return $this->domain . '.' . $this->class;
}
/**
* 设置域
* @param String $domin
* @return Q_Cache_Memcached
*/
public function setDomin($domin)
{
$this->domain = $domin;
$this->setPrefix($this->_prefix());
return $this;
}
/**
* 设置class
* @param String $class
* @return Q_Cache_Memcached
*/
public function setClass($class)
{
$this->class = $class;
$this->setPrefix($this->_prefix());
return $this;
}
/**
* 设置Tag
* @param String $tagName
* @return Q_Cache_Memcached
*/
public function tag($tagName)
{
assert(!empty($tagName) || is_string($tagName));
$this->tagName = $tagName;
return $this;
}
/**
* 设置前缀
* @param String $prefix
* @return Q_Cache_Memcached
*/
public function setPrefix($prefix)
{
assert(is_string($prefix));
$this->initCache()->setOption(Memcached::OPT_PREFIX_KEY, $prefix . '.');
return $this;
}
/**
*
* 删除Tag
* @param String $tagName
* @param Integer $delay
* @return Bool
*/
public function deleteTag($tagName, $delay = 0)
{
assert(!empty($tagName));
$_tagName = $tagName;
if (!is_array($tagName)) {
$_tagName = array($tagName);
}
$results = array();
foreach ($_tagName as $val) {
$this->tagName = $val;
$results[$val] = $this->initCache()->delete($this->tagKey($val), $delay);
}
$this->_unset();
return is_array($tagName) ? $results : $results[$tagName];
}
/**
*
* 设置MC选择
* @param String $option
* @param integer $value
* @return Q_Cache_Memcached
*/
public function setOption($option, $value)
{
$this->initCache()->setOption($option, $value);
return $this;
}
/**
*
* 向一个新的key下面增加一个元素
* @param String $key
* @param String $value
* @param Integer $expiration
*/
public function add($key, $value, $expiration = 0)
{
assert(is_string($key));
$results = $this->initCache()->add($this->getTagPrefix(true) . md5($key), $value, (int)$expiration);
$this->_unset();
return $results;
}
/**
*
* 在指定服务器上的一个新的key下增加一个元素
* @param String $server
* @param String $key
* @param Mixed $value
* @param Integer $expiration
* @return bool
*/
public function addByKey($server, $key, $value, $expiration = 0)
{
assert(is_string($server)) && assert(is_string($key));
return $this->initCache()->addByKey($server, $this->getTagPrefix() . md5($key), $value, $expiration);
}
/**
*
* 向服务器池中增加一个服务器
* @param String $host
* @param Intger $port
* @param Integer $weight
* @return bool
*/
public function addServer($host, $port = 11211, $weight)
{
assert(is_string($host));
return $this->initCache()->addServer((string)$host, (int)$port, (int)$weight);
}
/**
*
* 向服务器池中增加多台服务器
* @param array $servers
*/
public function addServers(array $servers)
{
assert(!empty($servers));
return $this->initCache()->addServers($servers);
}
/**
*
* 向已存在元素后追加数据
* @param String $key
* @param Mixed $val
* @throws Q_Cache_Exception
* @return bool
*/
public function append($key, $val)
{
$compression = $this->getOption(Memcached::OPT_COMPRESSION);
if ($compression == true) {
throw new Q_Cache_Exception(' 当前memcached是压缩模式,不能使用追加功能. ');
}
return $this->initCache()->append($this->getTagPrefix() . md5($key), $val);
}
/**
*
* 向指定服务器上已存在元素后追加数据
* @param String $server
* @param String $key
* @param Mixed $val
* @return bool
*/
public function appendByKey($server, $key, $val)
{
assert(is_string($server)) && assert(is_string($key));
return $this->initCache()->appendByKey($server, $this->getTagPrefix() . md5($key), $val);
}
/**
*
* 减小数值元素的值
* @param String $key
* @param Integer $offset
* @return bool
*/
public function decrement($key, $offset = 1)
{
assert(is_string($key)) && assert(is_int($offset));
return $this->initCache()->decrement($this->getTagPrefix() . md5($key), $offset);
}
/**
*
* 删除一个元素
* @param String $key
* @param Integer $time
* @return bool
*/
public function delete($key, $time = 0)
{
assert(is_string($key)) && assert(is_int($time));
return $this->initCache()->delete($this->getTagPrefix() . md5($key), $time);
}
/**
*
* 抓取下一个结果
* @throws Q_Cache_Exception
*/
public function fetch()
{
return $this->initCache()->fetch();
}
/**
*
* 抓取所有剩余的结果
* @return array
*/
public function fetchAll()
{
return $this->initCache()->fetchAll();
}
/**
*
* 作废缓存中的所有元素
* @param Integer $delay
* @return bool
*/
public function flush($delay = 0)
{
assert(is_int($delay));
return $this->initCache()->flush($delay);
}
/**
*
* 检索一个元素
* @param String $key
* @param null $callback
* @return Mixed
*/
public function get($key, $callback = NULL)
{
assert(is_string($key));
$returns = $this->initCache()->get($this->getTagPrefix() . md5($key), $callback);
$this->_unset();
return $returns;
}
/**
*
* 向Memcached服务端发出一个检索keys指定的多个key对应元素的请求。这个方法不会等待响应而是立即返回
* @param array $keys
* @param bool $with_cas
* @param String || NULL $callback
* @return Q_Cache_Memcached
*/
public function getDelayed(array $keys, $with_cas = true, $callback = NULL)
{
assert(!empty($keys));
$_keyPrefix = array_fill(0, count($keys), $this->getTagPrefix());
$realKey = array_map(array($this, '_realKey'), $_keyPrefix, $keys);
$this->initCache()->getDelayed($realKey, $with_cas, $callback);
return $this;
}
/**
*
* 检索多个元素
* @param array $keys
* @param null $cas_tokens
* @param Integer $flags
* @return array
*/
public function getMulti(array $keys, &$cas_tokens = NULL, $flags = Memcached::GET_PRESERVE_ORDER)
{
assert(!empty($keys));
$_keyPrefix = array_fill(0, count($keys), $this->getTagPrefix());
$realKey = array_map(array($this, '_realKey'), $_keyPrefix, $keys);
$_mc_returns = $this->initCache()->getMulti($realKey, $cas_tokens, $flags);
if (empty($_mc_returns)) {
return $_mc_returns;
}
$_keyList = array_combine($realKey, $keys);
$returns = array();
foreach ($_mc_returns as $key => $val) {
empty($_keyList[$key]) ? false : $returns[$_keyList[$key]] = $val;
}
return $returns;
}
/**
*
* 组织数据
* @param String $keyPrefix
* @param String $key
* @return String
*/
private function _realKey($keyPrefix, $key)
{
return empty($keyPrefix) ? md5($key) : $keyPrefix . md5($key);
}
/**
*
* 获取Memcached的选项值
* @param Integer $option
* @return bool
*/
public function getOption($option)
{
return $this->initCache()->getOption($option);
}
/**
*
* 返回最后一次操作的结果代码
* @return string
*/
public function getResultCode()
{
return $this->initCache()->getResultCode();
}
/**
*
* 返回最后一次操作的结果描述消息
* @return String
*/
public function getResultMessage()
{
return $this->initCache()->getResultMessage();
}
/**
* 获取一个key所映射的服务器信息
* @param String $server_key
* @return array
*/
public function getServerByKey($server_key)
{
$compatible = $this->initCache()->getOption(Memcached::OPT_LIBKETAMA_COMPATIBLE);
$compatible == false ? $this->initCache()->setOption(Memcached::OPT_LIBKETAMA_COMPATIBLE, true) : true;
return $this->initCache()->getServerByKey($server_key);
}
/**
*
* 获取服务器池中的服务器列表
* @return array
*/
public function getServerList()
{
return $this->initCache()->getServerList();
}
/**
*
* 获取服务器池的统计信息
* @return array
*/
public function getStats()
{
return $this->initCache()->getStats();
}
/**
*
* 增加数值元素的值
* @param String $key
* @param Integer $offset
* @return bool
*/
public function increment($key, $offset = 1)
{
assert(is_string($key)) && assert(is_int($offset));
return $this->initCache()->increment($this->getTagPrefix() . md5($key), $offset);
}
/**
*
* 向一个已存在的元素前面追加数据
* @param String $key
* @param Mixed $val
* @throws Q_Cache_Exception
*/
public function prepend($key, $val)
{
$compression = $this->getOption(Memcached::OPT_COMPRESSION);
if ($compression == true) {
throw new Q_Cache_Exception(' 当前memcached是压缩模式,不能使用追加功能. ');
}
return $this->initCache()->prepend($this->getTagPrefix() . md5($key), $val);
}
/**
*
* 替换已存在key下的元素
* @param String $key
* @param Mixed $value
* @param Integer $expiration
* @return bool
*/
public function replace($key, $value, $expiration = 0)
{
assert(is_string($key));
return $this->initCache()->replace($this->getTagPrefix() . md5($key), $value, $expiration);
}
/**
*
* 存储一个元素
* @param String $key
* @param Mixed $value
* @param Integer $expiration
* @return Mixed
*/
public function set($key, $value, $expiration = 0)
{
assert(is_string($key));
$results = $this->initCache()->set($this->getTagPrefix(true) . md5($key), $value, $expiration);
$this->_unset();
return $results;
}
/**
*
* 存储多个元素
* @param array $items
* @param Integer $expiration
* @return array
*/
public function setMulti(array $items, $expiration = 0)
{
assert(!empty($items));
$_prefix = $this->getTagPrefix(true);
$results = array();
foreach ($items as $key => $val) {
$results[$this->_realKey($_prefix, $key)] = $val;
}
return $this->initCache()->setMulti($results, $expiration);
}
/**
*
* 结束
*/
public function __destruct()
{
$this->_unset();
unset($this->_cache);
$this->servers = array();
}
}
... ...
<?php
class Q_Cache_Redis extends Q_Cache_Abstract
{
/**
*
* Enter description here ...
* @var Redis
*/
private $redis;
private $timeout = 2.5;
public function __construct(array $servers, $persistentID = '')
{
if (empty($servers)) {
throw new Q_Cache_Exception('redis server is null.');
}
$this->redis = new Redis();
$this->redis->connect($servers['host'], $servers['port'], $this->timeout);
}
/**
*
* 返回key所关联的字符串值,如果key不存在则返回特殊值nil。
* @param String $key
* @return Mixed or nil
*/
public function get($key)
{
assert(is_string($key));
return $this->redis->get($key);
}
/**
*
* 将字符串值value关联到key
* @param String $key
* @param Mixed $val
* @return bool
*/
public function set($key, $val)
{
assert(is_string($key));
return $this->redis->set($key, $val);
}
/**
*
* 同时设置一个或多个key-value对。
* @param array $keys
* @return bool
*/
public function mset(array $keys)
{
return $this->redis->mset($keys);
}
/**
*
* 返回所有(一个或多个)给定key的值.如果某个指定key不存在,那么返回特殊值nil。因此,该命令永不失败。
* @param array $keys
* @return Mixed
*/
public function mget(array $keys)
{
return $this->redis->mget($keys);
}
/**
*
* 返回key中字符串值的子字符串,字符串的截取范围由start和end两个偏移量决定(包括start和end在内)。
* 负数偏移量表示从字符串最后开始计数,-1表示最后一个字符,-2表示倒数第二个,以此类推
* @param String $key
* @param Integer $start
* @param Integer $end
* @return String
*/
public function getRange($key, $start, $end)
{
assert(is_string($key));
return $this->redis->getRange($key, $start, $end);
}
/**
*
* 删除数据 ( 返回删除个数 )
* @param String $key
* @return bool
*/
public function del($key)
{
assert(is_string($key));
return $this->redis->del($key);
}
/**
* 查找符合给定模式的key。
*
* 可以使用正则
* =========================================
* *命中数据库中所有key
* h?llo命中hello, hallo and hxllo等
* h*llo命中hllo和heeeeello等
* h[ae]llo命中hello和hallo,但不命中hillo
* =========================================
* KEYS的速度非常快,但在一个大的数据库中使用它仍然可能造成性能问题,如果你需要从一个数据集中查找特定的key,你最好还是用集合(set)结构。
* @param String $keys
* @return Mixed
*/
public function keys($keys)
{
return $this->redis->keys($keys);
}
/**
*
* 选择数据库
* @param String $db
* @return bool
*/
public function select($db = 9)
{
return $this->redis->select($db);
}
/**
*
* 获取 hash 集合中的键值
* @param String $hashName
* @param String $key
* @param Mixed $val
* @return Mixed
*/
public function hget($hashName, $key, $val)
{
assert(is_string($hashName)) && assert(is_string($key));
return $this->redis->hget($hashName, $key, $val);
}
/**
*
* 将哈希表key中的域field的值设为value。
* @param String $hashName
* @param String $key
* @param Mixed $val
* @return bool
*/
public function hset($hashName, $key, $val)
{
assert(is_string($hashName)) && assert(is_string($key));
return $this->redis->hset($hashName, $key, $val);
}
/**
*
* 排序
*
* @param String $key
* @param array $options
* 'by' => 'some_pattern_*',
* 'limit' => array(0, 1),
* 'get' => 'some_other_pattern_*' or an array of patterns,
* 'sort' => 'asc' or 'desc',
* 'alpha' => TRUE,
* 'store' => 'external-key'
* @return array
*/
public function sort($key, array $options = array())
{
assert(is_string($key));
return $this->redis->sort($key, $options);
}
/**
*
* 从当前数据库中随机返回(不删除)一个key。
* @return String or Mixed
*/
public function randomkey()
{
return $this->redis->randomKey();
}
/**
*
* 返回给定key的剩余生存时间(time to live)(以秒为单位)。
* @param String $key
* @return Integer
*/
public function ttl($key)
{
assert(is_string($key));
return $this->redis->ttl($key);
}
/**
*
* 检查给定key是否存在
* @param String $key
* @return bool
*/
public function exists($key)
{
assert(is_string($key));
return $this->redis->exists($key);
}
/**
*
* 移动key 到另外一个数据库
* @param String $key
* @param Integer $dbName
* @return bool
*/
public function move($key, $dbName)
{
assert(is_string($key));
return $this->redis->move($key, $dbName);
}
/**
*
* 将key改名为newkey
* @param String $key
* @param String $newKey
* @return bool
*/
public function rename($key, $newKey)
{
assert(is_string($key)) && assert(is_string($newKey));
return $this->redis->rename($key, $newKey);
}
/**
*
* 返回key所储存的值的类型
* @param String $key
* @return Mixed
* ================================
* none(key不存在) string(字符串) list(列表) set(集合) zset(有序集) hash(哈希表)
* ================================
*/
public function type($key)
{
return $this->redis->type($key);
}
/**
*
* 为给定key设置生存时间
* @param String $key
* @param Integer $expire
* @return bool
*/
public function setTimeout($key, $expire)
{
assert(is_string($key)) && assert(is_int($expire));
return $this->redis->setTimeout($key, $expire);
}
/**
*
* 不同在于EXPIREAT命令接受的时间参数是UNIX时间戳(unix timestamp)。
* @param String $key
* @param Integer $expire
* @return bool
*/
public function expireAt($key, $expire)
{
assert(is_string($key)) && assert(is_int($expire));
return $this->redis->expireAt($key, $expire);
}
/**
*
* 移除给定key的生存时间
* @param String $key
* @return bool
*/
public function persist($key)
{
assert(is_string($key));
return $this->redis->persist($key);
}
/**
*
* 将值value关联到key,并将key的生存时间设为seconds(以秒为单位)
* @param String $key
* @param Mixed $val
* @param Integer $expire
* @return bool
*/
public function setex($key, $val, $expire)
{
assert(is_string($key)) && assert(is_int($expire));
return $this->redis->setex($key, $expire, $val);
}
/**
*
* 如果key已经存在并且是一个字符串,APPEND命令将value追加到key原来的值之后
* @param String $key
* @param Mixed $val
* @return bool
*/
public function append($key, $val)
{
assert(is_string($key));
return $this->redis->append($key, $val);
}
/**
*
* 将给定key的值设为value,并返回key的旧值
* @param String $key
* @param Mixed $val
* @return Mixed
*/
public function getSet($key, $val)
{
assert(is_string($key));
return $this->redis->getSet($key, $val);
}
/**
*
* 返回key所储存的字符串值的长度
* @param String $key
* @return integer
*/
public function strlen($key)
{
return $this->redis->strlen($key);
}
/**
*
* 将key中储存的数字值减一
* @param String $key
* @return Integer
*/
public function decr($key)
{
assert(is_string($key));
return $this->redis->decr($key);
}
/**
*
* 将key所储存的值减去减量decrement。
* @param String $key
* @param Integer $value
* @return intger
*/
public function decrBy($key, $value = 1)
{
assert(is_string($key)) && assert(is_int($value));
return $this->redis->decrBy($key, $value);
}
/**
*
* 将key中储存的数字值增一
* @param String $key
* @param Integer $val
* @return Integer
*/
public function incrBy($key, $val = 1)
{
return $this->redis->incrBy($key, $val);
}
/**
*
* 同时将多个field - value(域-值)对设置到哈希表key中
* @param String $key
* @param array $vals
* @return bool
*/
public function hMset($hashKey, array $keys)
{
assert(is_string($hashKey));
return $this->redis->hMset($hashKey, $keys);
}
/**
*
* 返回哈希表key中,一个或多个给定域的值
* @param String $hashKey
* @param array $keys
* @return Mixed
*/
public function hmGet($hashKey, array $keys)
{
assert(is_string($hashKey));
return $this->redis->hmGet($hashKey, $keys);
}
/**
*
* 返回哈希表key中,所有的域和值
* @param String $hashKey
* @return Mixed
*/
public function hGetAll($hashKey)
{
assert(is_string($hashKey));
return $this->redis->hGetAll($hashKey);
}
/**
*
* 删除哈希表key中的一个或多个指定域
* @param String $hashKey
* @return bool
*/
public function hDel($hashKey)
{
$this->redis->hDel($hashKey);
}
/**
*
* 返回哈希表key中域的数量
* @param String $hashKey
* @return Integer
*/
public function hLen($hashKey)
{
return $this->redis->hLen($hashKey);
}
/**
*
* 查看哈希表key中,给定域field是否存在
* @param String $hashKey
* @return bool
*/
public function hExists($hashKey)
{
return $this->redis->hExists($hashKey);
}
/**
*
* 为哈希表key中的域field的值加上增量increment。
* @param String $hashKey
* @param String $key
* @param Integer $member
* @return Integer
*/
public function hincrby($hashKey, $key, $member)
{
return $this->redis->hIncrBy($hashKey, $key, $member);
}
/**
*
* 返回哈希表key中的所有域
* @param String $hashKey
* @return array
*/
public function hKeys($hashKey)
{
return $this->redis->hKeys($hashKey);
}
/**
*
* 返回哈希表key中的所有值
* @param String $hashKey
* @return Array
*/
public function hVals($hashKey)
{
return $this->redis->hVals($hashKey);
}
###########################
# 表 List
###########################
/**
*
* 将值value插入到列表key的表头
* @param String $key
* @param Mixed $value
* @return bool
*/
public function lPush($key, $value)
{
assert(is_string($key));
return $this->redis->lPush($key, $value);
}
/**
*
* 将值value插入到列表key的表头,当且仅当key存在并且是一个列表
* @param String $key
* @param Mixed $value
* @return bool
*/
public function lPushx($key, $value)
{
assert(is_string($key));
return $this->redis->lPushx($key, $value);
}
/**
*
* 将值value插入到列表key的表尾
* @param String $key
* @param Mixed $value
* @return bool
*/
public function rPush($key, $value)
{
assert(is_string($key));
return $this->redis->rPush($key, $value);
}
/**
*
* 将值value插入到列表key的表尾,当且仅当key存在并且是一个列表
* @param String $key
* @param Mixed $value
* @return bool
*/
public function rPushx($key, $value)
{
assert(is_string($key));
return $this->redis->rPushx($key, $value);
}
/**
*
* 移除并返回列表key的头元素
* @param String $key
* @return bool or nil
*/
public function lPop($key)
{
return $this->redis->lPop($key);
}
/**
*
* 移除并返回列表key的尾元素
* @param String $key
* @return bool or nil
*/
public function rPop($key)
{
return $this->redis->rPop($key);
}
/**
*
* BLPOP是列表的阻塞式(blocking)弹出原语
* ===================================
* 类似 Gearman 等待移除
* ===================================
* @param array $keys
* @param Integer $timeout
* @return array
*/
public function blPop(array $keys, $timeout = 2)
{
return $this->redis->blPop($keys, (int)$timeout);
}
/**
*
* BRPOP是列表的阻塞式(blocking)弹出原语。
* ===================================
* 类似 Gearman 等待移除
* ===================================
* @param array $keys
* @param Integer $timeout
*
*/
public function brPop(array $keys, $timeout = 2)
{
return $this->redis->brPop($keys, (int)$timeout);
}
/**
* TODO
* 返回列表key的长度。
*/
public function llen()
{
}
/**
*
* 返回列表key中指定区间内的元素,区间以偏移量start和stop指定。
* @param String $key
* @param Integer $start
* @param Integer $end
* @return array
*/
public function lRange($key, $start = 0, $end = 0)
{
return $this->redis->lRange($key, (int)$start, (int)$end);
}
/**
*
* 根据参数count的值,移除列表中与参数value相等的元素
* ============================================
* count的值可以是以下几种:
* count > 0: 从表头开始向表尾搜索,移除与value相等的元素,数量为count
* count < 0: 从表尾开始向表头搜索,移除与value相等的元素,数量为count的绝对值
* count = 0: 移除表中所有与value相等的值
* ============================================
* @param String $key
* @param String $value
* @param Integer $count
* @return Integer
*/
public function lRem($key, $value, $count)
{
$this->redis->lRem((string)$key, (string)$value, (int)$count);
}
/**
*
* 将列表key下标为index的元素的值甚至为value
* (当index参数超出范围,或对一个空列表(key不存在)进行LSET时,返回一个错误)
* @param String $key
* @param Integer $index
* @param String $value
* @return bool
*/
public function lSet($key, $index, $value)
{
return $this->redis->lSet((string)$key, (int)$index, (string)$value);
}
/**
*
* 对一个列表进行修剪(trim),就是说,让列表只保留指定区间内的元素,不在指定区间之内的元素都将被删除
* @param String $key
* @param Integer $start
* @param Integer $stop
* @return bool
*/
public function lTrim($key, $start, $stop)
{
return $this->redis->lTrim((string)$key, (int)$start, (int)$stop);
}
/**
*
* 返回列表key中,下标为index的元素
* @param String $key
* @param Integer $index
* @return bool or nil
*/
public function lGet($key, $index)
{
return $this->redis->lGet((string)$key, (int)$index);
}
/**
* TODO
* Enter description here ...
*/
public function rpoplpush()
{
}
##################################################################
# SET
##################################################################
/**
*
* 将一个或多个member元素加入到集合key当中,已经存在于集合的member元素将被忽略
* @param String $key
* @param Mixed $value
* @return bool
*/
public function sAdd($skey, $value)
{
return $this->redis->sAdd($skey, $value);
}
/**
*
* ( 扩展 ) 将一个或多个member元素加入到集合key当中,已经存在于集合的member元素将被忽略
* @param String $key
* @param Mixed $value
* @param Integer $expiration
* @return bool
*/
public function sAdd2($skey, $value, $expiration = 0)
{
$result = $this->redis->sAdd($skey, $value);
$this->redis->setTimeout($skey, $expiration);
return $result;
}
/**
*
* 移除集合key中的一个或多个member元素,不存在的member元素会被忽略
* @param String $key
* @param String $member
* @return bool
*/
public function sRem($skey, $member)
{
return $this->redis->sRem((string)$skey, (string)$member);
}
/**
*
* 返回集合key中的所有成员
* @param String $key
* @return array
*/
public function sMembers($skey)
{
return $this->redis->sMembers((string)$skey);
}
/**
*
* 判断member元素是否是集合key的成员
* @param String $key
* @param String $value
*/
public function sIsMember($skey, $value)
{
return $this->redis->sIsMember((string)$skey, (string)$value);
}
/**
*
* 返回集合key的基数(集合中元素的数量)
* @param String $skey
* @return Integer
*/
public function sCard($skey)
{
return $this->redis->sCard((string)$skey);
}
/**
*
* 将member元素从source集合移动到destination集合
* @param String $srcKey
* @param String $dstKey
* @param String $member
* @return bool
*/
public function sMove($srcKey, $dstKey, $member)
{
return $this->redis->sMove((string)$srcKey, (string)$dstKey, (string)$member);
}
/**
*
* 移除并返回集合中的一个随机元素
* @param String $skey
* @return string or bool
*/
public function sPop($skey)
{
return $this->redis->sPop((string)$skey);
}
/**
*
* 返回集合中的一个随机元素。
* @param String $skey
* @return array or nil
*/
public function sRandMember($skey)
{
return $this->redis->sRandMember((string)$skey);
}
/**
* func_get_args
* 返回一个集合的全部成员,该集合是所有给定集合的交集
* @param array $skey
* @return array
*/
public function sInter(array $skey)
{
return $this->redis->sInter($skey);
}
#TODO
//返回一个集合的全部成员,该集合是所有给定集合的并集
public function sUnion(array $skey)
{
return $this->redis->sUnion($skey);
}
//返回一个集合的全部成员,该集合是所有给定集合的差集
public function sDiff(array $skey)
{
return $this->redis->sDiff($skey);
}
########################################################
# 有序集(Sorted Set)
########################################################
/**
*
* 将一个或多个member元素及其score值加入到有序集key当中
* @param String $zKey
* @param Integer $score
* @param String $value
* @return Integer
*/
public function zAdd($zKey, $score, $value)
{
assert(is_string($zKey)) && assert(is_int($score)) && assert(is_string($value));
return $this->redis->zAdd($zKey, $score, $value);
}
/**
*
* 移除有序集key中的一个或多个成员,不存在的成员将被忽略
* @param String $zKey
* @param String $member
* @return Integer
*/
public function zRem($zKey, $member)
{
return $this->redis->zRem((string)$zKey, (string)$member);
}
/**
*
* 返回有序集key的基数
* @param String $zKey
* @return Integer
*/
public function zSize($zKey)
{
return $this->redis->zSize((string)$zKey);
}
/**
*
* 返回有序集key中,score值在min和max之间(默认包括score值等于min或max)的成员
* @param String $zKey
* @param Integer $start
* @param Integer $end
* @return array
*/
public function zCount($zKey, $start, $end)
{
return $this->redis->zCount($zKey, $start, $end);
}
/**
*
* 返回有序集key中,成员member的score值
* @param String $zKey
* @param String $member
* @return String
*/
public function zScore($zKey, $member)
{
return $this->redis->zScore($zKey, $member);
}
/**
*
* 为有序集key的成员member的score值加上增量increment
* @param String $zKey
* @param Integer $value
* @param String $member
* @return Integer
*/
public function zIncrBy($zKey, $value, $member)
{
return $this->redis->zIncrBy($zKey, $value, $member);
}
/**
*
* 返回有序集key中,指定区间内的成员
* @param String $zKey
* @param Integer $start
* @param Integer $end
* @param bool $withscores
* @return bool ( 默认False无键值/True有键值 )
*/
public function zRange($zKey, $start, $end, $withscores = false)
{
return $this->redis->zRange($zKey, $start, $end, $withscores);
}
/**
*
* 返回有序集key中,指定区间内的成员
* 其中成员的位置按score值递减(从大到小)来排列
* @param String $zKey
* @param Integer $start
* @param Integer $end
* @param bool $withscores
* @return bool ( 默认False无键值/True有键值 )
*/
public function zRevRange($zKey, $start, $end, $withscores = false)
{
return $this->redis->zRevRange($zKey, $start, $end, $withscores);
}
/**
*
* 返回有序集key中,所有score值介于min和max之间(包括等于min或max)的成员。有序集成员按score值递增(从小到大 or 从大到小)次序排列
* @param String $zKey
* @param Integer $start
* @param Integer $end
* @param array $options
* @return array
* =========================================================
* $redis->zRangeByScore('key', 0, 3);
* array('val0', 'val2')
* $redis->zRangeByScore('key', 0, 3, array('withscores' => TRUE);
* array('val0' => 0, 'val2' => 2)
* $redis->zRangeByScore('key', 0, 3, array('limit' => array(1, 1));
* array('val2' => 2)
* $redis->zRangeByScore('key', 0, 3, array('limit' => array(1, 1));
* array('val2')
* $redis->zRangeByScore('key', 0, 3, array('withscores' => TRUE, 'limit' => array(1, 1));
* array('val2' => 2)
* =========================================================
*
*/
public function zRangeByScore($zKey, $start, $end, array $options)
{
return $this->redis->zRangeByScore($zKey, $start, $end, $options);
}
/**
*
* 返回有序集key中成员member的排名。其中有序集成员按score值递增(从小到大 or 从大到小)顺序排列
* @param String $zKey
* @param String $member
* @param String $order ( desc or asc )
* @return array
*/
public function zRank($zKey, $member, $order = 'desc')
{
return $order == 'desc' ? $this->redis->zRank($zKey, $member) : $this->redis->zRevRank($zKey, $member);
}
/**
* 移除有序集key中,指定排名(rank)区间内的所有成员
* 区间分别以下标参数start和stop指出,包含start和stop在内
* @param String $zKey
* @param Integer $start
* @param Integer $end
* @return Integer
*/
public function zRemRangeByRank($zKey, $start, $end)
{
return $this->redis->zRemRangeByRank($zKey, $start, $end);
}
public function tag($tagName)
{
}
/**
* 移除有序集key中,指定(socre)区间内的所有成员
* 区间分别以下标参数start和stop指出,包含start和stop在内
* @param String $zKey
* @param Integer $start
* @param Integer $end
* @return Integer
*/
public function zRemRangeByScore($zKey, $start, $end)
{
return $this->redis->zRemRangeByScore($zKey, $start, $end);
}
public function zRevRangeByScore($zkey, $start, $end, array $options)
{
return $this->redis->zRevRangeByScore($zkey, $start, $end, $options);
}
/**
* 发布消息
*
* @param String $channel
* @param String $message
* @return Integer
*/
public function publish($channel, $message)
{
return $this->redis->publish($channel, $message);
}
/**
* 订阅消息
* @param String $channel
* @return String
*/
public function subscribe(array $channel, $callback)
{
return $this->redis->subscribe($channel, $callback);
}
/**
* 退订
* @param String $channel
*/
public function unsubscribe($channel)
{
return $this->redis->unsubscribe($channel);
}
/**
* 按照模式匹配订阅多个频道
*
* @param String $pattern (如:news.* 可订阅news.开头的所有频道)
*/
public function psubscribe($pattern)
{
return $this->redis->psubscribe($pattern);
}
/**
* 退订给定模式的所有渠道
*
* @param String $pattern
*/
public function punsubscribe($pattern)
{
return $this->redis->punsubscribe($pattern);
}
public function pubsub($pattern)
{
return $this->redis->pubsub($pattern);
}
}
\ No newline at end of file
... ...
<?php
/**
* Created by PhpStorm.
* User: ziy
* Date: 14-7-25
* Time: 上午12:47
*/
class Q_Cache_Ssdb_Base
{
private $debug = false;
public $sock = null;
private $_closed = false;
private $recv_buf = '';
private $_easy = false;
public $last_resp = null;
function __construct($host, $port, $timeout_ms = 2000)
{
$timeout_f = (float)$timeout_ms / 1000;
$this->sock = @stream_socket_client("$host:$port", $errno, $errstr, $timeout_f);
if (!$this->sock) {
throw new Q_Cache_Ssdb_Exception("$errno: $errstr");
}
$timeout_sec = intval($timeout_ms / 1000);
$timeout_usec = ($timeout_ms - $timeout_sec * 1000) * 1000;
@stream_set_timeout($this->sock, $timeout_sec, $timeout_usec);
if (function_exists('stream_set_chunk_size')) {
@stream_set_chunk_size($this->sock, 1024 * 1024);
}
}
/**
* After this method invoked with yesno=true, all requesting methods
* will not return a Q_Cache_Ssdb_Response object.
* And some certain methods like get/zget will return false
* when response is not ok(not_found, etc)
*/
function easy()
{
$this->_easy = true;
}
function close()
{
if (!$this->_closed) {
@fclose($this->sock);
$this->_closed = true;
$this->sock = null;
}
}
function closed()
{
return $this->_closed;
}
private $batch_mode = false;
private $batch_cmds = array();
function batch()
{
$this->batch_mode = true;
$this->batch_cmds = array();
return $this;
}
function multi()
{
return $this->batch();
}
function exec()
{
$ret = array();
foreach ($this->batch_cmds as $op) {
list($cmd, $params) = $op;
$this->send_req($cmd, $params);
}
foreach ($this->batch_cmds as $op) {
list($cmd, $params) = $op;
$resp = $this->recv_resp($cmd);
$resp = $this->check_easy_resp($cmd, $resp);
$ret[] = $resp;
}
$this->batch_mode = false;
$this->batch_cmds = array();
return $ret;
}
function request()
{
$args = func_get_args();
$cmd = array_shift($args);
return $this->__call($cmd, $args);
}
function __call($cmd, $params = array())
{
$cmd = strtolower($cmd);
// act like Redis::zAdd($key, $score, $value);
if ($cmd == 'zadd') {
$cmd = 'zset';
$t = $params[1];
$params[1] = $params[2];
$params[2] = $t;
}
if ($this->batch_mode) {
$this->batch_cmds[] = array($cmd, $params);
return $this;
}
try {
if ($this->send_req($cmd, $params) === false) {
$resp = new Q_Cache_Ssdb_Response('error', 'send error');
} else {
$resp = $this->recv_resp($cmd);
}
} catch (Q_Cache_Ssdb_Exception $e) {
if ($this->_easy) {
throw $e;
} else {
$resp = new Q_Cache_Ssdb_Response('error', $e->getMessage());
}
}
$resp = $this->check_easy_resp($cmd, $resp);
return $resp;
}
private function check_easy_resp($cmd, $resp)
{
$this->last_resp = $resp;
if ($this->_easy) {
if ($resp->not_found()) {
return NULL;
} else if (!$resp->ok() && !is_array($resp->data)) {
return false;
} else {
return $resp->data;
}
} else {
$resp->cmd = $cmd;
return $resp;
}
}
// all supported are listed, for documentation purpose
function multi_set($kvs = array())
{
$args = array();
foreach ($kvs as $k => $v) {
$args[] = $k;
$args[] = $v;
}
return $this->__call(__FUNCTION__, $args);
}
function multi_get($args = array())
{
$args = func_get_args();
return $this->__call(__FUNCTION__, $args);
}
function multi_del($keys = array())
{
$args = func_get_args();
return $this->__call(__FUNCTION__, $args);
}
function multi_exists($keys = array())
{
$args = func_get_args();
return $this->__call(__FUNCTION__, $args);
}
function multi_hexists($name, $keys = array())
{
$args = func_get_args();
return $this->__call(__FUNCTION__, $args);
}
function multi_zexists($name, $keys = array())
{
$args = func_get_args();
return $this->__call(__FUNCTION__, $args);
}
function multi_hsize($keys = array())
{
$args = func_get_args();
return $this->__call(__FUNCTION__, $args);
}
function multi_zsize($keys = array())
{
$args = func_get_args();
return $this->__call(__FUNCTION__, $args);
}
function multi_hget($name, $keys = array())
{
$args = func_get_args();
return $this->__call(__FUNCTION__, $args);
}
function multi_zget($name, $keys = array())
{
$args = func_get_args();
return $this->__call(__FUNCTION__, $args);
}
function multi_hdel($name, $keys = array())
{
$args = func_get_args();
return $this->__call(__FUNCTION__, $args);
}
function multi_zdel($name, $keys = array())
{
$args = func_get_args();
return $this->__call(__FUNCTION__, $args);
}
function multi_hset($name, $kvs = array())
{
$args = array($name);
foreach ($kvs as $k => $v) {
$args[] = $k;
$args[] = $v;
}
return $this->__call(__FUNCTION__, $args);
}
function multi_zset($name, $kvs = array())
{
$args = array($name);
foreach ($kvs as $k => $v) {
$args[] = $k;
$args[] = $v;
}
return $this->__call(__FUNCTION__, $args);
}
/**/
function set($key, $val)
{
$args = func_get_args();
return $this->__call(__FUNCTION__, $args);
}
function setx($key, $val, $ttl)
{
$args = func_get_args();
return $this->__call(__FUNCTION__, $args);
}
function incr($key, $val = 1)
{
$args = func_get_args();
return $this->__call(__FUNCTION__, $args);
}
function decr($key, $val)
{
$args = func_get_args();
return $this->__call(__FUNCTION__, $args);
}
function exists($key)
{
$args = func_get_args();
return $this->__call(__FUNCTION__, $args);
}
function get($key)
{
$args = func_get_args();
return $this->__call(__FUNCTION__, $args);
}
function del($key)
{
$args = func_get_args();
return $this->__call(__FUNCTION__, $args);
}
function scan($key_start, $key_end, $limit)
{
$args = func_get_args();
return $this->__call(__FUNCTION__, $args);
}
function rscan($key_start, $key_end, $limit)
{
$args = func_get_args();
return $this->__call(__FUNCTION__, $args);
}
function keys($key_start, $key_end, $limit)
{
$args = func_get_args();
return $this->__call(__FUNCTION__, $args);
}
/* zset */
function zset($name, $key, $score)
{
$args = func_get_args();
return $this->__call(__FUNCTION__, $args);
}
// for migrate from Redis::zAdd()
function zadd($key, $score, $value)
{
$args = func_get_args();
return $this->__call(__FUNCTION__, $args);
}
function zget($name, $key)
{
$args = func_get_args();
return $this->__call(__FUNCTION__, $args);
}
function zexists($name, $key)
{
$args = func_get_args();
return $this->__call(__FUNCTION__, $args);
}
function zdel($name, $key)
{
$args = func_get_args();
return $this->__call(__FUNCTION__, $args);
}
function zrange($name, $offset, $limit)
{
$args = func_get_args();
return $this->__call(__FUNCTION__, $args);
}
function zclear($name)
{
$args = func_get_args();
return $this->__call(__FUNCTION__, $args);
}
function zscan($name, $key_start, $score_start, $score_end, $limit)
{
$args = func_get_args();
return $this->__call(__FUNCTION__, $args);
}
function zrscan($name, $key_start, $score_start, $score_end, $limit)
{
$args = func_get_args();
return $this->__call(__FUNCTION__, $args);
}
function zkeys($name, $key_start, $score_start, $score_end, $limit)
{
$args = func_get_args();
return $this->__call(__FUNCTION__, $args);
}
function zincr($name, $key, $score = 1)
{
$args = func_get_args();
return $this->__call(__FUNCTION__, $args);
}
function zdecr($name, $key, $score)
{
$args = func_get_args();
return $this->__call(__FUNCTION__, $args);
}
function zsize($name)
{
$args = func_get_args();
return $this->__call(__FUNCTION__, $args);
}
function zlist($name_start, $name_end, $limit)
{
$args = func_get_args();
return $this->__call(__FUNCTION__, $args);
}
function zrank($name, $key)
{
$args = func_get_args();
return $this->__call(__FUNCTION__, $args);
}
function zrrank($name, $key)
{
$args = func_get_args();
return $this->__call(__FUNCTION__, $args);
}
function zRevRank($name, $key)
{
$args = func_get_args();
return $this->__call("zrrank", $args);
}
function zrrange($name, $offset, $limit)
{
$args = func_get_args();
return $this->__call(__FUNCTION__, $args);
}
function zRevRange($name, $offset, $limit)
{
$args = func_get_args();
return $this->__call("zrrange", $args);
}
/* hashmap */
function hset($name, $key, $val)
{
$args = func_get_args();
return $this->__call(__FUNCTION__, $args);
}
function hget($name, $key)
{
$args = func_get_args();
return $this->__call(__FUNCTION__, $args);
}
function hexists($name, $key)
{
$args = func_get_args();
return $this->__call(__FUNCTION__, $args);
}
function hdel($name, $key)
{
$args = func_get_args();
return $this->__call(__FUNCTION__, $args);
}
function hclear($name)
{
$args = func_get_args();
return $this->__call(__FUNCTION__, $args);
}
function hgetall($name)
{
$args = func_get_args();
return $this->__call(__FUNCTION__, $args);
}
function hscan($name, $key_start, $key_end, $limit)
{
$args = func_get_args();
return $this->__call(__FUNCTION__, $args);
}
function hrscan($name, $key_start, $key_end, $limit)
{
$args = func_get_args();
return $this->__call(__FUNCTION__, $args);
}
function hkeys($name, $key_start, $key_end, $limit)
{
$args = func_get_args();
return $this->__call(__FUNCTION__, $args);
}
function hincr($name, $key, $val = 1)
{
$args = func_get_args();
return $this->__call(__FUNCTION__, $args);
}
function hdecr($name, $key, $val)
{
$args = func_get_args();
return $this->__call(__FUNCTION__, $args);
}
function hsize($name)
{
$args = func_get_args();
return $this->__call(__FUNCTION__, $args);
}
function hlist($name_start, $name_end, $limit)
{
$args = func_get_args();
return $this->__call(__FUNCTION__, $args);
}
/*****/
function qfront($name)
{
$args = func_get_args();
return $this->__call(__FUNCTION__, $args);
}
function qback($name)
{
$args = func_get_args();
return $this->__call(__FUNCTION__, $args);
}
function qpop($name)
{
$args = func_get_args();
return $this->__call(__FUNCTION__, $args);
}
function qpush($name, $item)
{
$args = func_get_args();
return $this->__call(__FUNCTION__, $args);
}
private function send_req($cmd, $params)
{
$req = array($cmd);
foreach ($params as $p) {
if (is_array($p)) {
$req = array_merge($req, $p);
} else {
$req[] = $p;
}
}
return $this->send($req);
}
private function recv_resp($cmd)
{
$resp = $this->recv();
if ($resp === false) {
return new Q_Cache_Ssdb_Response('error', 'Unknown error');
} else if (!$resp) {
return new Q_Cache_Ssdb_Response('disconnected', 'Connection closed');
}
switch ($cmd) {
case 'getbit':
case 'setbit':
case 'countbit':
case 'strlen':
case 'set':
case 'setx':
case 'setnx':
case 'zset':
case 'hset':
case 'qpush':
case 'qpush_front':
case 'qpush_back':
case 'del':
case 'zdel':
case 'hdel':
case 'hsize':
case 'zsize':
case 'qsize':
case 'hclear':
case 'zclear':
case 'qclear':
case 'multi_set':
case 'multi_del':
case 'multi_hset':
case 'multi_hdel':
case 'multi_zset':
case 'multi_zdel':
case 'incr':
case 'decr':
case 'zincr':
case 'zdecr':
case 'hincr':
case 'hdecr':
case 'zget':
case 'zrank':
case 'zrrank':
case 'zcount':
case 'zsum':
case 'zremrangebyrank':
case 'zremrangebyscore':
$val = isset($resp[1]) ? intval($resp[1]) : 0;
return new Q_Cache_Ssdb_Response($resp[0], $val);
case 'zavg':
$val = isset($resp[1]) ? floatval($resp[1]) : (float)0;
return new Q_Cache_Ssdb_Response($resp[0], $val);
case 'get':
case 'substr':
case 'getset':
case 'hget':
case 'qget':
case 'qfront':
case 'qback':
case 'qpop':
case 'qpop_front':
case 'qpop_back':
if ($resp[0] == 'ok') {
if (count($resp) == 2) {
return new Q_Cache_Ssdb_Response('ok', $resp[1]);
} else {
return new Q_Cache_Ssdb_Response('server_error', 'Invalid response');
}
} else {
$errmsg = isset($resp[1]) ? $resp[1] : '';
return new Q_Cache_Ssdb_Response($resp[0], $errmsg);
}
break;
case 'keys':
case 'zkeys':
case 'hkeys':
case 'hlist':
case 'zlist':
case 'qslice':
$data = array();
if ($resp[0] == 'ok') {
for ($i = 1; $i < count($resp); $i++) {
$data[] = $resp[$i];
}
}
return new Q_Cache_Ssdb_Response($resp[0], $data);
case 'exists':
case 'hexists':
case 'zexists':
if ($resp[0] == 'ok') {
if (count($resp) == 2) {
return new Q_Cache_Ssdb_Response('ok', (bool)$resp[1]);
} else {
return new Q_Cache_Ssdb_Response('server_error', 'Invalid response');
}
} else {
$errmsg = isset($resp[1]) ? $resp[1] : '';
return new Q_Cache_Ssdb_Response($resp[0], $errmsg);
}
break;
case 'multi_exists':
case 'multi_hexists':
case 'multi_zexists':
if ($resp[0] == 'ok') {
if (count($resp) % 2 == 1) {
$data = array();
for ($i = 1; $i < count($resp); $i += 2) {
$data[$resp[$i]] = (bool)$resp[$i + 1];
}
return new Q_Cache_Ssdb_Response('ok', $data);
} else {
return new Q_Cache_Ssdb_Response('server_error', 'Invalid response');
}
} else {
return new Q_Cache_Ssdb_Response($resp[0]);
}
break;
case 'scan':
case 'rscan':
case 'zscan':
case 'zrscan':
case 'zrange':
case 'zrrange':
case 'hscan':
case 'hrscan':
case 'hgetall':
case 'multi_hsize':
case 'multi_zsize':
case 'multi_get':
case 'multi_hget':
case 'multi_zget':
if ($resp[0] == 'ok') {
if (count($resp) % 2 == 1) {
$data = array();
for ($i = 1; $i < count($resp); $i += 2) {
if ($cmd[0] == 'z') {
$data[$resp[$i]] = intval($resp[$i + 1]);
} else {
$data[$resp[$i]] = $resp[$i + 1];
}
}
return new Q_Cache_Ssdb_Response('ok', $data);
} else {
return new Q_Cache_Ssdb_Response('server_error', 'Invalid response');
}
} else {
return new Q_Cache_Ssdb_Response($resp[0]);
}
break;
default:
return new Q_Cache_Ssdb_Response($resp[0], array_slice($resp, 1));
}
return new Q_Cache_Ssdb_Response('error', 'Unknown command: $cmd');
}
private function send($data)
{
$ps = array();
foreach ($data as $p) {
$ps[] = strlen($p);
$ps[] = $p;
}
$s = join("\n", $ps) . "\n\n";
if ($this->debug) {
echo '> ' . str_replace(array("\r", "\n"), array('\r', '\n'), $s) . "\n";
}
try {
while (true) {
$ret = @fwrite($this->sock, $s);
if ($ret == false) {
$this->close();
throw new Q_Cache_Ssdb_Exception('Connection lost');
}
$s = substr($s, $ret);
if (strlen($s) == 0) {
break;
}
@fflush($this->sock);
}
} catch (Exception $e) {
$this->close();
throw new Q_Cache_Ssdb_Exception($e->getMessage());
}
return $ret;
}
private function recv()
{
while (true) {
$ret = $this->parse();
if ($ret === null) {
try {
$data = @fread($this->sock, 1024 * 1024);
if ($this->debug) {
echo '< ' . str_replace(array("\r", "\n"), array('\r', '\n'), $data) . "\n";
}
} catch (Exception $e) {
$data = '';
}
if ($data == false) {
$this->close();
throw new Q_Cache_Ssdb_Exception('Connection lost');
}
$this->recv_buf .= $data;
} else {
return $ret;
}
}
}
private function parse()
{
//if(len($this->recv_buf)){print 'recv_buf: ' + repr($this->recv_buf);}
$ret = array();
$spos = 0;
$epos = 0;
// performance issue for large reponse
//$this->recv_buf = ltrim($this->recv_buf);
while (true) {
$spos = $epos;
$epos = strpos($this->recv_buf, "\n", $spos);
if ($epos === false) {
break;
}
$epos += 1;
$line = substr($this->recv_buf, $spos, $epos - $spos);
$spos = $epos;
$line = trim($line);
if (strlen($line) == 0) { // head end
$this->recv_buf = substr($this->recv_buf, $spos);
return $ret;
}
$num = intval($line);
$epos = $spos + $num;
if ($epos > strlen($this->recv_buf)) {
break;
}
$data = substr($this->recv_buf, $spos, $epos - $spos);
$ret[] = $data;
$spos = $epos;
$epos = strpos($this->recv_buf, "\n", $spos);
if ($epos === false) {
break;
}
$epos += 1;
}
return null;
}
}
\ No newline at end of file
... ...
<?php
/**
* Created by PhpStorm.
* User: ziy
* Date: 14-7-25
* Time: 上午12:40
*/
class Q_Cache_Ssdb_Exception extends Exception
{
}
\ No newline at end of file
... ...
<?php
class Q_Cache_Ssdb_Response
{
public $cmd;
public $code;
public $data = null;
public $message;
function __construct($code = 'ok', $data_or_message = null)
{
$this->code = $code;
if ($code == 'ok') {
$this->data = $data_or_message;
} else {
$this->message = $data_or_message;
}
}
function __toString()
{
if ($this->code == 'ok') {
$s = $this->data === null ? '' : json_encode($this->data);
} else {
$s = $this->message;
}
return sprintf('%-13s %12s %s', $this->cmd, $this->code, $s);
}
function ok()
{
return $this->code == 'ok';
}
function not_found()
{
return $this->code == 'not_found';
}
}
\ No newline at end of file
... ...
<?php
/**
* Created by PhpStorm.
* User: ziy
* Date: 14-7-25
* Time: 上午12:42
*/
class Q_Cache_Ssdb_Simple extends Q_Cache_Ssdb_Base
{
function __construct($host, $port, $timeout_ms = 2000)
{
parent::__construct($host, $port, $timeout_ms);
$this->easy();
}
}
\ No newline at end of file
... ...
<?php
/**
* Created by PhpStorm.
* User: liuziyang
* Date: 14-1-25
* Time: 22:52
*/
class Q_Cache_Yac
{
static private $_yac = Null;
static function isEnabled()
{
return extension_loaded('yac');
}
/**
* @return Yac
*/
static function initYac()
{
if (!extension_loaded('yac')) {
throw new Exception('没有Yac插件.');
}
if (empty(self::$_yac)) {
self::$_yac = new Yac();
}
return self::$_yac;
}
static function set($key, $value)
{
return self::initYac()->set($key, $value);
}
static function get($key)
{
return self::initYac()->get($key);
}
static function delete($key)
{
return self::initYac()->delete($key);
}
static function add($key, $val)
{
return self::initYac()->add($key, $val);
}
static function dump($int)
{
return self::initYac()->dump($int);
}
static function flush()
{
return self::initYac()->flush();
}
}
\ No newline at end of file
... ...
<?php
/**
* Created by JetBrains PhpStorm.
* User: liuziyang
* Date: 12-3-16
* Time: 下午11:31
* To change this template use File | Settings | File Templates.
*/
class Q_Core_Algorithm_Totp
{
/**
* key 生产时间
*/
const keyRegeneration = 30;
/**
* key 长度
*/
const otpLength = 6;
/**
* 所需的Base32编码表
* @var array
*/
private static $lut = array(
"A" => 0, "B" => 1,
"C" => 2, "D" => 3,
"E" => 4, "F" => 5,
"G" => 6, "H" => 7,
"I" => 8, "J" => 9,
"K" => 10, "L" => 11,
"M" => 12, "N" => 13,
"O" => 14, "P" => 15,
"Q" => 16, "R" => 17,
"S" => 18, "T" => 19,
"U" => 20, "V" => 21,
"W" => 22, "X" => 23,
"Y" => 24, "Z" => 25,
"2" => 26, "3" => 27,
"4" => 28, "5" => 29,
"6" => 30, "7" => 31
);
/**
* Generates a 16 digit secret key in base32 format
* @return string
**/
public static function generate_secret_key($length = 16)
{
$b32 = "234567QWERTYUIOPASDFGHJKLZXCVBNM";
$s = "";
for ($i = 0; $i < $length; $i++)
$s .= $b32[rand(0, 31)];
return $s;
}
/**
* Returns the current Unix Timestamp devided by the keyRegeneration
* period.
* @return integer
**/
public static function get_timestamp()
{
return floor(microtime(true) / self::keyRegeneration);
}
/**
* Decodes a base32 string into a binary string.
**/
public static function base32_decode($b32)
{
$b32 = strtoupper($b32);
if (!preg_match('/^[ABCDEFGHIJKLMNOPQRSTUVWXYZ234567]+$/', $b32, $match))
throw new Exception('Invalid characters in the base32 string.');
$l = strlen($b32);
$n = 0;
$j = 0;
$binary = "";
for ($i = 0; $i < $l; $i++) {
$n = $n << 5; // Move buffer left by 5 to make room
$n = $n + self::$lut[$b32[$i]]; // Add value into buffer
$j = $j + 5; // Keep track of number of bits in buffer
if ($j >= 8) {
$j = $j - 8;
$binary .= chr(($n & (0xFF << $j)) >> $j);
}
}
return $binary;
}
/**
* Takes the secret key and the timestamp and returns the one time
* password.
*
* @param binary $key - Secret key in binary form.
* @param integer $counter - Timestamp as returned by get_timestamp.
* @return string
**/
public static function oath_hotp($key, $counter)
{
if (strlen($key) < 8)
throw new Exception('Secret key is too short. Must be at least 16 base 32 characters');
$bin_counter = pack('N*', 0) . pack('N*', $counter); // Counter must be 64-bit int
$hash = hash_hmac('sha1', $bin_counter, $key, true);
return str_pad(self::oath_truncate($hash), self::otpLength, '0', STR_PAD_LEFT);
}
/**
* Verifys a user inputted key against the current timestamp. Checks $window
* keys either side of the timestamp.
*
* @param string $b32seed
* @param string $key - User specified key
* @param integer $window
* @param boolean $useTimeStamp
* @return boolean
**/
public static function verify_key($b32seed, $key, $window = 4, $useTimeStamp = true)
{
$timeStamp = self::get_timestamp();
if ($useTimeStamp !== true) $timeStamp = (int)$useTimeStamp;
$binarySeed = self::base32_decode($b32seed);
for ($ts = $timeStamp - $window; $ts <= $timeStamp + $window; $ts++)
if (self::oath_hotp($binarySeed, $ts) == $key)
return true;
return false;
}
/**
* Extracts the OTP from the SHA1 hash.
* @param binary $hash
* @return integer
**/
public static function oath_truncate($hash)
{
$offset = ord($hash[19]) & 0xf;
return (
((ord($hash[$offset + 0]) & 0x7f) << 24) |
((ord($hash[$offset + 1]) & 0xff) << 16) |
((ord($hash[$offset + 2]) & 0xff) << 8) |
(ord($hash[$offset + 3]) & 0xff)
) % pow(10, self::otpLength);
}
}
/**
$InitalizationKey = "PEHMPSDNLXIOG65U";
$TimeStamp = Q_Core_Algorithm_Totp::get_timestamp();
$secretkey = Q_Core_Algorithm_Totp::base32_decode($InitalizationKey);
$otp = Q_Core_Algorithm_Totp::oath_hotp($secretkey, $TimeStamp);
echo("Init key: $InitalizationKey\n");
echo("Timestamp: $TimeStamp\n");
echo("One time password: $otp\n");
$result = Q_Core_Algorithm_Totp::verify_key($InitalizationKey, "123456");
var_dump($result);
**/
\ No newline at end of file
... ...
<?php
/**
* Created by PhpStorm.
* User: liuziyang
* Date: 13-12-16
* Time: 23:27
*/
class Q_Core_Config_Ini implements Q_Core_Config_Interface
{
protected $_data;
protected $_section;
protected $_sectionData;
protected $_nestSeparator = '.';
public function __construct($filename, $section = null)
{
$this->section($section);
$this->_data = $this->_parseIniFile($filename);
$this->_processSection();
}
public function section($section)
{
if ($section != null && (is_string($section) || is_int($section))) {
$this->_section = $section;
}
return $this;
}
public function get($key, $default = null)
{
$result = $default;
if (array_key_exists($this->_section, $this->_sectionData) && array_key_exists($key, $this->_sectionData[$this->_section])) {
$result = $this->_sectionData[$this->_section][$key];
}
return $result;
}
public function getSectionData()
{
$result = array();
if (array_key_exists($this->_section, $this->_sectionData)) {
$result = $this->_sectionData[$this->_section];
}
return $result;
}
public function count()
{
$result = 0;
if (array_key_exists($this->_section, $this->_sectionData)) {
$result = count($this->_sectionData[$this->_section]);
}
return $result;
}
protected function _parseIniFile($filename)
{
return parse_ini_file($filename, true);
}
protected function _processSection()
{
$allSection = array();
foreach ($this->_data as $key => $val) {
foreach ($val as $_key => $_val) {
$process = $this->_processKey($_key);
if (empty($process)) {
continue;
}
$allSection[$key][$process['prefix']][$process['key']] = $_val;
}
}
$this->_sectionData = $allSection;
}
protected function _processKey($key)
{
if (strpos($key, $this->_nestSeparator) !== false) {
$pieces = explode($this->_nestSeparator, $key, 2);
if (strlen($pieces[0]) && strlen($pieces[1])) {
return array(
'prefix' => $pieces[0],
'key' => $pieces[1]
);
}
throw new Q_Exception("ini key '$key' error.");
}
return array();
}
}
\ No newline at end of file
... ...
<?php
/**
* Created by PhpStorm.
* User: liuziyang
* Date: 13-12-16
* Time: 23:33
*/
interface Q_Core_Config_Interface
{
public function get($key, $default = null);
public function count();
}
\ No newline at end of file
... ...
<?php
class Q_Core_Consts
{
const Q_VERSION = '1.0';
const Q_AUTHOR = 'peter.zyliu';
const Q_CACHE_TIMEOUT = 300;
const Q_CACHE_PATH = '/tmp';
const Q_APPLICATION_ENV_TESTING = 'testing';
const Q_APPLICATION_ENV_LOCALING = 'localing';
const Q_APPLICATION_ENV_RELEASE = 'release';
const Q_SESSION = False;
const Q_APPLICATION_ENV = 'release';
const Q_FRAMEWORK_PATH = '/Data/code/Framework';
const Q_CONFIG = '/Data/code/Framework/Config';
// DB SQL Map 文件前缀
const DB_SQLMAP_PREFIX = 'Sqlmap-';
// DB SQL 缓存域 class
const DB_SQL_CACHE_CLASS = 'default';
// DB SQL 缓存域 Domain
const DB_SQL_CACHE_DOMAIN = 'sql.demo.com';
}
\ No newline at end of file
... ...
<?php
class Q_Core_Cookie
{
/**
* 取得所有的cookie值
*
* @return array
* @since 0.2.2
*/
public function all()
{
return $_COOKIE;
}
/**
* 获取 $_COOKIE
* @param String $name
* @return String
*/
public static function getCookie($name, $default = null)
{
return isset ($_COOKIE [$name]) ? $_COOKIE [$name] : $default;
}
/**
* 设置cookie
*
* @param String $name
* @param String $domain
* @param Mixed $value
* @param Integer $expire (0:Session、-1:删除、time():过期时间 )
* @param String $path
* @param bool $httponly
*/
public static function setCookie($name, $domain, $value = '', $expire = 0, $path = "/", $httponly = false, $secureAuto = false)
{
if ($secureAuto == false) {
$secure = $_SERVER ['SERVER_PORT'] == 443 ? true : false;
} else {
$secure = true;
}
if ($expire == 0) {
$expire = 0;
} else if ($expire == -1) {
$expire = time() - 3600;
}
setcookie($name, $value, $expire, $path, $domain, $secure, $httponly);
}
}
\ No newline at end of file
... ...
<?php
/**
* Uses CRC32 to hash a value into a signed 32bit int address space.
* Under 32bit PHP this (safely) overflows into negatives ints.
*
* @author Paul Annesley
* @package Flexihash
* @licence http://www.opensource.org/licenses/mit-license.php
*/
class Q_Core_Flexi_Crc32Hasher implements Q_Core_Flexi_Hasher {
/* (non-phpdoc)
* @see Flexihash_Hasher::hash()
*/
public function hash($string) {
return crc32($string);
}
}
... ...
<?php
class Q_Core_Flexi_Exception extends Q_Exception {
}
\ No newline at end of file
... ...
<?php
class Q_Core_Flexi_Hash {
/**
* The number of positions to hash each target to.
*
* @var int
*/
private $_replicas = 64;
/**
* The hash algorithm, encapsulated in a Flexihash_Hasher implementation.
* @var object Flexihash_Hasher
*/
private $_hasher;
/**
* Internal counter for current number of targets.
* @var int
*/
private $_targetCount = 0;
/**
* Internal map of positions (hash outputs) to targets
* @var array { position => target, ... }
*/
private $_positionToTarget = array();
/**
* Internal map of targets to lists of positions that target is hashed to.
* @var array { target => [ position, position, ... ], ... }
*/
private $_targetToPositions = array();
/**
* Whether the internal map of positions to targets is already sorted.
* @var boolean
*/
private $_positionToTargetSorted = false;
/**
* Constructor
* @param object $hasher Flexihash_Hasher
* @param int $replicas Amount of positions to hash each target to.
*/
public function __construct(Q_Core_Flexi_Hasher $hasher = null, $replicas = null) {
$this->_hasher = $hasher ? $hasher : new Q_Core_Flexi_Crc32Hasher();
if (!empty($replicas))
$this->_replicas = $replicas;
}
/**
* Add a target.
* @param string $target
* @chainable
*/
public function addTarget($target) {
if (isset($this->_targetToPositions[$target])) {
throw new Q_Core_Flexi_Exception("Target '$target' already exists.");
}
$this->_targetToPositions[$target] = array();
// hash the target into multiple positions
for ($i = 0; $i < $this->_replicas; $i++) {
$position = $this->_hasher->hash($target . $i);
$this->_positionToTarget[$position] = $target; // lookup
$this->_targetToPositions[$target][] = $position; // target removal
}
$this->_positionToTargetSorted = false;
$this->_targetCount++;
return $this;
}
/**
* Add a list of targets.
* @param array $targets
* @chainable
*/
public function addTargets($targets) {
foreach ($targets as $target) {
$this->addTarget($target);
}
return $this;
}
/**
* Remove a target.
* @param string $target
* @chainable
*/
public function removeTarget($target) {
if (!isset($this->_targetToPositions[$target])) {
throw new Flexihash_Exception("Target '$target' does not exist.");
}
foreach ($this->_targetToPositions[$target] as $position) {
unset($this->_positionToTarget[$position]);
}
unset($this->_targetToPositions[$target]);
$this->_targetCount--;
return $this;
}
/**
* A list of all potential targets
* @return array
*/
public function getAllTargets() {
return array_keys($this->_targetToPositions);
}
/**
* Looks up the target for the given resource.
* @param string $resource
* @return string
*/
public function lookup($resource) {
$targets = $this->lookupList($resource, 1);
if (empty($targets))
throw new Q_Core_Flexi_Exception('No targets exist');
return $targets[0];
}
/**
* Get a list of targets for the resource, in order of precedence.
* Up to $requestedCount targets are returned, less if there are fewer in total.
*
* @param string $resource
* @param int $requestedCount The length of the list to return
* @return array List of targets
*/
public function lookupList($resource, $requestedCount) {
if (!$requestedCount)
throw new Q_Core_Flexi_Exception('Invalid count requested');
// handle no targets
if (empty($this->_positionToTarget))
return array();
// optimize single target
if ($this->_targetCount == 1)
return array_unique(array_values($this->_positionToTarget));
// hash resource to a position
$resourcePosition = $this->_hasher->hash($resource);
$results = array();
$collect = false;
$this->_sortPositionTargets();
// search values above the resourcePosition
foreach ($this->_positionToTarget as $key => $value) {
// start collecting targets after passing resource position
if (!$collect && $key > $resourcePosition) {
$collect = true;
}
// only collect the first instance of any target
if ($collect && !in_array($value, $results)) {
$results[] = $value;
}
// return when enough results, or list exhausted
if (count($results) == $requestedCount || count($results) == $this->_targetCount) {
return $results;
}
}
// loop to start - search values below the resourcePosition
foreach ($this->_positionToTarget as $key => $value) {
if (!in_array($value, $results)) {
$results[] = $value;
}
// return when enough results, or list exhausted
if (count($results) == $requestedCount || count($results) == $this->_targetCount) {
return $results;
}
}
// return results after iterating through both "parts"
return $results;
}
public function __toString() {
return sprintf('%s{targets:[%s]}', get_class($this), implode(',', $this->getAllTargets()));
}
// ----------------------------------------
// private methods
/**
* Sorts the internal mapping (positions to targets) by position
*/
private function _sortPositionTargets() {
// sort by key (position) if not already
if (!$this->_positionToTargetSorted) {
ksort($this->_positionToTarget, SORT_REGULAR);
$this->_positionToTargetSorted = true;
}
}
}
\ No newline at end of file
... ...
<?php
/**
* Hashes given values into a sortable fixed size address space.
*
* @author Paul Annesley
* @package Flexihash
* @licence http://www.opensource.org/licenses/mit-license.php
*/
interface Q_Core_Flexi_Hasher {
/**
* Hashes the given string into a 32bit address space.
*
* Note that the output may be more than 32bits of raw data, for example
* hexidecimal characters representing a 32bit value.
*
* The data must have 0xFFFFFFFF possible values, and be sortable by
* PHP sort functions using SORT_REGULAR.
*
* @param string
* @return mixed A sortable format with 0xFFFFFFFF possible values
*/
public function hash($string);
}
... ...
<?php
/**
* Uses CRC32 to hash a value into a 32bit binary string data address space.
*
* @author Paul Annesley
* @package Flexihash
* @licence http://www.opensource.org/licenses/mit-license.php
*/
class Q_Core_Flexi_Md5 implements Q_Core_Flexi_Hasher {
/* (non-phpdoc)
* @see Flexihash_Hasher::hash()
*/
public function hash($string) {
return substr(md5($string), 0, 8); // 8 hexits = 32bit
// 4 bytes of binary md5 data could also be used, but
// performance seems to be the same.
}
}
\ No newline at end of file
... ...
<?php
class Q_Core_Pipe_BigPipe {
public function setPage(){
}
public function addPage(){
}
public function render(){
}
}
//UIPagelet()
\ No newline at end of file
... ...
<?php
class Q_Core_Pipe_Pagelet {
public function setSrc(){
}
public function setWrapperId(){
}
}
\ No newline at end of file
... ...
<?php
/**
* Created by PhpStorm.
* User: liuziyang
* Date: 14-1-19
* Time: 15:23
*/
class Q_Core_Session implements Q_Core_SessionHandlerInterface
{
const SESSION_PREFIX = 'qin.session';
private $maxLifeTime = 1800;
public function __construct($maxLifeTime = 1800, $cookieDomain = NULL)
{
if (phpversion() >= '5.4') {
register_shutdown_function('session_write_close');
}
$this->maxLifeTime = (int)$maxLifeTime;
// 设置生存周期
ini_set('session.gc_maxlifetime', $this->maxLifeTime);
// 设置域
$_cookieDomain = $this->currentDomain();
if ($cookieDomain != null || !empty($cookieDomain)) {
$_cookieDomain = $cookieDomain;
}
ini_set('session.cookie_domain', $_cookieDomain);
ini_set('session.use_cookies', 1);
ini_set('session.cookie_path', '/');
}
public function _cache()
{
return Q_Cache::factory('Memcached')->setPrefix(self::SESSION_PREFIX);
}
/**
* 获取Domain
* @return string
*/
public function currentDomain()
{
if (!isset($_SERVER['HTTP_HOST'])) {
return '';
}
if (ip2long($_SERVER['HTTP_HOST']) == false) {
return '.' . preg_replace("/^(.*\.)?([^.]*\..*)$/", "$2", $_SERVER['HTTP_HOST']);
}
return $_SERVER['HTTP_HOST'];
}
public function close()
{
return true;
}
public function destroy($sessionID)
{
return $this->_cache()->delete($sessionID);
}
public function gc($maxlifetime)
{
return true;
}
public function open($savePath, $sessionID)
{
return true;
}
public function read($sessionID)
{
$return = '';
$sessionData = $this->_cache()->get($sessionID);
if ($sessionData) {
if ((int)($sessionData['modified'] + $this->maxLifeTime) > time()) {
$return = $sessionData['data'];
} else {
$this->destroy($sessionID);
}
}
return $return;
}
public function write($sessionID, $sessionData)
{
$sessionDate = array('modified' => time(), 'data' => (string)$sessionData, 'lifetime' => $this->maxLifeTime);
return $this->_cache()->set($sessionID, $sessionDate, $this->maxLifeTime);
}
public function __destruct()
{
session_write_close();
}
/**
* 开启Session并设置NameSpace
*/
static function start($namespace)
{
$sessionID = session_id();
if (empty($sessionID)) {
$qinSession = new Q_Core_Session();
session_set_save_handler(
array(&$qinSession, "open"),
array(&$qinSession, "close"),
array(&$qinSession, "read"),
array(&$qinSession, "write"),
array(&$qinSession, "destroy"),
array(&$qinSession, "gc")
);
session_start();
}
return new Q_Core_SessionNamespace ($namespace);
}
/**
* 开启session
*/
static function sessionStart()
{
$sessionID = session_id();
if (empty($sessionID)) {
$qinSession = new Q_Core_Session();
session_set_save_handler(
array(&$qinSession, "open"),
array(&$qinSession, "close"),
array(&$qinSession, "read"),
array(&$qinSession, "write"),
array(&$qinSession, "destroy"),
array(&$qinSession, "gc")
);
session_start();
}
}
}
\ No newline at end of file
... ...
<?php
/**
* Created by PhpStorm.
* User: liuziyang
* Date: 14-2-23
* Time: 17:45
*/
interface Q_Core_SessionHandlerInterface
{
/**
* PHP >= 5.4.0<br/>
* Close the session
* @link http://php.net/manual/en/sessionhandlerinterafce.close.php
* @return bool <p>
* The return value (usually TRUE on success, FALSE on failure).
* Note this value is returned internally to PHP for processing.
* </p>
*/
public function close();
/**
* PHP >= 5.4.0<br/>
* Destroy a session
* @link http://php.net/manual/en/sessionhandlerinterafce.destroy.php
* @param int $session_id The session ID being destroyed.
* @return bool <p>
* The return value (usually TRUE on success, FALSE on failure).
* Note this value is returned internally to PHP for processing.
* </p>
*/
public function destroy($session_id);
/**
* PHP >= 5.4.0<br/>
* Cleanup old sessions
* @link http://php.net/manual/en/sessionhandlerinterafce.gc.php
* @param int $maxlifetime <p>
* Sessions that have not updated for
* the last maxlifetime seconds will be removed.
* </p>
* @return bool <p>
* The return value (usually TRUE on success, FALSE on failure).
* Note this value is returned internally to PHP for processing.
* </p>
*/
public function gc($maxlifetime);
/**
* PHP >= 5.4.0<br/>
* Initialize session
* @link http://php.net/manual/en/sessionhandlerinterafce.open.php
* @param string $save_path The path where to store/retrieve the session.
* @param string $session_id The session id.
* @return bool <p>
* The return value (usually TRUE on success, FALSE on failure).
* Note this value is returned internally to PHP for processing.
* </p>
*/
public function open($save_path, $session_id);
/**
* PHP >= 5.4.0<br/>
* Read session data
* @link http://php.net/manual/en/sessionhandlerinterafce.read.php
* @param string $session_id The session id to read data for.
* @return string <p>
* Returns an encoded string of the read data.
* If nothing was read, it must return an empty string.
* Note this value is returned internally to PHP for processing.
* </p>
*/
public function read($session_id);
/**
* PHP >= 5.4.0<br/>
* Write session data
* @link http://php.net/manual/en/sessionhandlerinterafce.write.php
* @param string $session_id The session id.
* @param string $session_data <p>
* The encoded session data. This data is the
* result of the PHP internally encoding
* the $_SESSION superglobal to a serialized
* string and passing it as this parameter.
* Please note sessions use an alternative serialization method.
* </p>
* @return bool <p>
* The return value (usually TRUE on success, FALSE on failure).
* Note this value is returned internally to PHP for processing.
* </p>
*/
public function write($session_id, $session_data);
}
\ No newline at end of file
... ...