Giter VIP home page Giter VIP logo

-alogic-xscript-kvalue's Introduction

alogic-xscript-kvalue

Overview

alogic-xscript-kvalue是基于xscript2.0的kvalue插件,提供了使用kvalue所需的相关指令,无缝对接redis等kvalue实现。

Getting started

按照以下步骤,您可轻松在您的项目中使用alogic-xscript-kvalue.

不过开始之前,我们希望您了解xscript的相关知识。

增加maven依赖

您可以在**仓库上找到alogic-xscript-kvalue的发布版本。

    <dependency>
        <groupId>com.github.anylogic</groupId>
        <artifactId>alogic-xscript-kvalue</artifactId>
        <version>1.6.5-20160826</version>
    </dependency>   	

alogic-xscript-kvalue版本号前面的1.6.5是其所依赖的alogic-kvalue的版本号,后面的20160826是其发布的日期。

引入Namespace

在您的脚本中,你需要引入kvalue作为Namespace,比如:

	
	<using xmlTag = "kv-row" module="com.alogic.xscript.kvalue.KVRow"/>
	
	<kv-row schema="demo" table="hash" key="test">
		<!--下面是针对指定row的操作-->
	</kv-row

或者

	<script>
        <using xmlTag="kv-schema" module="com.alogic.xscript.kvalue.KVSchema"/>

        <kv-schema schema="demo">
            <!--下面是针对kvalue数据库demo的操作-->
        </kv-schema>
    </script>

或者

	<script>
        <using xmlTag="kv-table" module="com.alogic.xscript.kvalue.KVTable"/>

        <kv-table schema="demo" table="str">
            <!--下面是对demo下str表的操作-->
        </kv-table>
    </script>

Example

下面的案例是对redis缓存的Hash类型的操作.

	<script>
		<using xmlTag = "kv-row" module="com.alogic.xscript.kvalue.KVRow"/>
		
		<array tag="log">
			<kv-row schema="demo" table="hash" key="test">
				<kv-hmset values="id;alogic;name;ketty;note;it's a web server"/>
				
				<array-item><get id="result" value="${$kv-hmset}"/></array-item>
				
				<kv-hset key="address" value="192.168.1.23"/>
				<array-item><get id="result" value="${$kv-hset}"/></array-item>
				
				<kv-hget key="note"/>
				<array-item><get id="result" value="${$kv-hget}"/></array-item>
				
				<kv-hmget tag="mget" keys="id;name"/>
				
				<kv-hgetall tag="getall"/>
			</kv-row>
		</array>
		
	</script>	

为了运行上面的指令,你必须要做下列工作:

  • 启动一个redis服务器;
  • 在环境变量中配置redis服务器的地址和端口,参考settings.xml;
	<?xml version="1.0"?>
	<settings>
		<parameter id="kvalue.master" value="java:///conf/kvalue.xml#App" />
		<parameter id="redis.server0.ip" value="localhost" final="true"/>
		<parameter id="redis.server0.port" value="6379" final="true"/>
	</settings>	
  • 指定一个kvalue配置文件,参考kvalue.xml;
	<?xml version="1.0" encoding="UTF-8"?>
	<kvdb>
		<context>
			<schema id="demo" module="com.logicbus.redis.kvalue.RedisSchema">
				<redis.source module="com.logicbus.redis.context.InnerContext">
					<rcp id = "redis0" host="${redis.server0.ip}" port="${redis.server0.port}" defaultDB="0" maxIdle="20" maxActive="100"/>
				</redis.source>
				<redis.tables>
					<table name="zset" possessive="false" dataType="SortedSet">
						<partitioner module="com.logicbus.kvalue.common.SimpleHash" nodesCnt="1">
							<partition src="redis0"/>
							<partitions>
								<partition case="0" src="redis0"/>
							</partitions>
						</partitioner>									 
					</table>	
					<table name="hash" possessive="false" dataType="Hash">
						<partitioner module="com.logicbus.kvalue.common.SimpleHash" nodesCnt="1">
							<partition src="redis0"/>
							<partitions>
								<partition case="0" src="redis0"/>
							</partitions>
						</partitioner>									 
					</table>	
					<table name="str" possessive="false" dataType="String">
						<partitioner module="com.logicbus.kvalue.common.SimpleHash" nodesCnt="1">
							<partition src="redis0"/>
							<partitions>
								<partition case="0" src="redis0"/>
							</partitions>
						</partitioner>									 
					</table>
					<table name="list" possessive="false" dataType="List">
						<partitioner module="com.logicbus.kvalue.common.SimpleHash" nodesCnt="1">
							<partition src="redis0"/>
							<partitions>
								<partition case="0" src="redis0"/>
							</partitions>
						</partitioner>									 
					</table>										
				</redis.tables>
			</schema>
		</context>
	</kvdb>

在上面的配置文件中,创建一个名为demo的schema,并在其中创建了4张表(zset,hash,str,list),分别用于测试SortedSet,Hash,String,List等4种常见的redis数据类型。

做好上面的工作之后,可以运行demo来测试xscript脚本。

Reference

参见alogic-xscript-kvalue参考

History

  • 0.0.1 [20160804 duanyy]
    • 初次发布
  • 1.6.5 [20160810 duanyy]
    • 更改版本为1.6.5,和alogic-kvalue保持一致;
    • 增加list类型的相关插件(1.6.5.1)
    • 发布20160826版本

-alogic-xscript-kvalue's People

Contributors

yyduan avatar zhong9257 avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.