コード例 #1
0
def main():
    glb = rg_global.RgGlobal('sync_demo')
    glb.connect_sync(rg_mom_common.Db.RGMOMD_HOST)
    mom = rg_mom_sync.RgMomSync(glb)
    master = rg_thread.RgThreadMaster(glb)

    demo = mom_test.Demo()
    demo.index = mom_test.DemoIndex()
    demo.index.index1 = '111'
    demo.index.index2 = '111'
    demo.v1 = 1.111
    mom.lpush(rg_mom_common.Db.RGMOMD_HOST, demo, 1)

    demo2 = mom_test.Demo()
    demo2.index = mom_test.DemoIndex()
    demo2.index.index1 = '111'
    demo2.index.index2 = '111'
    demo2.v1 = 2.222

    # 不应该报入参错误
    mom.linsert(rg_mom_common.Db.RGMOMD_HOST, demo, demo2, 1)

    def cb(t):
        os._exit(0)

    master.add_timer(cb, None, 1)
    glb.run()
コード例 #2
0
def main():
    glb = rg_global.RgGlobal('sync_demo')
    glb.connect_sync(rg_mom_common.Db.RGMOMD_HOST)
    mom = rg_mom_sync.RgMomSync(glb)
    master = rg_thread.RgThreadMaster(glb)

    demo = mom_test.Demo()
    demo.index = mom_test.DemoIndex()
    demo.index.index1 = '111'
    demo.index.index2 = '111'
    demo.v1 = 1.111
    ret = mom.lpop(rg_mom_common.Db.RGMOMD_HOST, demo)
    assert (ret == None)
    ret = mom.rpop(rg_mom_common.Db.RGMOMD_HOST, demo)
    assert (ret == None)

    mom.lpush(rg_mom_common.Db.RGMOMD_HOST, demo, 1)
    mom.lpush(rg_mom_common.Db.RGMOMD_HOST, demo, 1)
    ret = mom.lpop(rg_mom_common.Db.RGMOMD_HOST, demo)
    assert (ret != None)
    ret = mom.rpop(rg_mom_common.Db.RGMOMD_HOST, demo)
    assert (ret != None)

    ret, _, _ = mom.hgetall(rg_mom_common.Db.RGMOMD_HOST, demo)
    assert (ret == None)
    ret, _, _ = mom.hmget(rg_mom_common.Db.RGMOMD_HOST, demo, [6, 7])
    assert (ret == None)

    def cb(t):
        os._exit(0)

    master.add_timer(cb, None, 1)
    glb.run()
コード例 #3
0
    def __init__(self, glb):
        super(App, self).__init__(glb)  # 模板
        glb.regist_app(self)  # 模板

        self.demo = app_demo.Demo()
        self.demo.index = app_demo.DemoIndex()
        self.demo.index.index1 = 'async'
        self.demo.index.index2 = 'case4'
コード例 #4
0
    def __init__(self, glb):
        super(App, self).__init__(glb)  # 模板
        glb.regist_app(self)  # 模板
        self.thread_master = RgThreadMaster(glb)

        self.demo = app_demo.Demo()
        self.demo.index = app_demo.DemoIndex()
        self.demo.index.index1 = 'async'
        self.demo.index.index2 = 'case6'
コード例 #5
0
 def setUp(self):
     self.glb = rg_global.RgGlobal('sync_demo')
     if self.glb.connect_sync(Db.RGMOMD_HOST) != 0:
         sys.exit()
     self.db = Db.RGMOMD_HOST
     self.mom = rg_mom_sync.RgMomSync(self.glb)
     self.demo = app_demo.Demo()
     self.demo.index = app_demo.DemoIndex()
     self.demo.index.index1 = '111'
     self.demo.index.index2 = '222'
コード例 #6
0
def main():
    glb = rg_global.RgGlobal('sync_demo')
    glb.connect_sync(rg_mom_common.Db.RGMOMD_HOST)
    mom = rg_mom_sync.RgMomSync(glb)
    master = rg_thread.RgThreadMaster(glb)

    demo = mom_test.Demo()
    demo.index = mom_test.DemoIndex()
    demo.index.index1 = '111'
    demo.index.index2 = '111'

    ret, fields, change_fields = mom.hmget(rg_mom_common.Db.RGMOMD_HOST, demo,
                                           [6, 7])
    # 对于不存在的key,返回值应该是None
    assert (ret == None)

    def cb(t):
        os._exit(0)

    master.add_timer(cb, None, 1)
    glb.run()
コード例 #7
0
    def test_sadd(self):
        demo = app_demo.Demo()
        demo.index = app_demo.DemoIndex()
        demo.index.index1 = 's'
        demo.index.index2 = 's'
        for i in range(5):
            demo.v3 = i
            self.mom.sadd(self.db, demo, 1)
        for i in range(5):
            demo.v3 = i
            ret = self.mom.scard(self.db, demo)
            self.assertEqual(ret, 5)
            ret = self.mom.sismember(self.db, demo)
            self.assertEqual(ret, 0)

        demo.v3 = 2
        self.mom.srem(self.db, demo, 1)
        ret = self.mom.scard(self.db, demo)
        self.assertEqual(ret, 4)
        ret = self.mom.sismember(self.db, demo)
        self.assertEqual(ret, 1)
コード例 #8
0
    def test_base(self):
        # 先保证set、get、delete接口是正确的,因为其余的用例基本都要用这两个接口辅助判断
        demo = app_demo.Demo()
        demo.index = app_demo.DemoIndex()
        demo.index.index1 = '111'
        demo.index.index2 = '222'

        # 当前无数据
        demo2 = self.mom.get(self.db, demo)
        self.assertEqual(demo2, None)

        # set数据,get后正确
        demo.v1 = 3.1415
        self.mom.set(self.db, demo, 1)
        demo2 = self.mom.get(self.db, demo)
        self.assertEqual(demo2.index.index1, '111')
        self.assertEqual(demo2.index.index2, '222')
        self.assertEqual(demo2.v1, 3.1415)

        # delete删除数据
        self.mom.delete(self.db, demo, 1)
        demo2 = self.mom.get(self.db, demo)
        self.assertEqual(demo2, None)