赞
踩
1、下载Redis Statck(我采用的是centOS7)
2、上传到服务器,并解压
3、【可选】修改配置文件(我的服务器上目前已经有在用6379端口了,所以需要改配置)
vi ./etc/redis-statck.conf
4、启动服务
./bin/redis-stack-server &
5、连接服务
./bin/redis-cli -p 6679
6、测试
- JSON.SET animal $ '"dog"' //ok
-
- JSON.get animal $ //"[\"dog\"]"
1、引入maven依赖
- <dependency>
- <groupId>redis.clients</groupId>
- <artifactId>jedis</artifactId>
- <version>4.2.0</version>
- </dependency>
2、客户端测试代码
- public static void main(String[] args) {
- HostAndPort config = new HostAndPort("*.*.*.*", 6679);
- PooledConnectionProvider provider = new PooledConnectionProvider(config);
- UnifiedJedis client = new UnifiedJedis(provider);
- Map<Object,Object> data = new HashMap<>();
- data.put("id", "1");
- data.put("name", "userName1");
- client.jsonSet("testdata:1", SerializeUtils.convertMap2JsonString(data));
- data.put("id", "2");
- data.put("name", "userName2");
- client.jsonSet("testdata:2", SerializeUtils.convertMap2JsonString(data));
- client.close();
- }
3、查看数据
4、创建索引
如果想要根据某个属性进行数据查询,那么需要先添加改属性的索引
- public static void createIndex(UnifiedJedis client) {
- Schema schema = new Schema().addTextField("$.id", 1.0).addTextField("$.name", 1.0);
- IndexDefinition rule = new IndexDefinition(IndexDefinition.Type.JSON).setPrefixes(new String[] { "testdata:" });
- client.ftCreate("testdata-index", IndexOptions.defaultOptions().setDefinition(rule), schema);
- }
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。