diff --git a/conf/interpreter-list b/conf/interpreter-list index 38cb386d8cd..9bdd8b2a6f9 100644 --- a/conf/interpreter-list +++ b/conf/interpreter-list @@ -35,4 +35,5 @@ md org.apache.zeppelin:zeppelin-markdown:0.6.1 Markdown pig org.apache.zeppelin:zeppelin-pig:0.6.1 Pig interpreter postgresql org.apache.zeppelin:zeppelin-postgresql:0.6.1 Postgresql interpreter python org.apache.zeppelin:zeppelin-python:0.6.1 Python interpreter +redis org.apache.zeppelin:zeppelin-redis:0.6.1 Redis interpreter shell org.apache.zeppelin:zeppelin-shell:0.6.1 Shell command diff --git a/pom.xml b/pom.xml index 558ce0624a1..187d079d7da 100644 --- a/pom.xml +++ b/pom.xml @@ -75,6 +75,7 @@ elasticsearch bigquery alluxio + redis zeppelin-web zeppelin-server zeppelin-distribution diff --git a/redis/pom.xml b/redis/pom.xml new file mode 100644 index 00000000000..4a171d21242 --- /dev/null +++ b/redis/pom.xml @@ -0,0 +1,125 @@ + + + + + 4.0.0 + + + zeppelin + org.apache.zeppelin + 0.7.0-SNAPSHOT + + + org.apache.zeppelin + zeppelin-redis + 0.7.0-SNAPSHOT + Zeppelin: Redis Interpreter + Zeppelin Redis support + + + 2.9.0 + 1.7.7 + + + + + redis.clients + jedis + ${jedis.version} + + + org.slf4j + log4j-over-slf4j + ${slf4j.version} + + + com.google.guava + guava + + + ${project.groupId} + zeppelin-interpreter + ${project.version} + provided + + + junit + junit + test + + + + + + + maven-enforcer-plugin + 1.3.1 + + + enforce + none + + + + + + maven-dependency-plugin + 2.8 + + + copy-dependencies + package + + copy-dependencies + + + ${project.build.directory}/../../interpreter/redis + false + false + true + runtime + + + + copy-artifact + package + + copy + + + ${project.build.directory}/../../interpreter/redis + false + false + true + runtime + + + ${project.groupId} + ${project.artifactId} + ${project.version} + ${project.packaging} + + + + + + + + + diff --git a/redis/src/main/java/org/apache/zeppelin/redis/RedisInterpreter.java b/redis/src/main/java/org/apache/zeppelin/redis/RedisInterpreter.java new file mode 100644 index 00000000000..1a277eded71 --- /dev/null +++ b/redis/src/main/java/org/apache/zeppelin/redis/RedisInterpreter.java @@ -0,0 +1,328 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.zeppelin.redis; + +import com.google.common.base.Strings; +import com.google.common.collect.Lists; +import com.google.common.collect.Maps; +import org.apache.zeppelin.interpreter.Interpreter; +import org.apache.zeppelin.interpreter.InterpreterContext; +import org.apache.zeppelin.interpreter.InterpreterResult; +import org.apache.zeppelin.redis.command.RedisCommand; +import org.apache.zeppelin.redis.command.geo.GEOADDCommand; +import org.apache.zeppelin.redis.command.geo.GEODISTCommand; +import org.apache.zeppelin.redis.command.geo.GEOHASHCommand; +import org.apache.zeppelin.redis.command.geo.GEOPOSCommand; +import org.apache.zeppelin.redis.command.geo.GEORADIUSBYMEMBERCommand; +import org.apache.zeppelin.redis.command.geo.GEORADIUSCommand; +import org.apache.zeppelin.redis.command.hash.HDELCommand; +import org.apache.zeppelin.redis.command.hash.HEXISTSCommand; +import org.apache.zeppelin.redis.command.hash.HGETALLCommand; +import org.apache.zeppelin.redis.command.hash.HGETCommand; +import org.apache.zeppelin.redis.command.hash.HINCRBYCommand; +import org.apache.zeppelin.redis.command.hash.HINCRBYFLOATCommand; +import org.apache.zeppelin.redis.command.hash.HKEYSCommand; +import org.apache.zeppelin.redis.command.hash.HLENCommand; +import org.apache.zeppelin.redis.command.hash.HMGETCommand; +import org.apache.zeppelin.redis.command.hash.HMSETCommand; +import org.apache.zeppelin.redis.command.hash.HSCANCommand; +import org.apache.zeppelin.redis.command.hash.HSETCommand; +import org.apache.zeppelin.redis.command.hash.HSETNXCommand; +import org.apache.zeppelin.redis.command.hash.HVALSCommand; +import org.apache.zeppelin.redis.command.hyperloglog.PFADDCommand; +import org.apache.zeppelin.redis.command.hyperloglog.PFCOUNTCommand; +import org.apache.zeppelin.redis.command.hyperloglog.PFMERGECommand; +import org.apache.zeppelin.redis.command.key.*; +import org.apache.zeppelin.redis.command.list.*; +import org.apache.zeppelin.redis.command.set.SADDCommand; +import org.apache.zeppelin.redis.command.set.SCARDCommand; +import org.apache.zeppelin.redis.command.set.SDIFFCommand; +import org.apache.zeppelin.redis.command.set.SDIFFSTORECommand; +import org.apache.zeppelin.redis.command.set.SINTERCommand; +import org.apache.zeppelin.redis.command.set.SINTERSTORECommand; +import org.apache.zeppelin.redis.command.set.SISMEMBERCommand; +import org.apache.zeppelin.redis.command.set.SMEMBERSCommand; +import org.apache.zeppelin.redis.command.set.SMOVECommand; +import org.apache.zeppelin.redis.command.set.SPOPCommand; +import org.apache.zeppelin.redis.command.set.SRANDMEMBERCommand; +import org.apache.zeppelin.redis.command.set.SREMCommand; +import org.apache.zeppelin.redis.command.set.SSCANCommand; +import org.apache.zeppelin.redis.command.set.SUNIONCommand; +import org.apache.zeppelin.redis.command.set.SUNIONSTORECommand; +import org.apache.zeppelin.redis.command.set.sorted.*; +import org.apache.zeppelin.redis.command.string.*; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import redis.clients.jedis.JedisPool; +import redis.clients.jedis.JedisPoolConfig; +import redis.clients.jedis.Protocol; + +import java.util.List; +import java.util.Map; +import java.util.Properties; + +import static org.apache.zeppelin.interpreter.InterpreterResult.Code.ERROR; + +/** + * Redis interpreter for Zeppelin. + */ +public class RedisInterpreter extends Interpreter { + + private static final Logger LOG = LoggerFactory.getLogger(RedisInterpreter.class); + + private static final char SPACE = ' '; + private static final char DOUBLE_QUOTATION = '\"'; + + private static final String REDIS_HOST = "redis.host"; + private static final String REDIS_PORT = "redis.port"; + + private String host = Protocol.DEFAULT_HOST; + private int port = Protocol.DEFAULT_PORT; + + private JedisPoolConfig config; + private JedisPool clientPool; + + private static final Map COMMANDS = Maps.newHashMap(); + + public RedisInterpreter(Properties property) { + + super(property); + + if (property.containsKey(REDIS_HOST) && + !Strings.isNullOrEmpty(property.getProperty(REDIS_HOST))) { + host = property.getProperty(REDIS_HOST); + } + + if (property.containsKey(REDIS_PORT) && + !Strings.isNullOrEmpty(property.getProperty(REDIS_PORT))) { + port = Integer.valueOf(property.getProperty(REDIS_PORT)); + } + + LOG.info("Connection to %s:%d", host, port); + + config = new JedisPoolConfig(); + config.setMaxTotal(JedisPoolConfig.DEFAULT_MAX_TOTAL); + config.setMaxIdle(JedisPoolConfig.DEFAULT_MAX_IDLE); + config.setMinIdle(JedisPoolConfig.DEFAULT_MIN_IDLE); + config.setMaxWaitMillis(JedisPoolConfig.DEFAULT_MAX_WAIT_MILLIS); + } + + @Override + public void open() { + clientPool = new JedisPool(config, host, port); + + // GEO Commands + COMMANDS.put(Protocol.Command.GEOADD, new GEOADDCommand(clientPool)); + COMMANDS.put(Protocol.Command.GEODIST, new GEODISTCommand(clientPool)); + COMMANDS.put(Protocol.Command.GEOHASH, new GEOHASHCommand(clientPool)); + COMMANDS.put(Protocol.Command.GEOPOS, new GEOPOSCommand(clientPool)); + COMMANDS.put(Protocol.Command.GEORADIUSBYMEMBER, new GEORADIUSBYMEMBERCommand(clientPool)); + COMMANDS.put(Protocol.Command.GEORADIUS, new GEORADIUSCommand(clientPool)); + + // Hash Commands + COMMANDS.put(Protocol.Command.HDEL, new HDELCommand(clientPool)); + COMMANDS.put(Protocol.Command.HEXISTS, new HEXISTSCommand(clientPool)); + COMMANDS.put(Protocol.Command.HGET, new HGETCommand(clientPool)); + COMMANDS.put(Protocol.Command.HGETALL, new HGETALLCommand(clientPool)); + COMMANDS.put(Protocol.Command.HINCRBY, new HINCRBYCommand(clientPool)); + COMMANDS.put(Protocol.Command.HINCRBYFLOAT, new HINCRBYFLOATCommand(clientPool)); + COMMANDS.put(Protocol.Command.HKEYS, new HKEYSCommand(clientPool)); + COMMANDS.put(Protocol.Command.HLEN, new HLENCommand(clientPool)); + COMMANDS.put(Protocol.Command.HMGET, new HMGETCommand(clientPool)); + COMMANDS.put(Protocol.Command.HMSET, new HMSETCommand(clientPool)); + COMMANDS.put(Protocol.Command.HSET, new HSETCommand(clientPool)); + COMMANDS.put(Protocol.Command.HSETNX, new HSETNXCommand(clientPool)); + COMMANDS.put(Protocol.Command.HVALS, new HVALSCommand(clientPool)); + COMMANDS.put(Protocol.Command.HSCAN, new HSCANCommand(clientPool)); + + // HyperLogLog Commands + COMMANDS.put(Protocol.Command.PFADD, new PFADDCommand(clientPool)); + COMMANDS.put(Protocol.Command.PFCOUNT, new PFCOUNTCommand(clientPool)); + COMMANDS.put(Protocol.Command.PFMERGE, new PFMERGECommand(clientPool)); + + // Key Commands + COMMANDS.put(Protocol.Command.DEL, new DELCommand(clientPool)); + COMMANDS.put(Protocol.Command.DUMP, new DUMPCommand(clientPool)); + COMMANDS.put(Protocol.Command.EXISTS, new EXISTSCommand(clientPool)); + COMMANDS.put(Protocol.Command.EXPIRE, new EXPIRECommand(clientPool)); + COMMANDS.put(Protocol.Command.EXPIREAT, new EXPIREATCommand(clientPool)); + COMMANDS.put(Protocol.Command.KEYS, new KEYSCommand(clientPool)); + COMMANDS.put(Protocol.Command.MIGRATE, new MIGRATECommand(clientPool)); + COMMANDS.put(Protocol.Command.MOVE, new MOVECommand(clientPool)); + COMMANDS.put(Protocol.Command.PERSIST, new PERSISTCommand(clientPool)); + COMMANDS.put(Protocol.Command.PEXPIRE, new PEXPIRECommand(clientPool)); + COMMANDS.put(Protocol.Command.PEXPIREAT, new PEXPIREATCommand(clientPool)); + COMMANDS.put(Protocol.Command.PTTL, new PTTLCommand(clientPool)); + COMMANDS.put(Protocol.Command.RANDOMKEY, new RANDOMKEYCommand(clientPool)); + COMMANDS.put(Protocol.Command.RENAME, new RENAMECommand(clientPool)); + COMMANDS.put(Protocol.Command.RENAMENX, new RENAMENXCommand(clientPool)); + COMMANDS.put(Protocol.Command.RESTORE, new RESTORECommand(clientPool)); + COMMANDS.put(Protocol.Command.SORT, new SORTCommand(clientPool)); + COMMANDS.put(Protocol.Command.TTL, new TTLCommand(clientPool)); + COMMANDS.put(Protocol.Command.TYPE, new TYPECommand(clientPool)); + COMMANDS.put(Protocol.Command.WAIT, new WAITCommand(clientPool)); + COMMANDS.put(Protocol.Command.SCAN, new SCANCommand(clientPool)); + + // List Commands + COMMANDS.put(Protocol.Command.BLPOP, new BLPOPCommand(clientPool)); + COMMANDS.put(Protocol.Command.BRPOP, new BRPOPCommand(clientPool)); + COMMANDS.put(Protocol.Command.BRPOPLPUSH, new BRPOPLPUSHCommand(clientPool)); + COMMANDS.put(Protocol.Command.LINDEX, new LINDEXCommand(clientPool)); + COMMANDS.put(Protocol.Command.LINSERT, new LINSERTCommand(clientPool)); + COMMANDS.put(Protocol.Command.LLEN, new LLENCommand(clientPool)); + COMMANDS.put(Protocol.Command.LPOP, new LPOPCommand(clientPool)); + COMMANDS.put(Protocol.Command.LPUSH, new LPUSHCommand(clientPool)); + COMMANDS.put(Protocol.Command.LPUSHX, new LPUSHXCommand(clientPool)); + COMMANDS.put(Protocol.Command.LRANGE, new LRANGECommand(clientPool)); + COMMANDS.put(Protocol.Command.LREM, new LREMCommand(clientPool)); + COMMANDS.put(Protocol.Command.LSET, new LSETCommand(clientPool)); + COMMANDS.put(Protocol.Command.LTRIM, new LTRIMCommand(clientPool)); + COMMANDS.put(Protocol.Command.RPOP, new RPOPCommand(clientPool)); + COMMANDS.put(Protocol.Command.RPOPLPUSH, new RPOPLPUSHCommand(clientPool)); + COMMANDS.put(Protocol.Command.RPUSH, new RPUSHCommand(clientPool)); + COMMANDS.put(Protocol.Command.RPUSHX, new RPUSHXCommand(clientPool)); + + // Set Commands + COMMANDS.put(Protocol.Command.SADD, new SADDCommand(clientPool)); + COMMANDS.put(Protocol.Command.SCARD, new SCARDCommand(clientPool)); + COMMANDS.put(Protocol.Command.SDIFF, new SDIFFCommand(clientPool)); + COMMANDS.put(Protocol.Command.SDIFFSTORE, new SDIFFSTORECommand(clientPool)); + COMMANDS.put(Protocol.Command.SINTER, new SINTERCommand(clientPool)); + COMMANDS.put(Protocol.Command.SINTERSTORE, new SINTERSTORECommand(clientPool)); + COMMANDS.put(Protocol.Command.SISMEMBER, new SISMEMBERCommand(clientPool)); + COMMANDS.put(Protocol.Command.SMEMBERS, new SMEMBERSCommand(clientPool)); + COMMANDS.put(Protocol.Command.SMOVE, new SMOVECommand(clientPool)); + COMMANDS.put(Protocol.Command.SPOP, new SPOPCommand(clientPool)); + COMMANDS.put(Protocol.Command.SRANDMEMBER, new SRANDMEMBERCommand(clientPool)); + COMMANDS.put(Protocol.Command.SREM, new SREMCommand(clientPool)); + COMMANDS.put(Protocol.Command.SUNION, new SUNIONCommand(clientPool)); + COMMANDS.put(Protocol.Command.SUNIONSTORE, new SUNIONSTORECommand(clientPool)); + COMMANDS.put(Protocol.Command.SSCAN, new SSCANCommand(clientPool)); + + // Sorted Set Commands + COMMANDS.put(Protocol.Command.ZADD, new ZADDCommand(clientPool)); + COMMANDS.put(Protocol.Command.ZCARD, new ZCARDCommand(clientPool)); + COMMANDS.put(Protocol.Command.ZCOUNT, new ZCOUNTCommand(clientPool)); + COMMANDS.put(Protocol.Command.ZINCRBY, new ZINCRBYCommand(clientPool)); + COMMANDS.put(Protocol.Command.ZINTERSTORE, new ZINTERSTORECommand(clientPool)); + COMMANDS.put(Protocol.Command.ZLEXCOUNT, new ZLEXCOUNTCommand(clientPool)); + COMMANDS.put(Protocol.Command.ZRANGE, new ZRANGECommand(clientPool)); + COMMANDS.put(Protocol.Command.ZRANGEBYLEX, new ZRANGEBYLEXCommand(clientPool)); + COMMANDS.put(Protocol.Command.ZREVRANGEBYLEX, new ZREVRANGEBYLEXCommand(clientPool)); + COMMANDS.put(Protocol.Command.ZRANGEBYSCORE, new ZRANGEBYSCORECommand(clientPool)); + COMMANDS.put(Protocol.Command.ZRANK, new ZRANKCommand(clientPool)); + COMMANDS.put(Protocol.Command.ZREM, new ZREMCommand(clientPool)); + COMMANDS.put(Protocol.Command.ZREMRANGEBYLEX, new ZREMRANGEBYLEXCommand(clientPool)); + COMMANDS.put(Protocol.Command.ZREMRANGEBYRANK, new ZREMRANGEBYRANKCommand(clientPool)); + COMMANDS.put(Protocol.Command.ZREMRANGEBYSCORE, new ZREMRANGEBYSCORECommand(clientPool)); + COMMANDS.put(Protocol.Command.ZREVRANGE, new ZREVRANGECommand(clientPool)); + COMMANDS.put(Protocol.Command.ZREVRANGEBYSCORE, new ZREVRANGEBYSCORECommand(clientPool)); + COMMANDS.put(Protocol.Command.ZREVRANK, new ZREVRANKCommand(clientPool)); + COMMANDS.put(Protocol.Command.ZSCORE, new ZSCORECommand(clientPool)); + COMMANDS.put(Protocol.Command.ZUNIONSTORE, new ZUNIONSTORECommand(clientPool)); + COMMANDS.put(Protocol.Command.ZSCAN, new ZSCANCommand(clientPool)); + + // String Commands + COMMANDS.put(Protocol.Command.APPEND, new APPENDCommand(clientPool)); + COMMANDS.put(Protocol.Command.BITCOUNT, new BITCOUNTCommand(clientPool)); + COMMANDS.put(Protocol.Command.BITFIELD, new BITFIELDCommand(clientPool)); + COMMANDS.put(Protocol.Command.BITOP, new BITOPCommand(clientPool)); + COMMANDS.put(Protocol.Command.BITPOS, new BITPOSCommand(clientPool)); + COMMANDS.put(Protocol.Command.DECRBY, new DECRBYCommand(clientPool)); + COMMANDS.put(Protocol.Command.DECR, new DECRCommand(clientPool)); + COMMANDS.put(Protocol.Command.GETBIT, new GETBITCommand(clientPool)); + COMMANDS.put(Protocol.Command.GET, new GETCommand(clientPool)); + COMMANDS.put(Protocol.Command.GETRANGE, new GETRANGECommand(clientPool)); + COMMANDS.put(Protocol.Command.GETSET, new GETSETCommand(clientPool)); + COMMANDS.put(Protocol.Command.INCRBY, new INCRBYCommand(clientPool)); + COMMANDS.put(Protocol.Command.INCRBYFLOAT, new INCRBYFLOATCommand(clientPool)); + COMMANDS.put(Protocol.Command.INCR, new INCRCommand(clientPool)); + COMMANDS.put(Protocol.Command.MGET, new MGETCommand(clientPool)); + COMMANDS.put(Protocol.Command.MSET, new MSETCommand(clientPool)); + COMMANDS.put(Protocol.Command.MSETNX, new MSETNXCommand(clientPool)); + COMMANDS.put(Protocol.Command.PSETEX, new PSETEXCommand(clientPool)); + COMMANDS.put(Protocol.Command.SETBIT, new SETBITCommand(clientPool)); + COMMANDS.put(Protocol.Command.SET, new SETCommand(clientPool)); + COMMANDS.put(Protocol.Command.SETEX, new SETEXCommand(clientPool)); + COMMANDS.put(Protocol.Command.SETNX, new SETNXCommand(clientPool)); + COMMANDS.put(Protocol.Command.SETRANGE, new SETRANGECommand(clientPool)); + COMMANDS.put(Protocol.Command.STRLEN, new STRLENCommand(clientPool)); + } + + @Override + public InterpreterResult interpret(String input, InterpreterContext context) { + String[] tokens = splitTokens(input); + String keyword = tokens[0].toUpperCase(); + + InterpreterResult result; + Protocol.Command command = Protocol.Command.valueOf(keyword); + if (COMMANDS.containsKey(command)) { + result = COMMANDS.get(command).execute(tokens); + } else { + result = new InterpreterResult(ERROR, "Keyword " + tokens + " is not supported"); + } + + return result; + } + + private String[] splitTokens(String input) { + List list = Lists.newArrayList(); + int start = 0; + boolean flag = false; + + for (int index = 0; index < input.length(); index++) { + if (input.charAt(index) == DOUBLE_QUOTATION) { + flag = !flag; + } + + if (input.charAt(index) == SPACE && !flag) { + String token = input.substring(start, index); + if (!Strings.isNullOrEmpty(token.trim())) { + list.add(token); + } + start = index + 1; + } + } + + list.add(input.substring(start, input.length())); + String[] result = new String[list.size()]; + return list.toArray(result); + } + + @Override + public void cancel(InterpreterContext context) { + + } + + @Override + public FormType getFormType() { + return FormType.SIMPLE; + } + + @Override + public int getProgress(InterpreterContext context) { + return 0; + } + + @Override + public void close() { + if (clientPool != null && clientPool.isClosed()) { + clientPool.close(); + } + } +} diff --git a/redis/src/main/java/org/apache/zeppelin/redis/command/RedisCommand.java b/redis/src/main/java/org/apache/zeppelin/redis/command/RedisCommand.java new file mode 100644 index 00000000000..7fffdbe4405 --- /dev/null +++ b/redis/src/main/java/org/apache/zeppelin/redis/command/RedisCommand.java @@ -0,0 +1,66 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.zeppelin.redis.command; + +import org.apache.zeppelin.interpreter.InterpreterResult; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import redis.clients.jedis.Jedis; +import redis.clients.jedis.JedisPool; +import redis.clients.jedis.exceptions.JedisException; + +import static org.apache.zeppelin.interpreter.InterpreterResult.Code.ERROR; +import static org.apache.zeppelin.interpreter.InterpreterResult.Code.SUCCESS; + +/** + * Redis Base Command + */ +public abstract class RedisCommand { + + private static final Logger LOG = LoggerFactory.getLogger(RedisCommand.class); + private JedisPool clientPool; + + public RedisCommand(JedisPool clientPool) { + this.clientPool = clientPool; + } + + public InterpreterResult execute(String[] tokens) { + try (Jedis client = clientPool.getResource()) { + try { + return new InterpreterResult(SUCCESS, execute(client, tokens)); + } catch (JedisException exception) { + LOG.error("Couldn't execute redis command {}", tokens[0], exception); + return new InterpreterResult(ERROR, exception.getMessage()); + } + } + } + + protected String[] copy(String[] tokens, int start) { + String[] elements = new String[tokens.length - start]; + System.arraycopy(tokens, start, elements, 0, tokens.length - start); + return elements; + } + + /** + * @param tokens + * @return + * @throws Exception + */ + protected abstract String execute(Jedis client, String[] tokens); + +} diff --git a/redis/src/main/java/org/apache/zeppelin/redis/command/geo/GEOADDCommand.java b/redis/src/main/java/org/apache/zeppelin/redis/command/geo/GEOADDCommand.java new file mode 100644 index 00000000000..e1bb808458d --- /dev/null +++ b/redis/src/main/java/org/apache/zeppelin/redis/command/geo/GEOADDCommand.java @@ -0,0 +1,39 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.zeppelin.redis.command.geo; + +import org.apache.zeppelin.redis.command.RedisCommand; +import redis.clients.jedis.Jedis; +import redis.clients.jedis.JedisPool; + +/** + * Add one or more geospatial items in the geospatial index represented using a sorted set + */ +public class GEOADDCommand extends RedisCommand { + + public GEOADDCommand(JedisPool clientPool) { + super(clientPool); + } + + @Override + protected String execute(Jedis client, String[] tokens) { + String result = client.geoadd(tokens[1], Double.valueOf(tokens[2]), + Double.valueOf(tokens[3]), tokens[4]).toString(); + return result; + } +} diff --git a/redis/src/main/java/org/apache/zeppelin/redis/command/geo/GEODISTCommand.java b/redis/src/main/java/org/apache/zeppelin/redis/command/geo/GEODISTCommand.java new file mode 100644 index 00000000000..f1822c078b2 --- /dev/null +++ b/redis/src/main/java/org/apache/zeppelin/redis/command/geo/GEODISTCommand.java @@ -0,0 +1,38 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.zeppelin.redis.command.geo; + +import org.apache.zeppelin.redis.command.RedisCommand; +import redis.clients.jedis.Jedis; +import redis.clients.jedis.JedisPool; + +/** + * Returns the distance between two members of a geospatial index + */ +public class GEODISTCommand extends RedisCommand { + + public GEODISTCommand(JedisPool clientPool) { + super(clientPool); + } + + @Override + protected String execute(Jedis client, String[] tokens) { + String result = client.geodist(tokens[1], tokens[2], tokens[3]).toString(); + return result; + } +} diff --git a/redis/src/main/java/org/apache/zeppelin/redis/command/geo/GEOHASHCommand.java b/redis/src/main/java/org/apache/zeppelin/redis/command/geo/GEOHASHCommand.java new file mode 100644 index 00000000000..c2a8f28ee4e --- /dev/null +++ b/redis/src/main/java/org/apache/zeppelin/redis/command/geo/GEOHASHCommand.java @@ -0,0 +1,40 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.zeppelin.redis.command.geo; + +import org.apache.zeppelin.redis.command.RedisCommand; +import redis.clients.jedis.Jedis; +import redis.clients.jedis.JedisPool; + +/** + * Returns members of a geospatial index as standard geohash strings + */ +public class GEOHASHCommand extends RedisCommand { + + public GEOHASHCommand(JedisPool clientPool) { + super(clientPool); + } + + @Override + protected String execute(Jedis client, String[] tokens) { + String[] members = new String[tokens.length - 2]; + System.arraycopy(tokens, 2, members, 0, tokens.length - 2); + String result = client.geohash(tokens[1], members).toString(); + return result; + } +} diff --git a/redis/src/main/java/org/apache/zeppelin/redis/command/geo/GEOPOSCommand.java b/redis/src/main/java/org/apache/zeppelin/redis/command/geo/GEOPOSCommand.java new file mode 100644 index 00000000000..d46e537a496 --- /dev/null +++ b/redis/src/main/java/org/apache/zeppelin/redis/command/geo/GEOPOSCommand.java @@ -0,0 +1,40 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.zeppelin.redis.command.geo; + +import org.apache.zeppelin.redis.command.RedisCommand; +import redis.clients.jedis.Jedis; +import redis.clients.jedis.JedisPool; + +/** + * Returns longitude and latitude of members of a geospatial index + */ +public class GEOPOSCommand extends RedisCommand { + + public GEOPOSCommand(JedisPool clientPool) { + super(clientPool); + } + + @Override + protected String execute(Jedis client, String[] tokens) { + String[] members = new String[tokens.length - 2]; + System.arraycopy(tokens, 2, members, 0, tokens.length - 2); + String result = client.geopos(tokens[1], members).toString(); + return result; + } +} diff --git a/redis/src/main/java/org/apache/zeppelin/redis/command/geo/GEORADIUSBYMEMBERCommand.java b/redis/src/main/java/org/apache/zeppelin/redis/command/geo/GEORADIUSBYMEMBERCommand.java new file mode 100644 index 00000000000..a1bce8b650c --- /dev/null +++ b/redis/src/main/java/org/apache/zeppelin/redis/command/geo/GEORADIUSBYMEMBERCommand.java @@ -0,0 +1,42 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.zeppelin.redis.command.geo; + +import org.apache.zeppelin.redis.command.RedisCommand; +import redis.clients.jedis.GeoUnit; +import redis.clients.jedis.Jedis; +import redis.clients.jedis.JedisPool; + +/** + * Query a sorted set representing a geospatial index to fetch members matching + * a given maximum distance from a member + */ +public class GEORADIUSBYMEMBERCommand extends RedisCommand { + + public GEORADIUSBYMEMBERCommand(JedisPool clientPool) { + super(clientPool); + } + + @Override + protected String execute(Jedis client, String[] tokens) { + String result = client.georadiusByMember(tokens[1], tokens[2], + Double.valueOf(tokens[3]), + GeoUnit.valueOf(tokens[4])).toString(); + return result; + } +} diff --git a/redis/src/main/java/org/apache/zeppelin/redis/command/geo/GEORADIUSCommand.java b/redis/src/main/java/org/apache/zeppelin/redis/command/geo/GEORADIUSCommand.java new file mode 100644 index 00000000000..443c8eaa719 --- /dev/null +++ b/redis/src/main/java/org/apache/zeppelin/redis/command/geo/GEORADIUSCommand.java @@ -0,0 +1,42 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.zeppelin.redis.command.geo; + +import org.apache.zeppelin.redis.command.RedisCommand; +import redis.clients.jedis.GeoUnit; +import redis.clients.jedis.Jedis; +import redis.clients.jedis.JedisPool; + +/** + * Query a sorted set representing a geospatial index to fetch members matching a + * given maximum distance from a point + */ +public class GEORADIUSCommand extends RedisCommand { + + public GEORADIUSCommand(JedisPool clientPool) { + super(clientPool); + } + + @Override + protected String execute(Jedis client, String[] tokens) { + String result = client.georadius(tokens[1], Double.valueOf(tokens[2]), + Double.valueOf(tokens[3]), Double.valueOf(tokens[4]), + GeoUnit.valueOf(tokens[5])).toString(); + return result; + } +} diff --git a/redis/src/main/java/org/apache/zeppelin/redis/command/hash/HDELCommand.java b/redis/src/main/java/org/apache/zeppelin/redis/command/hash/HDELCommand.java new file mode 100644 index 00000000000..1a158c66d97 --- /dev/null +++ b/redis/src/main/java/org/apache/zeppelin/redis/command/hash/HDELCommand.java @@ -0,0 +1,40 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.zeppelin.redis.command.hash; + +import org.apache.zeppelin.redis.command.RedisCommand; +import redis.clients.jedis.Jedis; +import redis.clients.jedis.JedisPool; + +/** + * Delete one or more hash fields + */ +public class HDELCommand extends RedisCommand { + + public HDELCommand(JedisPool clientPool) { + super(clientPool); + } + + @Override + protected String execute(Jedis client, String[] tokens) { + String[] keys = new String[tokens.length - 2]; + System.arraycopy(tokens, 2, keys, 0, tokens.length - 2); + String result = client.hdel(tokens[1], keys).toString(); + return result; + } +} diff --git a/redis/src/main/java/org/apache/zeppelin/redis/command/hash/HEXISTSCommand.java b/redis/src/main/java/org/apache/zeppelin/redis/command/hash/HEXISTSCommand.java new file mode 100644 index 00000000000..4df3ae50c08 --- /dev/null +++ b/redis/src/main/java/org/apache/zeppelin/redis/command/hash/HEXISTSCommand.java @@ -0,0 +1,38 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.zeppelin.redis.command.hash; + +import org.apache.zeppelin.redis.command.RedisCommand; +import redis.clients.jedis.Jedis; +import redis.clients.jedis.JedisPool; + +/** + * Determine if a hash field exists + */ +public class HEXISTSCommand extends RedisCommand { + + public HEXISTSCommand(JedisPool clientPool) { + super(clientPool); + } + + @Override + protected String execute(Jedis client, String[] tokens) { + String result = client.hexists(tokens[1], tokens[2]).toString(); + return result; + } +} diff --git a/redis/src/main/java/org/apache/zeppelin/redis/command/hash/HGETALLCommand.java b/redis/src/main/java/org/apache/zeppelin/redis/command/hash/HGETALLCommand.java new file mode 100644 index 00000000000..aabb45e0dc2 --- /dev/null +++ b/redis/src/main/java/org/apache/zeppelin/redis/command/hash/HGETALLCommand.java @@ -0,0 +1,38 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.zeppelin.redis.command.hash; + +import org.apache.zeppelin.redis.command.RedisCommand; +import redis.clients.jedis.Jedis; +import redis.clients.jedis.JedisPool; + +/** + * Get all the fields and values in a hash + */ +public class HGETALLCommand extends RedisCommand { + + public HGETALLCommand(JedisPool clientPool) { + super(clientPool); + } + + @Override + protected String execute(Jedis client, String[] tokens) { + String result = client.hgetAll(tokens[1]).toString(); + return result; + } +} diff --git a/redis/src/main/java/org/apache/zeppelin/redis/command/hash/HGETCommand.java b/redis/src/main/java/org/apache/zeppelin/redis/command/hash/HGETCommand.java new file mode 100644 index 00000000000..5067a393fb8 --- /dev/null +++ b/redis/src/main/java/org/apache/zeppelin/redis/command/hash/HGETCommand.java @@ -0,0 +1,38 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.zeppelin.redis.command.hash; + +import org.apache.zeppelin.redis.command.RedisCommand; +import redis.clients.jedis.Jedis; +import redis.clients.jedis.JedisPool; + +/** + * Get the value of a hash field + */ +public class HGETCommand extends RedisCommand { + + public HGETCommand(JedisPool clientPool) { + super(clientPool); + } + + @Override + protected String execute(Jedis client, String[] tokens) { + String result = client.hget(tokens[1], tokens[2]); + return result; + } +} diff --git a/redis/src/main/java/org/apache/zeppelin/redis/command/hash/HINCRBYCommand.java b/redis/src/main/java/org/apache/zeppelin/redis/command/hash/HINCRBYCommand.java new file mode 100644 index 00000000000..4846f64b958 --- /dev/null +++ b/redis/src/main/java/org/apache/zeppelin/redis/command/hash/HINCRBYCommand.java @@ -0,0 +1,38 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.zeppelin.redis.command.hash; + +import org.apache.zeppelin.redis.command.RedisCommand; +import redis.clients.jedis.Jedis; +import redis.clients.jedis.JedisPool; + +/** + * Increment the integer value of a hash field by the given number + */ +public class HINCRBYCommand extends RedisCommand { + + public HINCRBYCommand(JedisPool clientPool) { + super(clientPool); + } + + @Override + protected String execute(Jedis client, String[] tokens) { + String result = client.hincrBy(tokens[1], tokens[2], Long.valueOf(tokens[3])).toString(); + return result; + } +} diff --git a/redis/src/main/java/org/apache/zeppelin/redis/command/hash/HINCRBYFLOATCommand.java b/redis/src/main/java/org/apache/zeppelin/redis/command/hash/HINCRBYFLOATCommand.java new file mode 100644 index 00000000000..ada5c6fc5f8 --- /dev/null +++ b/redis/src/main/java/org/apache/zeppelin/redis/command/hash/HINCRBYFLOATCommand.java @@ -0,0 +1,38 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.zeppelin.redis.command.hash; + +import org.apache.zeppelin.redis.command.RedisCommand; +import redis.clients.jedis.Jedis; +import redis.clients.jedis.JedisPool; + +/** + * Increment the float value of a hash field by the given amount + */ +public class HINCRBYFLOATCommand extends RedisCommand { + + public HINCRBYFLOATCommand(JedisPool clientPool) { + super(clientPool); + } + + @Override + protected String execute(Jedis client, String[] tokens) { + String result = client.hincrByFloat(tokens[1], tokens[2], Double.valueOf(tokens[3])).toString(); + return result; + } +} diff --git a/redis/src/main/java/org/apache/zeppelin/redis/command/hash/HKEYSCommand.java b/redis/src/main/java/org/apache/zeppelin/redis/command/hash/HKEYSCommand.java new file mode 100644 index 00000000000..82928f07161 --- /dev/null +++ b/redis/src/main/java/org/apache/zeppelin/redis/command/hash/HKEYSCommand.java @@ -0,0 +1,38 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.zeppelin.redis.command.hash; + +import org.apache.zeppelin.redis.command.RedisCommand; +import redis.clients.jedis.Jedis; +import redis.clients.jedis.JedisPool; + +/** + * Get all the fields in a hash + */ +public class HKEYSCommand extends RedisCommand { + + public HKEYSCommand(JedisPool clientPool) { + super(clientPool); + } + + @Override + protected String execute(Jedis client, String[] tokens) { + String result = client.hkeys(tokens[1]).toString(); + return result; + } +} diff --git a/redis/src/main/java/org/apache/zeppelin/redis/command/hash/HLENCommand.java b/redis/src/main/java/org/apache/zeppelin/redis/command/hash/HLENCommand.java new file mode 100644 index 00000000000..f40d8f5372c --- /dev/null +++ b/redis/src/main/java/org/apache/zeppelin/redis/command/hash/HLENCommand.java @@ -0,0 +1,38 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.zeppelin.redis.command.hash; + +import org.apache.zeppelin.redis.command.RedisCommand; +import redis.clients.jedis.Jedis; +import redis.clients.jedis.JedisPool; + +/** + * Get the number of fields in a hash + */ +public class HLENCommand extends RedisCommand { + + public HLENCommand(JedisPool clientPool) { + super(clientPool); + } + + @Override + protected String execute(Jedis client, String[] tokens) { + String result = client.hlen(tokens[1]).toString(); + return result; + } +} diff --git a/redis/src/main/java/org/apache/zeppelin/redis/command/hash/HMGETCommand.java b/redis/src/main/java/org/apache/zeppelin/redis/command/hash/HMGETCommand.java new file mode 100644 index 00000000000..ea5484ce4d5 --- /dev/null +++ b/redis/src/main/java/org/apache/zeppelin/redis/command/hash/HMGETCommand.java @@ -0,0 +1,40 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.zeppelin.redis.command.hash; + +import org.apache.zeppelin.redis.command.RedisCommand; +import redis.clients.jedis.Jedis; +import redis.clients.jedis.JedisPool; + +/** + * Get the values of all the given hash fields + */ +public class HMGETCommand extends RedisCommand { + + public HMGETCommand(JedisPool clientPool) { + super(clientPool); + } + + @Override + protected String execute(Jedis client, String[] tokens) { + String[] fields = new String[tokens.length - 2]; + System.arraycopy(tokens, 2, fields, 0, tokens.length - 2); + String result = client.hmget(tokens[1], fields).toString(); + return result; + } +} diff --git a/redis/src/main/java/org/apache/zeppelin/redis/command/hash/HMSETCommand.java b/redis/src/main/java/org/apache/zeppelin/redis/command/hash/HMSETCommand.java new file mode 100644 index 00000000000..40f2afd52c8 --- /dev/null +++ b/redis/src/main/java/org/apache/zeppelin/redis/command/hash/HMSETCommand.java @@ -0,0 +1,45 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.zeppelin.redis.command.hash; + +import com.google.common.collect.Maps; +import org.apache.zeppelin.redis.command.RedisCommand; +import redis.clients.jedis.Jedis; +import redis.clients.jedis.JedisPool; + +import java.util.Map; + +/** + * Set multiple hash fields to multiple values + */ +public class HMSETCommand extends RedisCommand { + + public HMSETCommand(JedisPool clientPool) { + super(clientPool); + } + + @Override + protected String execute(Jedis client, String[] tokens) { + Map pairs = Maps.newHashMap(); + for (int index = 2; index < tokens.length; index++) { + pairs.put(tokens[index], tokens[index += 1]); + } + String result = client.hmset(tokens[1], pairs); + return result; + } +} diff --git a/redis/src/main/java/org/apache/zeppelin/redis/command/hash/HSCANCommand.java b/redis/src/main/java/org/apache/zeppelin/redis/command/hash/HSCANCommand.java new file mode 100644 index 00000000000..3f0d8e93d85 --- /dev/null +++ b/redis/src/main/java/org/apache/zeppelin/redis/command/hash/HSCANCommand.java @@ -0,0 +1,38 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.zeppelin.redis.command.hash; + +import org.apache.zeppelin.redis.command.RedisCommand; +import redis.clients.jedis.Jedis; +import redis.clients.jedis.JedisPool; + +/** + * Incrementally iterate hash fields and associated values + */ +public class HSCANCommand extends RedisCommand { + + public HSCANCommand(JedisPool clientPool) { + super(clientPool); + } + + @Override + protected String execute(Jedis client, String[] tokens) { + String result = client.hscan(tokens[1], tokens[2]).toString(); + return result; + } +} diff --git a/redis/src/main/java/org/apache/zeppelin/redis/command/hash/HSETCommand.java b/redis/src/main/java/org/apache/zeppelin/redis/command/hash/HSETCommand.java new file mode 100644 index 00000000000..012ab54391d --- /dev/null +++ b/redis/src/main/java/org/apache/zeppelin/redis/command/hash/HSETCommand.java @@ -0,0 +1,38 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.zeppelin.redis.command.hash; + +import org.apache.zeppelin.redis.command.RedisCommand; +import redis.clients.jedis.Jedis; +import redis.clients.jedis.JedisPool; + +/** + * Set the string value of a hash field + */ +public class HSETCommand extends RedisCommand { + + public HSETCommand(JedisPool clientPool) { + super(clientPool); + } + + @Override + protected String execute(Jedis client, String[] tokens) { + String result = client.hset(tokens[1], tokens[2], tokens[3]).toString(); + return result; + } +} diff --git a/redis/src/main/java/org/apache/zeppelin/redis/command/hash/HSETNXCommand.java b/redis/src/main/java/org/apache/zeppelin/redis/command/hash/HSETNXCommand.java new file mode 100644 index 00000000000..f446bc2aa70 --- /dev/null +++ b/redis/src/main/java/org/apache/zeppelin/redis/command/hash/HSETNXCommand.java @@ -0,0 +1,38 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.zeppelin.redis.command.hash; + +import org.apache.zeppelin.redis.command.RedisCommand; +import redis.clients.jedis.Jedis; +import redis.clients.jedis.JedisPool; + +/** + * Set the value of a hash field, only if the field does not exist + */ +public class HSETNXCommand extends RedisCommand { + + public HSETNXCommand(JedisPool clientPool) { + super(clientPool); + } + + @Override + protected String execute(Jedis client, String[] tokens) { + String result = client.hsetnx(tokens[1], tokens[2], tokens[3]).toString(); + return result; + } +} diff --git a/redis/src/main/java/org/apache/zeppelin/redis/command/hash/HVALSCommand.java b/redis/src/main/java/org/apache/zeppelin/redis/command/hash/HVALSCommand.java new file mode 100644 index 00000000000..16067d3b142 --- /dev/null +++ b/redis/src/main/java/org/apache/zeppelin/redis/command/hash/HVALSCommand.java @@ -0,0 +1,38 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.zeppelin.redis.command.hash; + +import org.apache.zeppelin.redis.command.RedisCommand; +import redis.clients.jedis.Jedis; +import redis.clients.jedis.JedisPool; + +/** + * Get all the values in a hash + */ +public class HVALSCommand extends RedisCommand { + + public HVALSCommand(JedisPool clientPool) { + super(clientPool); + } + + @Override + protected String execute(Jedis client, String[] tokens) { + String result = client.hvals(tokens[1]).toString(); + return result; + } +} diff --git a/redis/src/main/java/org/apache/zeppelin/redis/command/hyperloglog/PFADDCommand.java b/redis/src/main/java/org/apache/zeppelin/redis/command/hyperloglog/PFADDCommand.java new file mode 100644 index 00000000000..c5d688369a2 --- /dev/null +++ b/redis/src/main/java/org/apache/zeppelin/redis/command/hyperloglog/PFADDCommand.java @@ -0,0 +1,40 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.zeppelin.redis.command.hyperloglog; + +import org.apache.zeppelin.redis.command.RedisCommand; +import redis.clients.jedis.Jedis; +import redis.clients.jedis.JedisPool; + +/** + * Adds the specified elements to the specified HyperLogLog. + */ +public class PFADDCommand extends RedisCommand { + + public PFADDCommand(JedisPool clientPool) { + super(clientPool); + } + + @Override + protected String execute(Jedis client, String[] tokens) { + String[] elements = new String[tokens.length - 2]; + System.arraycopy(tokens, 2, elements, 0, tokens.length - 2); + String result = client.pfadd(tokens[1], elements).toString(); + return result; + } +} diff --git a/redis/src/main/java/org/apache/zeppelin/redis/command/hyperloglog/PFCOUNTCommand.java b/redis/src/main/java/org/apache/zeppelin/redis/command/hyperloglog/PFCOUNTCommand.java new file mode 100644 index 00000000000..f17e624fea9 --- /dev/null +++ b/redis/src/main/java/org/apache/zeppelin/redis/command/hyperloglog/PFCOUNTCommand.java @@ -0,0 +1,38 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.zeppelin.redis.command.hyperloglog; + +import org.apache.zeppelin.redis.command.RedisCommand; +import redis.clients.jedis.Jedis; +import redis.clients.jedis.JedisPool; + +/** + * Return the approximated cardinality of the set(s) observed by the HyperLogLog at key(s). + */ +public class PFCOUNTCommand extends RedisCommand { + + public PFCOUNTCommand(JedisPool clientPool) { + super(clientPool); + } + + @Override + protected String execute(Jedis client, String[] tokens) { + String result = client.pfcount(tokens[1]) + ""; + return result; + } +} diff --git a/redis/src/main/java/org/apache/zeppelin/redis/command/hyperloglog/PFMERGECommand.java b/redis/src/main/java/org/apache/zeppelin/redis/command/hyperloglog/PFMERGECommand.java new file mode 100644 index 00000000000..6060d3e9f66 --- /dev/null +++ b/redis/src/main/java/org/apache/zeppelin/redis/command/hyperloglog/PFMERGECommand.java @@ -0,0 +1,40 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.zeppelin.redis.command.hyperloglog; + +import org.apache.zeppelin.redis.command.RedisCommand; +import redis.clients.jedis.Jedis; +import redis.clients.jedis.JedisPool; + +/** + * Merge N different HyperLogLogs into a single one. + */ +public class PFMERGECommand extends RedisCommand { + + public PFMERGECommand(JedisPool clientPool) { + super(clientPool); + } + + @Override + protected String execute(Jedis client, String[] tokens) { + String[] sourcekeys = new String[tokens.length - 2]; + System.arraycopy(tokens, 2, sourcekeys, 0, tokens.length - 2); + String result = client.pfmerge(tokens[1], sourcekeys); + return result; + } +} diff --git a/redis/src/main/java/org/apache/zeppelin/redis/command/key/DELCommand.java b/redis/src/main/java/org/apache/zeppelin/redis/command/key/DELCommand.java new file mode 100644 index 00000000000..5ca212bddb5 --- /dev/null +++ b/redis/src/main/java/org/apache/zeppelin/redis/command/key/DELCommand.java @@ -0,0 +1,40 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.zeppelin.redis.command.key; + +import org.apache.zeppelin.redis.command.RedisCommand; +import redis.clients.jedis.Jedis; +import redis.clients.jedis.JedisPool; + +/** + * Delete a key + */ +public class DELCommand extends RedisCommand { + + public DELCommand(JedisPool clientPool) { + super(clientPool); + } + + @Override + protected String execute(Jedis client, String[] tokens) { + String[] keys = new String[tokens.length - 1]; + System.arraycopy(tokens, 1, keys, 0, tokens.length - 1); + String result = client.del(keys).toString(); + return result; + } +} diff --git a/redis/src/main/java/org/apache/zeppelin/redis/command/key/DUMPCommand.java b/redis/src/main/java/org/apache/zeppelin/redis/command/key/DUMPCommand.java new file mode 100644 index 00000000000..28ee283be7f --- /dev/null +++ b/redis/src/main/java/org/apache/zeppelin/redis/command/key/DUMPCommand.java @@ -0,0 +1,38 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.zeppelin.redis.command.key; + +import org.apache.zeppelin.redis.command.RedisCommand; +import redis.clients.jedis.Jedis; +import redis.clients.jedis.JedisPool; + +/** + * Return a serialized version of the value stored at the specified key. + */ +public class DUMPCommand extends RedisCommand { + + public DUMPCommand(JedisPool clientPool) { + super(clientPool); + } + + @Override + protected String execute(Jedis client, String[] tokens) { + String result = new String(client.dump(tokens[1])); + return result; + } +} diff --git a/redis/src/main/java/org/apache/zeppelin/redis/command/key/EXISTSCommand.java b/redis/src/main/java/org/apache/zeppelin/redis/command/key/EXISTSCommand.java new file mode 100644 index 00000000000..0dbe2f6b864 --- /dev/null +++ b/redis/src/main/java/org/apache/zeppelin/redis/command/key/EXISTSCommand.java @@ -0,0 +1,40 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.zeppelin.redis.command.key; + +import org.apache.zeppelin.redis.command.RedisCommand; +import redis.clients.jedis.Jedis; +import redis.clients.jedis.JedisPool; + +/** + * Determine if a key exists + */ +public class EXISTSCommand extends RedisCommand { + + public EXISTSCommand(JedisPool clientPool) { + super(clientPool); + } + + @Override + protected String execute(Jedis client, String[] tokens) { + String[] keys = new String[tokens.length - 1]; + System.arraycopy(tokens, 1, keys, 0, tokens.length - 1); + String result = client.exists(keys).toString(); + return result; + } +} diff --git a/redis/src/main/java/org/apache/zeppelin/redis/command/key/EXPIREATCommand.java b/redis/src/main/java/org/apache/zeppelin/redis/command/key/EXPIREATCommand.java new file mode 100644 index 00000000000..5cbb333ed4b --- /dev/null +++ b/redis/src/main/java/org/apache/zeppelin/redis/command/key/EXPIREATCommand.java @@ -0,0 +1,38 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.zeppelin.redis.command.key; + +import org.apache.zeppelin.redis.command.RedisCommand; +import redis.clients.jedis.Jedis; +import redis.clients.jedis.JedisPool; + +/** + * Set the expiration for a key as a UNIX timestamp + */ +public class EXPIREATCommand extends RedisCommand { + + public EXPIREATCommand(JedisPool clientPool) { + super(clientPool); + } + + @Override + protected String execute(Jedis client, String[] tokens) { + String result = client.expireAt(tokens[1], Long.valueOf(tokens[2])).toString(); + return result; + } +} diff --git a/redis/src/main/java/org/apache/zeppelin/redis/command/key/EXPIRECommand.java b/redis/src/main/java/org/apache/zeppelin/redis/command/key/EXPIRECommand.java new file mode 100644 index 00000000000..b98ec8b5cf0 --- /dev/null +++ b/redis/src/main/java/org/apache/zeppelin/redis/command/key/EXPIRECommand.java @@ -0,0 +1,38 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.zeppelin.redis.command.key; + +import org.apache.zeppelin.redis.command.RedisCommand; +import redis.clients.jedis.Jedis; +import redis.clients.jedis.JedisPool; + +/** + * Set a key's time to live in seconds + */ +public class EXPIRECommand extends RedisCommand { + + public EXPIRECommand(JedisPool clientPool) { + super(clientPool); + } + + @Override + protected String execute(Jedis client, String[] tokens) { + String result = client.expire(tokens[1], Integer.valueOf(tokens[2])).toString(); + return result; + } +} diff --git a/redis/src/main/java/org/apache/zeppelin/redis/command/key/KEYSCommand.java b/redis/src/main/java/org/apache/zeppelin/redis/command/key/KEYSCommand.java new file mode 100644 index 00000000000..7e3f5a4a8f3 --- /dev/null +++ b/redis/src/main/java/org/apache/zeppelin/redis/command/key/KEYSCommand.java @@ -0,0 +1,38 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.zeppelin.redis.command.key; + +import org.apache.zeppelin.redis.command.RedisCommand; +import redis.clients.jedis.Jedis; +import redis.clients.jedis.JedisPool; + +/** + * Find all keys matching the given pattern + */ +public class KEYSCommand extends RedisCommand { + + public KEYSCommand(JedisPool clientPool) { + super(clientPool); + } + + @Override + protected String execute(Jedis client, String[] tokens) { + String result = client.keys(tokens[1]).toString(); + return result; + } +} diff --git a/redis/src/main/java/org/apache/zeppelin/redis/command/key/MIGRATECommand.java b/redis/src/main/java/org/apache/zeppelin/redis/command/key/MIGRATECommand.java new file mode 100644 index 00000000000..7ff4a96cb78 --- /dev/null +++ b/redis/src/main/java/org/apache/zeppelin/redis/command/key/MIGRATECommand.java @@ -0,0 +1,39 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.zeppelin.redis.command.key; + +import org.apache.zeppelin.redis.command.RedisCommand; +import redis.clients.jedis.Jedis; +import redis.clients.jedis.JedisPool; + +/** + * Atomically transfer a key from a Redis instance to another one. + */ +public class MIGRATECommand extends RedisCommand { + + public MIGRATECommand(JedisPool clientPool) { + super(clientPool); + } + + @Override + protected String execute(Jedis client, String[] tokens) { + String result = client.migrate(tokens[1], Integer.valueOf(tokens[2]), tokens[3], + Integer.valueOf(tokens[4]), Integer.valueOf(tokens[5])); + return result; + } +} diff --git a/redis/src/main/java/org/apache/zeppelin/redis/command/key/MOVECommand.java b/redis/src/main/java/org/apache/zeppelin/redis/command/key/MOVECommand.java new file mode 100644 index 00000000000..ccc12334617 --- /dev/null +++ b/redis/src/main/java/org/apache/zeppelin/redis/command/key/MOVECommand.java @@ -0,0 +1,38 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.zeppelin.redis.command.key; + +import org.apache.zeppelin.redis.command.RedisCommand; +import redis.clients.jedis.Jedis; +import redis.clients.jedis.JedisPool; + +/** + * Move a key to another database + */ +public class MOVECommand extends RedisCommand { + + public MOVECommand(JedisPool clientPool) { + super(clientPool); + } + + @Override + protected String execute(Jedis client, String[] tokens) { + String result = client.move(tokens[1], Integer.valueOf(tokens[2])).toString(); + return result; + } +} diff --git a/redis/src/main/java/org/apache/zeppelin/redis/command/key/PERSISTCommand.java b/redis/src/main/java/org/apache/zeppelin/redis/command/key/PERSISTCommand.java new file mode 100644 index 00000000000..0b4d16bc757 --- /dev/null +++ b/redis/src/main/java/org/apache/zeppelin/redis/command/key/PERSISTCommand.java @@ -0,0 +1,38 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.zeppelin.redis.command.key; + +import org.apache.zeppelin.redis.command.RedisCommand; +import redis.clients.jedis.Jedis; +import redis.clients.jedis.JedisPool; + +/** + * Remove the expiration from a key + */ +public class PERSISTCommand extends RedisCommand { + + public PERSISTCommand(JedisPool clientPool) { + super(clientPool); + } + + @Override + protected String execute(Jedis client, String[] tokens) { + String result = client.persist(tokens[1]).toString(); + return result; + } +} diff --git a/redis/src/main/java/org/apache/zeppelin/redis/command/key/PEXPIREATCommand.java b/redis/src/main/java/org/apache/zeppelin/redis/command/key/PEXPIREATCommand.java new file mode 100644 index 00000000000..3f55e619b69 --- /dev/null +++ b/redis/src/main/java/org/apache/zeppelin/redis/command/key/PEXPIREATCommand.java @@ -0,0 +1,38 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.zeppelin.redis.command.key; + +import org.apache.zeppelin.redis.command.RedisCommand; +import redis.clients.jedis.Jedis; +import redis.clients.jedis.JedisPool; + +/** + * Set the expiration for a key as a UNIX timestamp specified in milliseconds + */ +public class PEXPIREATCommand extends RedisCommand { + + public PEXPIREATCommand(JedisPool clientPool) { + super(clientPool); + } + + @Override + protected String execute(Jedis client, String[] tokens) { + String result = client.pexpireAt(tokens[1], Long.valueOf(tokens[2])).toString(); + return result; + } +} diff --git a/redis/src/main/java/org/apache/zeppelin/redis/command/key/PEXPIRECommand.java b/redis/src/main/java/org/apache/zeppelin/redis/command/key/PEXPIRECommand.java new file mode 100644 index 00000000000..912ed94bb21 --- /dev/null +++ b/redis/src/main/java/org/apache/zeppelin/redis/command/key/PEXPIRECommand.java @@ -0,0 +1,38 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.zeppelin.redis.command.key; + +import org.apache.zeppelin.redis.command.RedisCommand; +import redis.clients.jedis.Jedis; +import redis.clients.jedis.JedisPool; + +/** + * Set a key's time to live in milliseconds + */ +public class PEXPIRECommand extends RedisCommand { + + public PEXPIRECommand(JedisPool clientPool) { + super(clientPool); + } + + @Override + protected String execute(Jedis client, String[] tokens) { + String result = client.pexpire(tokens[1], Long.valueOf(tokens[2])).toString(); + return result; + } +} diff --git a/redis/src/main/java/org/apache/zeppelin/redis/command/key/PTTLCommand.java b/redis/src/main/java/org/apache/zeppelin/redis/command/key/PTTLCommand.java new file mode 100644 index 00000000000..ed3fc778854 --- /dev/null +++ b/redis/src/main/java/org/apache/zeppelin/redis/command/key/PTTLCommand.java @@ -0,0 +1,38 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.zeppelin.redis.command.key; + +import org.apache.zeppelin.redis.command.RedisCommand; +import redis.clients.jedis.Jedis; +import redis.clients.jedis.JedisPool; + +/** + * Get the time to live for a key in milliseconds + */ +public class PTTLCommand extends RedisCommand { + + public PTTLCommand(JedisPool clientPool) { + super(clientPool); + } + + @Override + protected String execute(Jedis client, String[] tokens) { + String result = client.pttl(tokens[1]).toString(); + return result; + } +} diff --git a/redis/src/main/java/org/apache/zeppelin/redis/command/key/RANDOMKEYCommand.java b/redis/src/main/java/org/apache/zeppelin/redis/command/key/RANDOMKEYCommand.java new file mode 100644 index 00000000000..5beb6087c3b --- /dev/null +++ b/redis/src/main/java/org/apache/zeppelin/redis/command/key/RANDOMKEYCommand.java @@ -0,0 +1,38 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.zeppelin.redis.command.key; + +import org.apache.zeppelin.redis.command.RedisCommand; +import redis.clients.jedis.Jedis; +import redis.clients.jedis.JedisPool; + +/** + * Return a random key from the keyspace + */ +public class RANDOMKEYCommand extends RedisCommand { + + public RANDOMKEYCommand(JedisPool clientPool) { + super(clientPool); + } + + @Override + protected String execute(Jedis client, String[] tokens) { + String result = client.randomKey(); + return result; + } +} diff --git a/redis/src/main/java/org/apache/zeppelin/redis/command/key/RENAMECommand.java b/redis/src/main/java/org/apache/zeppelin/redis/command/key/RENAMECommand.java new file mode 100644 index 00000000000..5af537579ec --- /dev/null +++ b/redis/src/main/java/org/apache/zeppelin/redis/command/key/RENAMECommand.java @@ -0,0 +1,38 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.zeppelin.redis.command.key; + +import org.apache.zeppelin.redis.command.RedisCommand; +import redis.clients.jedis.Jedis; +import redis.clients.jedis.JedisPool; + +/** + * Rename a key + */ +public class RENAMECommand extends RedisCommand { + + public RENAMECommand(JedisPool clientPool) { + super(clientPool); + } + + @Override + protected String execute(Jedis client, String[] tokens) { + String result = client.rename(tokens[1], tokens[2]); + return result; + } +} diff --git a/redis/src/main/java/org/apache/zeppelin/redis/command/key/RENAMENXCommand.java b/redis/src/main/java/org/apache/zeppelin/redis/command/key/RENAMENXCommand.java new file mode 100644 index 00000000000..5151f37dc6c --- /dev/null +++ b/redis/src/main/java/org/apache/zeppelin/redis/command/key/RENAMENXCommand.java @@ -0,0 +1,38 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.zeppelin.redis.command.key; + +import org.apache.zeppelin.redis.command.RedisCommand; +import redis.clients.jedis.Jedis; +import redis.clients.jedis.JedisPool; + +/** + * Rename a key, only if the new key does not exist + */ +public class RENAMENXCommand extends RedisCommand { + + public RENAMENXCommand(JedisPool clientPool) { + super(clientPool); + } + + @Override + protected String execute(Jedis client, String[] tokens) { + String result = client.renamenx(tokens[1], tokens[2]).toString(); + return result; + } +} diff --git a/redis/src/main/java/org/apache/zeppelin/redis/command/key/RESTORECommand.java b/redis/src/main/java/org/apache/zeppelin/redis/command/key/RESTORECommand.java new file mode 100644 index 00000000000..9538eaca363 --- /dev/null +++ b/redis/src/main/java/org/apache/zeppelin/redis/command/key/RESTORECommand.java @@ -0,0 +1,39 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.zeppelin.redis.command.key; + +import org.apache.zeppelin.redis.command.RedisCommand; +import redis.clients.jedis.Jedis; +import redis.clients.jedis.JedisPool; + +/** + * Create a key using the provided serialized value, previously obtained using DUMP. + */ +public class RESTORECommand extends RedisCommand { + + public RESTORECommand(JedisPool clientPool) { + super(clientPool); + } + + @Override + protected String execute(Jedis client, String[] tokens) { + String result = client.restore(tokens[1], Integer.valueOf(tokens[2]), + tokens[2].getBytes()); + return result; + } +} diff --git a/redis/src/main/java/org/apache/zeppelin/redis/command/key/SCANCommand.java b/redis/src/main/java/org/apache/zeppelin/redis/command/key/SCANCommand.java new file mode 100644 index 00000000000..fd9e5575b45 --- /dev/null +++ b/redis/src/main/java/org/apache/zeppelin/redis/command/key/SCANCommand.java @@ -0,0 +1,38 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.zeppelin.redis.command.key; + +import org.apache.zeppelin.redis.command.RedisCommand; +import redis.clients.jedis.Jedis; +import redis.clients.jedis.JedisPool; + +/** + * Incrementally iterate the keys space + */ +public class SCANCommand extends RedisCommand { + + public SCANCommand(JedisPool clientPool) { + super(clientPool); + } + + @Override + protected String execute(Jedis client, String[] tokens) { + String result = client.scan(tokens[1]).toString(); + return result; + } +} diff --git a/redis/src/main/java/org/apache/zeppelin/redis/command/key/SORTCommand.java b/redis/src/main/java/org/apache/zeppelin/redis/command/key/SORTCommand.java new file mode 100644 index 00000000000..431dfe76ba4 --- /dev/null +++ b/redis/src/main/java/org/apache/zeppelin/redis/command/key/SORTCommand.java @@ -0,0 +1,38 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.zeppelin.redis.command.key; + +import org.apache.zeppelin.redis.command.RedisCommand; +import redis.clients.jedis.Jedis; +import redis.clients.jedis.JedisPool; + +/** + * Sort the elements in a list, set or sorted set + */ +public class SORTCommand extends RedisCommand { + + public SORTCommand(JedisPool clientPool) { + super(clientPool); + } + + @Override + protected String execute(Jedis client, String[] tokens) { + String result = client.sort(tokens[1]).toString(); + return result; + } +} diff --git a/redis/src/main/java/org/apache/zeppelin/redis/command/key/TTLCommand.java b/redis/src/main/java/org/apache/zeppelin/redis/command/key/TTLCommand.java new file mode 100644 index 00000000000..ea0dcf15ec5 --- /dev/null +++ b/redis/src/main/java/org/apache/zeppelin/redis/command/key/TTLCommand.java @@ -0,0 +1,38 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.zeppelin.redis.command.key; + +import org.apache.zeppelin.redis.command.RedisCommand; +import redis.clients.jedis.Jedis; +import redis.clients.jedis.JedisPool; + +/** + * Get the time to live for a key + */ +public class TTLCommand extends RedisCommand { + + public TTLCommand(JedisPool clientPool) { + super(clientPool); + } + + @Override + protected String execute(Jedis client, String[] tokens) { + String result = client.ttl(tokens[1]).toString(); + return result; + } +} diff --git a/redis/src/main/java/org/apache/zeppelin/redis/command/key/TYPECommand.java b/redis/src/main/java/org/apache/zeppelin/redis/command/key/TYPECommand.java new file mode 100644 index 00000000000..6b897b12120 --- /dev/null +++ b/redis/src/main/java/org/apache/zeppelin/redis/command/key/TYPECommand.java @@ -0,0 +1,38 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.zeppelin.redis.command.key; + +import org.apache.zeppelin.redis.command.RedisCommand; +import redis.clients.jedis.Jedis; +import redis.clients.jedis.JedisPool; + +/** + * Determine the type stored at key + */ +public class TYPECommand extends RedisCommand { + + public TYPECommand(JedisPool clientPool) { + super(clientPool); + } + + @Override + protected String execute(Jedis client, String[] tokens) { + String result = client.type(tokens[1]); + return result; + } +} diff --git a/redis/src/main/java/org/apache/zeppelin/redis/command/key/WAITCommand.java b/redis/src/main/java/org/apache/zeppelin/redis/command/key/WAITCommand.java new file mode 100644 index 00000000000..22826284df3 --- /dev/null +++ b/redis/src/main/java/org/apache/zeppelin/redis/command/key/WAITCommand.java @@ -0,0 +1,26 @@ +package org.apache.zeppelin.redis.command.key; + +import org.apache.zeppelin.redis.command.RedisCommand; +import redis.clients.jedis.Jedis; +import redis.clients.jedis.JedisPool; + +/** + * Wait for the synchronous replication of all the write commands sent + * in the context of the current connection + */ +public class WAITCommand extends RedisCommand { + + public WAITCommand(JedisPool clientPool) { + super(clientPool); + } + + @Override + protected String execute(Jedis client, String[] tokens) { + try { + client.wait(Long.valueOf(tokens[1])); + return "SUCC"; + } catch (InterruptedException e) { + return "Interrupted"; + } + } +} diff --git a/redis/src/main/java/org/apache/zeppelin/redis/command/list/BLPOPCommand.java b/redis/src/main/java/org/apache/zeppelin/redis/command/list/BLPOPCommand.java new file mode 100644 index 00000000000..4dc6127d0e1 --- /dev/null +++ b/redis/src/main/java/org/apache/zeppelin/redis/command/list/BLPOPCommand.java @@ -0,0 +1,40 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.zeppelin.redis.command.list; + +import org.apache.zeppelin.redis.command.RedisCommand; +import redis.clients.jedis.Jedis; +import redis.clients.jedis.JedisPool; + +/** + * Remove and get the first element in a list, or block until one is available + */ +public class BLPOPCommand extends RedisCommand { + + public BLPOPCommand(JedisPool clientPool) { + super(clientPool); + } + + @Override + protected String execute(Jedis client, String[] tokens) { + String[] keys = new String[tokens.length - 2]; + System.arraycopy(tokens, 2, keys, 0, tokens.length - 2); + String result = client.blpop(Integer.valueOf(tokens[1]), keys).toString(); + return result; + } +} diff --git a/redis/src/main/java/org/apache/zeppelin/redis/command/list/BRPOPCommand.java b/redis/src/main/java/org/apache/zeppelin/redis/command/list/BRPOPCommand.java new file mode 100644 index 00000000000..26cb52dff93 --- /dev/null +++ b/redis/src/main/java/org/apache/zeppelin/redis/command/list/BRPOPCommand.java @@ -0,0 +1,41 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.zeppelin.redis.command.list; + +import org.apache.zeppelin.redis.command.RedisCommand; +import redis.clients.jedis.Jedis; +import redis.clients.jedis.JedisPool; + +/** + * Remove and get the last element in a list, or block until one is available + */ +public class BRPOPCommand extends RedisCommand { + + public BRPOPCommand(JedisPool clientPool) { + super(clientPool); + } + + @Override + protected String execute(Jedis client, String[] tokens) { + String[] keys = new String[tokens.length - 2]; + System.arraycopy(tokens, 2, keys, 0, tokens.length - 2); + String result = client.brpop(Integer.valueOf(tokens[1]), + keys).toString(); + return result; + } +} diff --git a/redis/src/main/java/org/apache/zeppelin/redis/command/list/BRPOPLPUSHCommand.java b/redis/src/main/java/org/apache/zeppelin/redis/command/list/BRPOPLPUSHCommand.java new file mode 100644 index 00000000000..cb3a35a60c8 --- /dev/null +++ b/redis/src/main/java/org/apache/zeppelin/redis/command/list/BRPOPLPUSHCommand.java @@ -0,0 +1,39 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.zeppelin.redis.command.list; + +import org.apache.zeppelin.redis.command.RedisCommand; +import redis.clients.jedis.Jedis; +import redis.clients.jedis.JedisPool; + +/** + * Pop a value from a list, push it to another list and return it; or block until one is available + */ +public class BRPOPLPUSHCommand extends RedisCommand { + + public BRPOPLPUSHCommand(JedisPool clientPool) { + super(clientPool); + } + + @Override + protected String execute(Jedis client, String[] tokens) { + String result = client.brpoplpush(tokens[1], tokens[2], + Integer.valueOf(tokens[3])); + return result; + } +} diff --git a/redis/src/main/java/org/apache/zeppelin/redis/command/list/LINDEXCommand.java b/redis/src/main/java/org/apache/zeppelin/redis/command/list/LINDEXCommand.java new file mode 100644 index 00000000000..2cfc51aa7e8 --- /dev/null +++ b/redis/src/main/java/org/apache/zeppelin/redis/command/list/LINDEXCommand.java @@ -0,0 +1,37 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.zeppelin.redis.command.list; + +import org.apache.zeppelin.redis.command.RedisCommand; +import redis.clients.jedis.Jedis; +import redis.clients.jedis.JedisPool; + +/** + * Get an element from a list by its index + */ +public class LINDEXCommand extends RedisCommand { + public LINDEXCommand(JedisPool clientPool) { + super(clientPool); + } + + @Override + protected String execute(Jedis client, String[] tokens) { + String result = client.lindex(tokens[1], Long.valueOf(tokens[2])); + return result; + } +} diff --git a/redis/src/main/java/org/apache/zeppelin/redis/command/list/LINSERTCommand.java b/redis/src/main/java/org/apache/zeppelin/redis/command/list/LINSERTCommand.java new file mode 100644 index 00000000000..2ba0cdeb0e4 --- /dev/null +++ b/redis/src/main/java/org/apache/zeppelin/redis/command/list/LINSERTCommand.java @@ -0,0 +1,40 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.zeppelin.redis.command.list; + +import org.apache.zeppelin.redis.command.RedisCommand; +import redis.clients.jedis.BinaryClient; +import redis.clients.jedis.Jedis; +import redis.clients.jedis.JedisPool; + +/** + * Insert an element before or after another element in a list + */ +public class LINSERTCommand extends RedisCommand { + + public LINSERTCommand(JedisPool clientPool) { + super(clientPool); + } + + @Override + protected String execute(Jedis client, String[] tokens) { + String result = client.linsert(tokens[1], BinaryClient.LIST_POSITION.valueOf(tokens[2]), + tokens[3], tokens[4]).toString(); + return result; + } +} diff --git a/redis/src/main/java/org/apache/zeppelin/redis/command/list/LLENCommand.java b/redis/src/main/java/org/apache/zeppelin/redis/command/list/LLENCommand.java new file mode 100644 index 00000000000..abb81594308 --- /dev/null +++ b/redis/src/main/java/org/apache/zeppelin/redis/command/list/LLENCommand.java @@ -0,0 +1,38 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.zeppelin.redis.command.list; + +import org.apache.zeppelin.redis.command.RedisCommand; +import redis.clients.jedis.Jedis; +import redis.clients.jedis.JedisPool; + +/** + * Get the length of a list + */ +public class LLENCommand extends RedisCommand { + + public LLENCommand(JedisPool clientPool) { + super(clientPool); + } + + @Override + protected String execute(Jedis client, String[] tokens) { + String result = client.llen(tokens[1]).toString(); + return result; + } +} diff --git a/redis/src/main/java/org/apache/zeppelin/redis/command/list/LPOPCommand.java b/redis/src/main/java/org/apache/zeppelin/redis/command/list/LPOPCommand.java new file mode 100644 index 00000000000..97c43a5e158 --- /dev/null +++ b/redis/src/main/java/org/apache/zeppelin/redis/command/list/LPOPCommand.java @@ -0,0 +1,38 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.zeppelin.redis.command.list; + +import org.apache.zeppelin.redis.command.RedisCommand; +import redis.clients.jedis.Jedis; +import redis.clients.jedis.JedisPool; + +/** + * Remove and get the first element in a list + */ +public class LPOPCommand extends RedisCommand { + + public LPOPCommand(JedisPool clientPool) { + super(clientPool); + } + + @Override + protected String execute(Jedis client, String[] tokens) { + String result = client.lpop(tokens[1]); + return result; + } +} diff --git a/redis/src/main/java/org/apache/zeppelin/redis/command/list/LPUSHCommand.java b/redis/src/main/java/org/apache/zeppelin/redis/command/list/LPUSHCommand.java new file mode 100644 index 00000000000..16ccc15ecca --- /dev/null +++ b/redis/src/main/java/org/apache/zeppelin/redis/command/list/LPUSHCommand.java @@ -0,0 +1,40 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.zeppelin.redis.command.list; + +import org.apache.zeppelin.redis.command.RedisCommand; +import redis.clients.jedis.Jedis; +import redis.clients.jedis.JedisPool; + +/** + * Prepend one or multiple values to a list + */ +public class LPUSHCommand extends RedisCommand { + + public LPUSHCommand(JedisPool clientPool) { + super(clientPool); + } + + @Override + protected String execute(Jedis client, String[] tokens) { + String[] keys = new String[tokens.length - 2]; + System.arraycopy(tokens, 2, keys, 0, tokens.length - 2); + String result = client.lpush(tokens[1], keys).toString(); + return result; + } +} diff --git a/redis/src/main/java/org/apache/zeppelin/redis/command/list/LPUSHXCommand.java b/redis/src/main/java/org/apache/zeppelin/redis/command/list/LPUSHXCommand.java new file mode 100644 index 00000000000..3b185a3a12a --- /dev/null +++ b/redis/src/main/java/org/apache/zeppelin/redis/command/list/LPUSHXCommand.java @@ -0,0 +1,40 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.zeppelin.redis.command.list; + +import org.apache.zeppelin.redis.command.RedisCommand; +import redis.clients.jedis.Jedis; +import redis.clients.jedis.JedisPool; + +/** + * Prepend a value to a list, only if the list exists + */ +public class LPUSHXCommand extends RedisCommand { + + public LPUSHXCommand(JedisPool clientPool) { + super(clientPool); + } + + @Override + protected String execute(Jedis client, String[] tokens) { + String[] keys = new String[tokens.length - 2]; + System.arraycopy(tokens, 2, keys, 0, tokens.length - 2); + String result = client.lpushx(tokens[1], keys).toString(); + return result; + } +} diff --git a/redis/src/main/java/org/apache/zeppelin/redis/command/list/LRANGECommand.java b/redis/src/main/java/org/apache/zeppelin/redis/command/list/LRANGECommand.java new file mode 100644 index 00000000000..67c9e6089a4 --- /dev/null +++ b/redis/src/main/java/org/apache/zeppelin/redis/command/list/LRANGECommand.java @@ -0,0 +1,39 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.zeppelin.redis.command.list; + +import org.apache.zeppelin.redis.command.RedisCommand; +import redis.clients.jedis.Jedis; +import redis.clients.jedis.JedisPool; + +/** + * Get a range of elements from a list + */ +public class LRANGECommand extends RedisCommand { + + public LRANGECommand(JedisPool clientPool) { + super(clientPool); + } + + @Override + protected String execute(Jedis client, String[] tokens) { + String result = client.lrange(tokens[1], Long.valueOf(tokens[2]), + Long.valueOf(tokens[3])).toString(); + return result; + } +} diff --git a/redis/src/main/java/org/apache/zeppelin/redis/command/list/LREMCommand.java b/redis/src/main/java/org/apache/zeppelin/redis/command/list/LREMCommand.java new file mode 100644 index 00000000000..f250f02dc8d --- /dev/null +++ b/redis/src/main/java/org/apache/zeppelin/redis/command/list/LREMCommand.java @@ -0,0 +1,39 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.zeppelin.redis.command.list; + +import org.apache.zeppelin.redis.command.RedisCommand; +import redis.clients.jedis.Jedis; +import redis.clients.jedis.JedisPool; + +/** + * Remove elements from a list + */ +public class LREMCommand extends RedisCommand { + + public LREMCommand(JedisPool clientPool) { + super(clientPool); + } + + @Override + protected String execute(Jedis client, String[] tokens) { + String result = client.lrem(tokens[1], Long.valueOf(tokens[2]), + tokens[3]).toString(); + return result; + } +} diff --git a/redis/src/main/java/org/apache/zeppelin/redis/command/list/LSETCommand.java b/redis/src/main/java/org/apache/zeppelin/redis/command/list/LSETCommand.java new file mode 100644 index 00000000000..81a907470a8 --- /dev/null +++ b/redis/src/main/java/org/apache/zeppelin/redis/command/list/LSETCommand.java @@ -0,0 +1,38 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.zeppelin.redis.command.list; + +import org.apache.zeppelin.redis.command.RedisCommand; +import redis.clients.jedis.Jedis; +import redis.clients.jedis.JedisPool; + +/** + * Set the value of an element in a list by its index + */ +public class LSETCommand extends RedisCommand { + + public LSETCommand(JedisPool clientPool) { + super(clientPool); + } + + @Override + protected String execute(Jedis client, String[] tokens) { + String result = client.lset(tokens[1], Long.valueOf(tokens[2]), tokens[3]); + return result; + } +} diff --git a/redis/src/main/java/org/apache/zeppelin/redis/command/list/LTRIMCommand.java b/redis/src/main/java/org/apache/zeppelin/redis/command/list/LTRIMCommand.java new file mode 100644 index 00000000000..9f56a842007 --- /dev/null +++ b/redis/src/main/java/org/apache/zeppelin/redis/command/list/LTRIMCommand.java @@ -0,0 +1,39 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.zeppelin.redis.command.list; + +import org.apache.zeppelin.redis.command.RedisCommand; +import redis.clients.jedis.Jedis; +import redis.clients.jedis.JedisPool; + +/** + * Trim a list to the specified range + */ +public class LTRIMCommand extends RedisCommand { + + public LTRIMCommand(JedisPool clientPool) { + super(clientPool); + } + + @Override + protected String execute(Jedis client, String[] tokens) { + String result = client.ltrim(tokens[1], Long.valueOf(tokens[2]), + Long.valueOf(tokens[3])); + return result; + } +} diff --git a/redis/src/main/java/org/apache/zeppelin/redis/command/list/RPOPCommand.java b/redis/src/main/java/org/apache/zeppelin/redis/command/list/RPOPCommand.java new file mode 100644 index 00000000000..3c520979517 --- /dev/null +++ b/redis/src/main/java/org/apache/zeppelin/redis/command/list/RPOPCommand.java @@ -0,0 +1,38 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.zeppelin.redis.command.list; + +import org.apache.zeppelin.redis.command.RedisCommand; +import redis.clients.jedis.Jedis; +import redis.clients.jedis.JedisPool; + +/** + * Remove and get the last element in a list + */ +public class RPOPCommand extends RedisCommand { + + public RPOPCommand(JedisPool clientPool) { + super(clientPool); + } + + @Override + protected String execute(Jedis client, String[] tokens) { + String result = client.rpop(tokens[1]); + return result; + } +} diff --git a/redis/src/main/java/org/apache/zeppelin/redis/command/list/RPOPLPUSHCommand.java b/redis/src/main/java/org/apache/zeppelin/redis/command/list/RPOPLPUSHCommand.java new file mode 100644 index 00000000000..316ae61681d --- /dev/null +++ b/redis/src/main/java/org/apache/zeppelin/redis/command/list/RPOPLPUSHCommand.java @@ -0,0 +1,38 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.zeppelin.redis.command.list; + +import org.apache.zeppelin.redis.command.RedisCommand; +import redis.clients.jedis.Jedis; +import redis.clients.jedis.JedisPool; + +/** + * Remove the last element in a list, prepend it to another list and return it + */ +public class RPOPLPUSHCommand extends RedisCommand { + + public RPOPLPUSHCommand(JedisPool clientPool) { + super(clientPool); + } + + @Override + protected String execute(Jedis client, String[] tokens) { + String result = client.rpoplpush(tokens[1], tokens[2]); + return result; + } +} diff --git a/redis/src/main/java/org/apache/zeppelin/redis/command/list/RPUSHCommand.java b/redis/src/main/java/org/apache/zeppelin/redis/command/list/RPUSHCommand.java new file mode 100644 index 00000000000..4da5ad2444e --- /dev/null +++ b/redis/src/main/java/org/apache/zeppelin/redis/command/list/RPUSHCommand.java @@ -0,0 +1,40 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.zeppelin.redis.command.list; + +import org.apache.zeppelin.redis.command.RedisCommand; +import redis.clients.jedis.Jedis; +import redis.clients.jedis.JedisPool; + +/** + * Append one or multiple values to a list + */ +public class RPUSHCommand extends RedisCommand { + + public RPUSHCommand(JedisPool clientPool) { + super(clientPool); + } + + @Override + protected String execute(Jedis client, String[] tokens) { + String[] keys = new String[tokens.length - 2]; + System.arraycopy(tokens, 2, keys, 0, tokens.length - 2); + String result = client.rpush(tokens[1], keys).toString(); + return result; + } +} diff --git a/redis/src/main/java/org/apache/zeppelin/redis/command/list/RPUSHXCommand.java b/redis/src/main/java/org/apache/zeppelin/redis/command/list/RPUSHXCommand.java new file mode 100644 index 00000000000..9df3742efde --- /dev/null +++ b/redis/src/main/java/org/apache/zeppelin/redis/command/list/RPUSHXCommand.java @@ -0,0 +1,40 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.zeppelin.redis.command.list; + +import org.apache.zeppelin.redis.command.RedisCommand; +import redis.clients.jedis.Jedis; +import redis.clients.jedis.JedisPool; + +/** + * Append a value to a list, only if the list exists + */ +public class RPUSHXCommand extends RedisCommand { + + public RPUSHXCommand(JedisPool clientPool) { + super(clientPool); + } + + @Override + protected String execute(Jedis client, String[] tokens) { + String[] keys = new String[tokens.length - 2]; + System.arraycopy(tokens, 2, keys, 0, tokens.length - 2); + String result = client.rpushx(tokens[1], keys).toString(); + return result; + } +} diff --git a/redis/src/main/java/org/apache/zeppelin/redis/command/set/SADDCommand.java b/redis/src/main/java/org/apache/zeppelin/redis/command/set/SADDCommand.java new file mode 100644 index 00000000000..2a87b7921cd --- /dev/null +++ b/redis/src/main/java/org/apache/zeppelin/redis/command/set/SADDCommand.java @@ -0,0 +1,40 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.zeppelin.redis.command.set; + +import org.apache.zeppelin.redis.command.RedisCommand; +import redis.clients.jedis.Jedis; +import redis.clients.jedis.JedisPool; + +/** + * Add one or more members to a set + */ +public class SADDCommand extends RedisCommand { + + public SADDCommand(JedisPool clientPool) { + super(clientPool); + } + + @Override + protected String execute(Jedis client, String[] tokens) { + String[] members = new String[tokens.length - 2]; + System.arraycopy(tokens, 2, members, 0, tokens.length - 2); + String result = client.sadd(tokens[1], members).toString(); + return result; + } +} diff --git a/redis/src/main/java/org/apache/zeppelin/redis/command/set/SCARDCommand.java b/redis/src/main/java/org/apache/zeppelin/redis/command/set/SCARDCommand.java new file mode 100644 index 00000000000..bb9916d6dbb --- /dev/null +++ b/redis/src/main/java/org/apache/zeppelin/redis/command/set/SCARDCommand.java @@ -0,0 +1,38 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.zeppelin.redis.command.set; + +import org.apache.zeppelin.redis.command.RedisCommand; +import redis.clients.jedis.Jedis; +import redis.clients.jedis.JedisPool; + +/** + * Get the number of members in a set + */ +public class SCARDCommand extends RedisCommand { + + public SCARDCommand(JedisPool clientPool) { + super(clientPool); + } + + @Override + protected String execute(Jedis client, String[] tokens) { + String result = client.scard(tokens[1]).toString(); + return result; + } +} diff --git a/redis/src/main/java/org/apache/zeppelin/redis/command/set/SDIFFCommand.java b/redis/src/main/java/org/apache/zeppelin/redis/command/set/SDIFFCommand.java new file mode 100644 index 00000000000..5b7fde8f0b3 --- /dev/null +++ b/redis/src/main/java/org/apache/zeppelin/redis/command/set/SDIFFCommand.java @@ -0,0 +1,40 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.zeppelin.redis.command.set; + +import org.apache.zeppelin.redis.command.RedisCommand; +import redis.clients.jedis.Jedis; +import redis.clients.jedis.JedisPool; + +/** + * Subtract multiple sets + */ +public class SDIFFCommand extends RedisCommand { + + public SDIFFCommand(JedisPool clientPool) { + super(clientPool); + } + + @Override + protected String execute(Jedis client, String[] tokens) { + String[] members = new String[tokens.length - 1]; + System.arraycopy(tokens, 1, members, 0, tokens.length - 1); + String result = client.sdiff(members).toString(); + return result; + } +} diff --git a/redis/src/main/java/org/apache/zeppelin/redis/command/set/SDIFFSTORECommand.java b/redis/src/main/java/org/apache/zeppelin/redis/command/set/SDIFFSTORECommand.java new file mode 100644 index 00000000000..e24d0a0e5a5 --- /dev/null +++ b/redis/src/main/java/org/apache/zeppelin/redis/command/set/SDIFFSTORECommand.java @@ -0,0 +1,40 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.zeppelin.redis.command.set; + +import org.apache.zeppelin.redis.command.RedisCommand; +import redis.clients.jedis.Jedis; +import redis.clients.jedis.JedisPool; + +/** + * Subtract multiple sets and store the resulting set in a key + */ +public class SDIFFSTORECommand extends RedisCommand { + + public SDIFFSTORECommand(JedisPool clientPool) { + super(clientPool); + } + + @Override + protected String execute(Jedis client, String[] tokens) { + String[] members = new String[tokens.length - 2]; + System.arraycopy(tokens, 2, members, 0, tokens.length - 2); + String result = client.sdiffstore(tokens[1], members).toString(); + return result; + } +} diff --git a/redis/src/main/java/org/apache/zeppelin/redis/command/set/SINTERCommand.java b/redis/src/main/java/org/apache/zeppelin/redis/command/set/SINTERCommand.java new file mode 100644 index 00000000000..4700da31dac --- /dev/null +++ b/redis/src/main/java/org/apache/zeppelin/redis/command/set/SINTERCommand.java @@ -0,0 +1,40 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.zeppelin.redis.command.set; + +import org.apache.zeppelin.redis.command.RedisCommand; +import redis.clients.jedis.Jedis; +import redis.clients.jedis.JedisPool; + +/** + * Intersect multiple sets + */ +public class SINTERCommand extends RedisCommand { + + public SINTERCommand(JedisPool clientPool) { + super(clientPool); + } + + @Override + protected String execute(Jedis client, String[] tokens) { + String[] members = new String[tokens.length - 1]; + System.arraycopy(tokens, 1, members, 0, tokens.length - 1); + String result = client.sinter(members).toString(); + return result; + } +} diff --git a/redis/src/main/java/org/apache/zeppelin/redis/command/set/SINTERSTORECommand.java b/redis/src/main/java/org/apache/zeppelin/redis/command/set/SINTERSTORECommand.java new file mode 100644 index 00000000000..b68af01dcc3 --- /dev/null +++ b/redis/src/main/java/org/apache/zeppelin/redis/command/set/SINTERSTORECommand.java @@ -0,0 +1,40 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.zeppelin.redis.command.set; + +import org.apache.zeppelin.redis.command.RedisCommand; +import redis.clients.jedis.Jedis; +import redis.clients.jedis.JedisPool; + +/** + * Intersect multiple sets and store the resulting set in a key + */ +public class SINTERSTORECommand extends RedisCommand { + + public SINTERSTORECommand(JedisPool clientPool) { + super(clientPool); + } + + @Override + protected String execute(Jedis client, String[] tokens) { + String[] members = new String[tokens.length - 2]; + System.arraycopy(tokens, 2, members, 0, tokens.length - 2); + String result = client.sinterstore(tokens[1], members).toString(); + return result; + } +} diff --git a/redis/src/main/java/org/apache/zeppelin/redis/command/set/SISMEMBERCommand.java b/redis/src/main/java/org/apache/zeppelin/redis/command/set/SISMEMBERCommand.java new file mode 100644 index 00000000000..f772401e78c --- /dev/null +++ b/redis/src/main/java/org/apache/zeppelin/redis/command/set/SISMEMBERCommand.java @@ -0,0 +1,38 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.zeppelin.redis.command.set; + +import org.apache.zeppelin.redis.command.RedisCommand; +import redis.clients.jedis.Jedis; +import redis.clients.jedis.JedisPool; + +/** + * Determine if a given value is a member of a set + */ +public class SISMEMBERCommand extends RedisCommand { + + public SISMEMBERCommand(JedisPool clientPool) { + super(clientPool); + } + + @Override + protected String execute(Jedis client, String[] tokens) { + String result = client.sismember(tokens[1], tokens[2]).toString(); + return result; + } +} diff --git a/redis/src/main/java/org/apache/zeppelin/redis/command/set/SMEMBERSCommand.java b/redis/src/main/java/org/apache/zeppelin/redis/command/set/SMEMBERSCommand.java new file mode 100644 index 00000000000..adf9a7d34f9 --- /dev/null +++ b/redis/src/main/java/org/apache/zeppelin/redis/command/set/SMEMBERSCommand.java @@ -0,0 +1,38 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.zeppelin.redis.command.set; + +import org.apache.zeppelin.redis.command.RedisCommand; +import redis.clients.jedis.Jedis; +import redis.clients.jedis.JedisPool; + +/** + * Get all the members in a set + */ +public class SMEMBERSCommand extends RedisCommand { + + public SMEMBERSCommand(JedisPool clientPool) { + super(clientPool); + } + + @Override + protected String execute(Jedis client, String[] tokens) { + String result = client.smembers(tokens[1]).toString(); + return result; + } +} diff --git a/redis/src/main/java/org/apache/zeppelin/redis/command/set/SMOVECommand.java b/redis/src/main/java/org/apache/zeppelin/redis/command/set/SMOVECommand.java new file mode 100644 index 00000000000..58fc9419aaa --- /dev/null +++ b/redis/src/main/java/org/apache/zeppelin/redis/command/set/SMOVECommand.java @@ -0,0 +1,38 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.zeppelin.redis.command.set; + +import org.apache.zeppelin.redis.command.RedisCommand; +import redis.clients.jedis.Jedis; +import redis.clients.jedis.JedisPool; + +/** + * Move a member from one set to another + */ +public class SMOVECommand extends RedisCommand { + + public SMOVECommand(JedisPool clientPool) { + super(clientPool); + } + + @Override + protected String execute(Jedis client, String[] tokens) { + String result = client.smove(tokens[1], tokens[2], tokens[3]).toString(); + return result; + } +} diff --git a/redis/src/main/java/org/apache/zeppelin/redis/command/set/SPOPCommand.java b/redis/src/main/java/org/apache/zeppelin/redis/command/set/SPOPCommand.java new file mode 100644 index 00000000000..817c713633c --- /dev/null +++ b/redis/src/main/java/org/apache/zeppelin/redis/command/set/SPOPCommand.java @@ -0,0 +1,38 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.zeppelin.redis.command.set; + +import org.apache.zeppelin.redis.command.RedisCommand; +import redis.clients.jedis.Jedis; +import redis.clients.jedis.JedisPool; + +/** + * Remove and return one or multiple random members from a set + */ +public class SPOPCommand extends RedisCommand { + + public SPOPCommand(JedisPool clientPool) { + super(clientPool); + } + + @Override + protected String execute(Jedis client, String[] tokens) { + String result = client.spop(tokens[1]); + return result; + } +} diff --git a/redis/src/main/java/org/apache/zeppelin/redis/command/set/SRANDMEMBERCommand.java b/redis/src/main/java/org/apache/zeppelin/redis/command/set/SRANDMEMBERCommand.java new file mode 100644 index 00000000000..f4937f73629 --- /dev/null +++ b/redis/src/main/java/org/apache/zeppelin/redis/command/set/SRANDMEMBERCommand.java @@ -0,0 +1,38 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.zeppelin.redis.command.set; + +import org.apache.zeppelin.redis.command.RedisCommand; +import redis.clients.jedis.Jedis; +import redis.clients.jedis.JedisPool; + +/** + * Get one or multiple random members from a set + */ +public class SRANDMEMBERCommand extends RedisCommand { + + public SRANDMEMBERCommand(JedisPool clientPool) { + super(clientPool); + } + + @Override + protected String execute(Jedis client, String[] tokens) { + String result = client.srandmember(tokens[1]); + return result; + } +} diff --git a/redis/src/main/java/org/apache/zeppelin/redis/command/set/SREMCommand.java b/redis/src/main/java/org/apache/zeppelin/redis/command/set/SREMCommand.java new file mode 100644 index 00000000000..90f73fa9fed --- /dev/null +++ b/redis/src/main/java/org/apache/zeppelin/redis/command/set/SREMCommand.java @@ -0,0 +1,40 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.zeppelin.redis.command.set; + +import org.apache.zeppelin.redis.command.RedisCommand; +import redis.clients.jedis.Jedis; +import redis.clients.jedis.JedisPool; + +/** + * Remove one or more members from a set + */ +public class SREMCommand extends RedisCommand { + + public SREMCommand(JedisPool clientPool) { + super(clientPool); + } + + @Override + protected String execute(Jedis client, String[] tokens) { + String[] members = new String[tokens.length - 2]; + System.arraycopy(tokens, 2, members, 0, tokens.length - 2); + String result = client.srem(tokens[1], members).toString(); + return result; + } +} diff --git a/redis/src/main/java/org/apache/zeppelin/redis/command/set/SSCANCommand.java b/redis/src/main/java/org/apache/zeppelin/redis/command/set/SSCANCommand.java new file mode 100644 index 00000000000..9842c455682 --- /dev/null +++ b/redis/src/main/java/org/apache/zeppelin/redis/command/set/SSCANCommand.java @@ -0,0 +1,38 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.zeppelin.redis.command.set; + +import org.apache.zeppelin.redis.command.RedisCommand; +import redis.clients.jedis.Jedis; +import redis.clients.jedis.JedisPool; + +/** + * Incrementally iterate Set elements + */ +public class SSCANCommand extends RedisCommand { + + public SSCANCommand(JedisPool clientPool) { + super(clientPool); + } + + @Override + protected String execute(Jedis client, String[] tokens) { + String result = client.sscan(tokens[1], tokens[2]).toString(); + return result; + } +} diff --git a/redis/src/main/java/org/apache/zeppelin/redis/command/set/SUNIONCommand.java b/redis/src/main/java/org/apache/zeppelin/redis/command/set/SUNIONCommand.java new file mode 100644 index 00000000000..3d3297919a3 --- /dev/null +++ b/redis/src/main/java/org/apache/zeppelin/redis/command/set/SUNIONCommand.java @@ -0,0 +1,40 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.zeppelin.redis.command.set; + +import org.apache.zeppelin.redis.command.RedisCommand; +import redis.clients.jedis.Jedis; +import redis.clients.jedis.JedisPool; + +/** + * Add multiple sets + */ +public class SUNIONCommand extends RedisCommand { + + public SUNIONCommand(JedisPool clientPool) { + super(clientPool); + } + + @Override + protected String execute(Jedis client, String[] tokens) { + String[] members = new String[tokens.length - 1]; + System.arraycopy(tokens, 1, members, 0, tokens.length - 1); + String result = client.sunion(members).toString(); + return result; + } +} diff --git a/redis/src/main/java/org/apache/zeppelin/redis/command/set/SUNIONSTORECommand.java b/redis/src/main/java/org/apache/zeppelin/redis/command/set/SUNIONSTORECommand.java new file mode 100644 index 00000000000..12eb8aee073 --- /dev/null +++ b/redis/src/main/java/org/apache/zeppelin/redis/command/set/SUNIONSTORECommand.java @@ -0,0 +1,40 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.zeppelin.redis.command.set; + +import org.apache.zeppelin.redis.command.RedisCommand; +import redis.clients.jedis.Jedis; +import redis.clients.jedis.JedisPool; + +/** + * Add multiple sets and store the resulting set in a key + */ +public class SUNIONSTORECommand extends RedisCommand { + + public SUNIONSTORECommand(JedisPool clientPool) { + super(clientPool); + } + + @Override + protected String execute(Jedis client, String[] tokens) { + String[] members = new String[tokens.length - 2]; + System.arraycopy(tokens, 2, members, 0, tokens.length - 2); + String result = client.sunionstore(tokens[1], members).toString(); + return result; + } +} diff --git a/redis/src/main/java/org/apache/zeppelin/redis/command/set/sorted/ZADDCommand.java b/redis/src/main/java/org/apache/zeppelin/redis/command/set/sorted/ZADDCommand.java new file mode 100644 index 00000000000..6990b590f09 --- /dev/null +++ b/redis/src/main/java/org/apache/zeppelin/redis/command/set/sorted/ZADDCommand.java @@ -0,0 +1,39 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.zeppelin.redis.command.set.sorted; + +import org.apache.zeppelin.redis.command.RedisCommand; +import redis.clients.jedis.Jedis; +import redis.clients.jedis.JedisPool; + +/** + * Add one or more members to a sorted set, or update its score if it already exists + */ +public class ZADDCommand extends RedisCommand { + + public ZADDCommand(JedisPool clientPool) { + super(clientPool); + } + + @Override + protected String execute(Jedis client, String[] tokens) { + String result = client.zadd(tokens[1], Double.valueOf(tokens[2]), + tokens[3]).toString(); + return result; + } +} diff --git a/redis/src/main/java/org/apache/zeppelin/redis/command/set/sorted/ZCARDCommand.java b/redis/src/main/java/org/apache/zeppelin/redis/command/set/sorted/ZCARDCommand.java new file mode 100644 index 00000000000..62968d14102 --- /dev/null +++ b/redis/src/main/java/org/apache/zeppelin/redis/command/set/sorted/ZCARDCommand.java @@ -0,0 +1,38 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.zeppelin.redis.command.set.sorted; + +import org.apache.zeppelin.redis.command.RedisCommand; +import redis.clients.jedis.Jedis; +import redis.clients.jedis.JedisPool; + +/** + * Get the number of members in a sorted set + */ +public class ZCARDCommand extends RedisCommand { + + public ZCARDCommand(JedisPool clientPool) { + super(clientPool); + } + + @Override + protected String execute(Jedis client, String[] tokens) { + String result = client.zcard(tokens[2]).toString(); + return result; + } +} diff --git a/redis/src/main/java/org/apache/zeppelin/redis/command/set/sorted/ZCOUNTCommand.java b/redis/src/main/java/org/apache/zeppelin/redis/command/set/sorted/ZCOUNTCommand.java new file mode 100644 index 00000000000..bdf983d8287 --- /dev/null +++ b/redis/src/main/java/org/apache/zeppelin/redis/command/set/sorted/ZCOUNTCommand.java @@ -0,0 +1,40 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + + +package org.apache.zeppelin.redis.command.set.sorted; + +import org.apache.zeppelin.redis.command.RedisCommand; +import redis.clients.jedis.Jedis; +import redis.clients.jedis.JedisPool; + +/** + * Count the members in a sorted set with scores within the given values + */ +public class ZCOUNTCommand extends RedisCommand { + + public ZCOUNTCommand(JedisPool clientPool) { + super(clientPool); + } + + @Override + protected String execute(Jedis client, String[] tokens) { + String result = client.zcount(tokens[1], Double.valueOf(tokens[2]), + Double.valueOf(tokens[3])).toString(); + return result; + } +} diff --git a/redis/src/main/java/org/apache/zeppelin/redis/command/set/sorted/ZINCRBYCommand.java b/redis/src/main/java/org/apache/zeppelin/redis/command/set/sorted/ZINCRBYCommand.java new file mode 100644 index 00000000000..346606ba316 --- /dev/null +++ b/redis/src/main/java/org/apache/zeppelin/redis/command/set/sorted/ZINCRBYCommand.java @@ -0,0 +1,40 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + + +package org.apache.zeppelin.redis.command.set.sorted; + +import org.apache.zeppelin.redis.command.RedisCommand; +import redis.clients.jedis.Jedis; +import redis.clients.jedis.JedisPool; + +/** + * Increment the score of a member in a sorted set + */ +public class ZINCRBYCommand extends RedisCommand { + + public ZINCRBYCommand(JedisPool clientPool) { + super(clientPool); + } + + @Override + protected String execute(Jedis client, String[] tokens) { + String result = client.zincrby(tokens[1], Double.valueOf(tokens[2]), + tokens[3]).toString(); + return result; + } +} diff --git a/redis/src/main/java/org/apache/zeppelin/redis/command/set/sorted/ZINTERSTORECommand.java b/redis/src/main/java/org/apache/zeppelin/redis/command/set/sorted/ZINTERSTORECommand.java new file mode 100644 index 00000000000..b56e7b82308 --- /dev/null +++ b/redis/src/main/java/org/apache/zeppelin/redis/command/set/sorted/ZINTERSTORECommand.java @@ -0,0 +1,40 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.zeppelin.redis.command.set.sorted; + +import org.apache.zeppelin.redis.command.RedisCommand; +import redis.clients.jedis.Jedis; +import redis.clients.jedis.JedisPool; + +/** + * Intersect multiple sorted sets and store the resulting sorted set in a new key + */ +public class ZINTERSTORECommand extends RedisCommand { + + public ZINTERSTORECommand(JedisPool clientPool) { + super(clientPool); + } + + @Override + protected String execute(Jedis client, String[] tokens) { + String[] members = new String[tokens.length - 2]; + System.arraycopy(tokens, 2, members, 0, tokens.length - 2); + String result = client.zinterstore(tokens[1], members).toString(); + return result; + } +} diff --git a/redis/src/main/java/org/apache/zeppelin/redis/command/set/sorted/ZLEXCOUNTCommand.java b/redis/src/main/java/org/apache/zeppelin/redis/command/set/sorted/ZLEXCOUNTCommand.java new file mode 100644 index 00000000000..ded723bdfa8 --- /dev/null +++ b/redis/src/main/java/org/apache/zeppelin/redis/command/set/sorted/ZLEXCOUNTCommand.java @@ -0,0 +1,38 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.zeppelin.redis.command.set.sorted; + +import org.apache.zeppelin.redis.command.RedisCommand; +import redis.clients.jedis.Jedis; +import redis.clients.jedis.JedisPool; + +/** + * Count the number of members in a sorted set between a given lexicographical range + */ +public class ZLEXCOUNTCommand extends RedisCommand { + + public ZLEXCOUNTCommand(JedisPool clientPool) { + super(clientPool); + } + + @Override + protected String execute(Jedis client, String[] tokens) { + String result = client.zlexcount(tokens[1], tokens[2], tokens[3]).toString(); + return result; + } +} diff --git a/redis/src/main/java/org/apache/zeppelin/redis/command/set/sorted/ZRANGEBYLEXCommand.java b/redis/src/main/java/org/apache/zeppelin/redis/command/set/sorted/ZRANGEBYLEXCommand.java new file mode 100644 index 00000000000..0a7c043f99e --- /dev/null +++ b/redis/src/main/java/org/apache/zeppelin/redis/command/set/sorted/ZRANGEBYLEXCommand.java @@ -0,0 +1,38 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.zeppelin.redis.command.set.sorted; + +import org.apache.zeppelin.redis.command.RedisCommand; +import redis.clients.jedis.Jedis; +import redis.clients.jedis.JedisPool; + +/** + * Return a range of members in a sorted set, by lexicographical range + */ +public class ZRANGEBYLEXCommand extends RedisCommand { + + public ZRANGEBYLEXCommand(JedisPool clientPool) { + super(clientPool); + } + + @Override + protected String execute(Jedis client, String[] tokens) { + String result = client.zrangeByLex(tokens[1], tokens[2], tokens[3]).toString(); + return result; + } +} diff --git a/redis/src/main/java/org/apache/zeppelin/redis/command/set/sorted/ZRANGEBYSCORECommand.java b/redis/src/main/java/org/apache/zeppelin/redis/command/set/sorted/ZRANGEBYSCORECommand.java new file mode 100644 index 00000000000..388cab0d452 --- /dev/null +++ b/redis/src/main/java/org/apache/zeppelin/redis/command/set/sorted/ZRANGEBYSCORECommand.java @@ -0,0 +1,39 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.zeppelin.redis.command.set.sorted; + +import org.apache.zeppelin.redis.command.RedisCommand; +import redis.clients.jedis.Jedis; +import redis.clients.jedis.JedisPool; + +/** + * Return a range of members in a sorted set, by score + */ +public class ZRANGEBYSCORECommand extends RedisCommand { + + public ZRANGEBYSCORECommand(JedisPool clientPool) { + super(clientPool); + } + + @Override + protected String execute(Jedis client, String[] tokens) { + String result = client.zrangeByScore(tokens[1], Double.valueOf(tokens[2]), + Double.valueOf(tokens[3])).toString(); + return result; + } +} diff --git a/redis/src/main/java/org/apache/zeppelin/redis/command/set/sorted/ZRANGECommand.java b/redis/src/main/java/org/apache/zeppelin/redis/command/set/sorted/ZRANGECommand.java new file mode 100644 index 00000000000..ca4d312d25a --- /dev/null +++ b/redis/src/main/java/org/apache/zeppelin/redis/command/set/sorted/ZRANGECommand.java @@ -0,0 +1,39 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.zeppelin.redis.command.set.sorted; + +import org.apache.zeppelin.redis.command.RedisCommand; +import redis.clients.jedis.Jedis; +import redis.clients.jedis.JedisPool; + +/** + * Return a range of members in a sorted set, by index + */ +public class ZRANGECommand extends RedisCommand { + + public ZRANGECommand(JedisPool clientPool) { + super(clientPool); + } + + @Override + protected String execute(Jedis client, String[] tokens) { + String result = client.zrange(tokens[1], Long.valueOf(tokens[2]), + Long.valueOf(tokens[3])).toString(); + return result; + } +} diff --git a/redis/src/main/java/org/apache/zeppelin/redis/command/set/sorted/ZRANKCommand.java b/redis/src/main/java/org/apache/zeppelin/redis/command/set/sorted/ZRANKCommand.java new file mode 100644 index 00000000000..00b1b457be1 --- /dev/null +++ b/redis/src/main/java/org/apache/zeppelin/redis/command/set/sorted/ZRANKCommand.java @@ -0,0 +1,38 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.zeppelin.redis.command.set.sorted; + +import org.apache.zeppelin.redis.command.RedisCommand; +import redis.clients.jedis.Jedis; +import redis.clients.jedis.JedisPool; + +/** + * Determine the index of a member in a sorted set + */ +public class ZRANKCommand extends RedisCommand { + + public ZRANKCommand(JedisPool clientPool) { + super(clientPool); + } + + @Override + protected String execute(Jedis client, String[] tokens) { + String result = client.zrank(tokens[1], tokens[2]).toString(); + return result; + } +} diff --git a/redis/src/main/java/org/apache/zeppelin/redis/command/set/sorted/ZREMCommand.java b/redis/src/main/java/org/apache/zeppelin/redis/command/set/sorted/ZREMCommand.java new file mode 100644 index 00000000000..d7b66c94051 --- /dev/null +++ b/redis/src/main/java/org/apache/zeppelin/redis/command/set/sorted/ZREMCommand.java @@ -0,0 +1,40 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.zeppelin.redis.command.set.sorted; + +import org.apache.zeppelin.redis.command.RedisCommand; +import redis.clients.jedis.Jedis; +import redis.clients.jedis.JedisPool; + +/** + * Remove one or more members from a sorted set + */ +public class ZREMCommand extends RedisCommand { + + public ZREMCommand(JedisPool clientPool) { + super(clientPool); + } + + @Override + protected String execute(Jedis client, String[] tokens) { + String[] members = new String[tokens.length - 2]; + System.arraycopy(tokens, 2, members, 0, tokens.length - 2); + String result = client.zrem(tokens[1], members).toString(); + return result; + } +} diff --git a/redis/src/main/java/org/apache/zeppelin/redis/command/set/sorted/ZREMRANGEBYLEXCommand.java b/redis/src/main/java/org/apache/zeppelin/redis/command/set/sorted/ZREMRANGEBYLEXCommand.java new file mode 100644 index 00000000000..1675b4db786 --- /dev/null +++ b/redis/src/main/java/org/apache/zeppelin/redis/command/set/sorted/ZREMRANGEBYLEXCommand.java @@ -0,0 +1,38 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.zeppelin.redis.command.set.sorted; + +import org.apache.zeppelin.redis.command.RedisCommand; +import redis.clients.jedis.Jedis; +import redis.clients.jedis.JedisPool; + +/** + * Remove all members in a sorted set between the given lexicographical range + */ +public class ZREMRANGEBYLEXCommand extends RedisCommand { + + public ZREMRANGEBYLEXCommand(JedisPool clientPool) { + super(clientPool); + } + + @Override + protected String execute(Jedis client, String[] tokens) { + String result = client.zremrangeByLex(tokens[1], tokens[2], tokens[3]).toString(); + return result; + } +} diff --git a/redis/src/main/java/org/apache/zeppelin/redis/command/set/sorted/ZREMRANGEBYRANKCommand.java b/redis/src/main/java/org/apache/zeppelin/redis/command/set/sorted/ZREMRANGEBYRANKCommand.java new file mode 100644 index 00000000000..51ae2840f08 --- /dev/null +++ b/redis/src/main/java/org/apache/zeppelin/redis/command/set/sorted/ZREMRANGEBYRANKCommand.java @@ -0,0 +1,39 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.zeppelin.redis.command.set.sorted; + +import org.apache.zeppelin.redis.command.RedisCommand; +import redis.clients.jedis.Jedis; +import redis.clients.jedis.JedisPool; + +/** + * Remove all members in a sorted set within the given indexes + */ +public class ZREMRANGEBYRANKCommand extends RedisCommand { + + public ZREMRANGEBYRANKCommand(JedisPool clientPool) { + super(clientPool); + } + + @Override + protected String execute(Jedis client, String[] tokens) { + String result = client.zremrangeByRank(tokens[1], Long.valueOf(tokens[2]), + Long.valueOf(tokens[3])).toString(); + return result; + } +} diff --git a/redis/src/main/java/org/apache/zeppelin/redis/command/set/sorted/ZREMRANGEBYSCORECommand.java b/redis/src/main/java/org/apache/zeppelin/redis/command/set/sorted/ZREMRANGEBYSCORECommand.java new file mode 100644 index 00000000000..bb0ff82050e --- /dev/null +++ b/redis/src/main/java/org/apache/zeppelin/redis/command/set/sorted/ZREMRANGEBYSCORECommand.java @@ -0,0 +1,39 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.zeppelin.redis.command.set.sorted; + +import org.apache.zeppelin.redis.command.RedisCommand; +import redis.clients.jedis.Jedis; +import redis.clients.jedis.JedisPool; + +/** + * Remove all members in a sorted set within the given scores + */ +public class ZREMRANGEBYSCORECommand extends RedisCommand { + + public ZREMRANGEBYSCORECommand(JedisPool clientPool) { + super(clientPool); + } + + @Override + protected String execute(Jedis client, String[] tokens) { + String result = client.zremrangeByScore(tokens[1], Double.valueOf(tokens[2]), + Double.valueOf(tokens[3])).toString(); + return result; + } +} diff --git a/redis/src/main/java/org/apache/zeppelin/redis/command/set/sorted/ZREVRANGEBYLEXCommand.java b/redis/src/main/java/org/apache/zeppelin/redis/command/set/sorted/ZREVRANGEBYLEXCommand.java new file mode 100644 index 00000000000..d01a04301df --- /dev/null +++ b/redis/src/main/java/org/apache/zeppelin/redis/command/set/sorted/ZREVRANGEBYLEXCommand.java @@ -0,0 +1,39 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.zeppelin.redis.command.set.sorted; + +import org.apache.zeppelin.redis.command.RedisCommand; +import redis.clients.jedis.Jedis; +import redis.clients.jedis.JedisPool; + +/** + * Return a range of members in a sorted set, by lexicographical range, + * ordered from higher to lower strings. + */ +public class ZREVRANGEBYLEXCommand extends RedisCommand { + + public ZREVRANGEBYLEXCommand(JedisPool clientPool) { + super(clientPool); + } + + @Override + protected String execute(Jedis client, String[] tokens) { + String result = client.zrevrangeByLex(tokens[1], tokens[2], tokens[3]).toString(); + return result; + } +} diff --git a/redis/src/main/java/org/apache/zeppelin/redis/command/set/sorted/ZREVRANGEBYSCORECommand.java b/redis/src/main/java/org/apache/zeppelin/redis/command/set/sorted/ZREVRANGEBYSCORECommand.java new file mode 100644 index 00000000000..1706bf02504 --- /dev/null +++ b/redis/src/main/java/org/apache/zeppelin/redis/command/set/sorted/ZREVRANGEBYSCORECommand.java @@ -0,0 +1,39 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.zeppelin.redis.command.set.sorted; + +import org.apache.zeppelin.redis.command.RedisCommand; +import redis.clients.jedis.Jedis; +import redis.clients.jedis.JedisPool; + +/** + * Return a range of members in a sorted set, by score, with scores ordered from high to low + */ +public class ZREVRANGEBYSCORECommand extends RedisCommand { + + public ZREVRANGEBYSCORECommand(JedisPool clientPool) { + super(clientPool); + } + + @Override + protected String execute(Jedis client, String[] tokens) { + String result = client.zrevrangeByScore(tokens[1], Double.valueOf(tokens[2]), + Double.valueOf(tokens[3])).toString(); + return result; + } +} diff --git a/redis/src/main/java/org/apache/zeppelin/redis/command/set/sorted/ZREVRANGECommand.java b/redis/src/main/java/org/apache/zeppelin/redis/command/set/sorted/ZREVRANGECommand.java new file mode 100644 index 00000000000..2f0afda52b2 --- /dev/null +++ b/redis/src/main/java/org/apache/zeppelin/redis/command/set/sorted/ZREVRANGECommand.java @@ -0,0 +1,39 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.zeppelin.redis.command.set.sorted; + +import org.apache.zeppelin.redis.command.RedisCommand; +import redis.clients.jedis.Jedis; +import redis.clients.jedis.JedisPool; + +/** + * Return a range of members in a sorted set, by index, with scores ordered from high to low + */ +public class ZREVRANGECommand extends RedisCommand { + + public ZREVRANGECommand(JedisPool clientPool) { + super(clientPool); + } + + @Override + protected String execute(Jedis client, String[] tokens) { + String result = client.zrevrange(tokens[1], Long.valueOf(tokens[2]), + Long.valueOf(tokens[3])).toString(); + return result; + } +} diff --git a/redis/src/main/java/org/apache/zeppelin/redis/command/set/sorted/ZREVRANKCommand.java b/redis/src/main/java/org/apache/zeppelin/redis/command/set/sorted/ZREVRANKCommand.java new file mode 100644 index 00000000000..45fcc99c136 --- /dev/null +++ b/redis/src/main/java/org/apache/zeppelin/redis/command/set/sorted/ZREVRANKCommand.java @@ -0,0 +1,38 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.zeppelin.redis.command.set.sorted; + +import org.apache.zeppelin.redis.command.RedisCommand; +import redis.clients.jedis.Jedis; +import redis.clients.jedis.JedisPool; + +/** + * Determine the index of a member in a sorted set, with scores ordered from high to low + */ +public class ZREVRANKCommand extends RedisCommand { + + public ZREVRANKCommand(JedisPool clientPool) { + super(clientPool); + } + + @Override + protected String execute(Jedis client, String[] tokens) { + String result = client.zrevrank(tokens[1], tokens[2]).toString(); + return result; + } +} diff --git a/redis/src/main/java/org/apache/zeppelin/redis/command/set/sorted/ZSCANCommand.java b/redis/src/main/java/org/apache/zeppelin/redis/command/set/sorted/ZSCANCommand.java new file mode 100644 index 00000000000..bb2c8241d52 --- /dev/null +++ b/redis/src/main/java/org/apache/zeppelin/redis/command/set/sorted/ZSCANCommand.java @@ -0,0 +1,38 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.zeppelin.redis.command.set.sorted; + +import org.apache.zeppelin.redis.command.RedisCommand; +import redis.clients.jedis.Jedis; +import redis.clients.jedis.JedisPool; + +/** + * Incrementally iterate sorted sets elements and associated scores + */ +public class ZSCANCommand extends RedisCommand { + + public ZSCANCommand(JedisPool clientPool) { + super(clientPool); + } + + @Override + protected String execute(Jedis client, String[] tokens) { + String result = client.zscan(tokens[1], tokens[2]).toString(); + return result; + } +} diff --git a/redis/src/main/java/org/apache/zeppelin/redis/command/set/sorted/ZSCORECommand.java b/redis/src/main/java/org/apache/zeppelin/redis/command/set/sorted/ZSCORECommand.java new file mode 100644 index 00000000000..87097c79a34 --- /dev/null +++ b/redis/src/main/java/org/apache/zeppelin/redis/command/set/sorted/ZSCORECommand.java @@ -0,0 +1,38 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.zeppelin.redis.command.set.sorted; + +import org.apache.zeppelin.redis.command.RedisCommand; +import redis.clients.jedis.Jedis; +import redis.clients.jedis.JedisPool; + +/** + * Get the score associated with the given member in a sorted set + */ +public class ZSCORECommand extends RedisCommand { + + public ZSCORECommand(JedisPool clientPool) { + super(clientPool); + } + + @Override + protected String execute(Jedis client, String[] tokens) { + String result = client.zscore(tokens[1], tokens[2]).toString(); + return result; + } +} diff --git a/redis/src/main/java/org/apache/zeppelin/redis/command/set/sorted/ZUNIONSTORECommand.java b/redis/src/main/java/org/apache/zeppelin/redis/command/set/sorted/ZUNIONSTORECommand.java new file mode 100644 index 00000000000..bd00963268e --- /dev/null +++ b/redis/src/main/java/org/apache/zeppelin/redis/command/set/sorted/ZUNIONSTORECommand.java @@ -0,0 +1,38 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.zeppelin.redis.command.set.sorted; + +import org.apache.zeppelin.redis.command.RedisCommand; +import redis.clients.jedis.Jedis; +import redis.clients.jedis.JedisPool; + +/** + * Add multiple sorted sets and store the resulting sorted set in a new key + */ +public class ZUNIONSTORECommand extends RedisCommand { + + public ZUNIONSTORECommand(JedisPool clientPool) { + super(clientPool); + } + + @Override + protected String execute(Jedis client, String[] tokens) { + String result = client.zunionstore(tokens[1]).toString(); + return result; + } +} diff --git a/redis/src/main/java/org/apache/zeppelin/redis/command/string/APPENDCommand.java b/redis/src/main/java/org/apache/zeppelin/redis/command/string/APPENDCommand.java new file mode 100644 index 00000000000..232cfb757cb --- /dev/null +++ b/redis/src/main/java/org/apache/zeppelin/redis/command/string/APPENDCommand.java @@ -0,0 +1,38 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.zeppelin.redis.command.string; + +import org.apache.zeppelin.redis.command.RedisCommand; +import redis.clients.jedis.Jedis; +import redis.clients.jedis.JedisPool; + +/** + * Append a value to a key + */ +public class APPENDCommand extends RedisCommand { + + public APPENDCommand(JedisPool clientPool) { + super(clientPool); + } + + @Override + protected String execute(Jedis client, String[] tokens) { + String result = client.append(tokens[1], tokens[2]).toString(); + return result; + } +} diff --git a/redis/src/main/java/org/apache/zeppelin/redis/command/string/BITCOUNTCommand.java b/redis/src/main/java/org/apache/zeppelin/redis/command/string/BITCOUNTCommand.java new file mode 100644 index 00000000000..e02883c14a2 --- /dev/null +++ b/redis/src/main/java/org/apache/zeppelin/redis/command/string/BITCOUNTCommand.java @@ -0,0 +1,38 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.zeppelin.redis.command.string; + +import org.apache.zeppelin.redis.command.RedisCommand; +import redis.clients.jedis.Jedis; +import redis.clients.jedis.JedisPool; + +/** + * Count set bits in a string + */ +public class BITCOUNTCommand extends RedisCommand { + + public BITCOUNTCommand(JedisPool clientPool) { + super(clientPool); + } + + @Override + protected String execute(Jedis client, String[] tokens) { + String result = client.bitcount(tokens[1]).toString(); + return result; + } +} diff --git a/redis/src/main/java/org/apache/zeppelin/redis/command/string/BITFIELDCommand.java b/redis/src/main/java/org/apache/zeppelin/redis/command/string/BITFIELDCommand.java new file mode 100644 index 00000000000..60a7b726894 --- /dev/null +++ b/redis/src/main/java/org/apache/zeppelin/redis/command/string/BITFIELDCommand.java @@ -0,0 +1,40 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.zeppelin.redis.command.string; + +import org.apache.zeppelin.redis.command.RedisCommand; +import redis.clients.jedis.Jedis; +import redis.clients.jedis.JedisPool; + +/** + * Perform arbitrary bitfield integer operations on strings + */ +public class BITFIELDCommand extends RedisCommand { + + public BITFIELDCommand(JedisPool clientPool) { + super(clientPool); + } + + @Override + protected String execute(Jedis client, String[] tokens) { + String[] fields = new String[tokens.length - 2]; + System.arraycopy(tokens, 2, fields, 0, tokens.length - 2); + String result = client.bitfield(tokens[1], fields).toString(); + return result; + } +} diff --git a/redis/src/main/java/org/apache/zeppelin/redis/command/string/BITOPCommand.java b/redis/src/main/java/org/apache/zeppelin/redis/command/string/BITOPCommand.java new file mode 100644 index 00000000000..38f0add7c4b --- /dev/null +++ b/redis/src/main/java/org/apache/zeppelin/redis/command/string/BITOPCommand.java @@ -0,0 +1,41 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.zeppelin.redis.command.string; + +import org.apache.zeppelin.redis.command.RedisCommand; +import redis.clients.jedis.BitOP; +import redis.clients.jedis.Jedis; +import redis.clients.jedis.JedisPool; + +/** + * Perform bitwise operations between strings + */ +public class BITOPCommand extends RedisCommand { + + public BITOPCommand(JedisPool clientPool) { + super(clientPool); + } + + @Override + protected String execute(Jedis client, String[] tokens) { + String[] fields = new String[tokens.length - 3]; + System.arraycopy(tokens, 3, fields, 0, tokens.length - 3); + String result = client.bitop(BitOP.valueOf(tokens[1]), tokens[2], fields).toString(); + return result; + } +} diff --git a/redis/src/main/java/org/apache/zeppelin/redis/command/string/BITPOSCommand.java b/redis/src/main/java/org/apache/zeppelin/redis/command/string/BITPOSCommand.java new file mode 100644 index 00000000000..8275dfd315d --- /dev/null +++ b/redis/src/main/java/org/apache/zeppelin/redis/command/string/BITPOSCommand.java @@ -0,0 +1,38 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.zeppelin.redis.command.string; + +import org.apache.zeppelin.redis.command.RedisCommand; +import redis.clients.jedis.Jedis; +import redis.clients.jedis.JedisPool; + +/** + * Find first bit set or clear in a string + */ +public class BITPOSCommand extends RedisCommand { + + public BITPOSCommand(JedisPool clientPool) { + super(clientPool); + } + + @Override + protected String execute(Jedis client, String[] tokens) { + String result = client.bitpos(tokens[1], Boolean.valueOf(tokens[2])).toString(); + return result; + } +} diff --git a/redis/src/main/java/org/apache/zeppelin/redis/command/string/DECRBYCommand.java b/redis/src/main/java/org/apache/zeppelin/redis/command/string/DECRBYCommand.java new file mode 100644 index 00000000000..9a9605b65f7 --- /dev/null +++ b/redis/src/main/java/org/apache/zeppelin/redis/command/string/DECRBYCommand.java @@ -0,0 +1,38 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.zeppelin.redis.command.string; + +import org.apache.zeppelin.redis.command.RedisCommand; +import redis.clients.jedis.Jedis; +import redis.clients.jedis.JedisPool; + +/** + * Decrement the integer value of a key by the given number + */ +public class DECRBYCommand extends RedisCommand { + + public DECRBYCommand(JedisPool clientPool) { + super(clientPool); + } + + @Override + protected String execute(Jedis client, String[] tokens) { + String result = client.decrBy(tokens[1], Long.valueOf(tokens[2])).toString(); + return result; + } +} diff --git a/redis/src/main/java/org/apache/zeppelin/redis/command/string/DECRCommand.java b/redis/src/main/java/org/apache/zeppelin/redis/command/string/DECRCommand.java new file mode 100644 index 00000000000..b3144f56325 --- /dev/null +++ b/redis/src/main/java/org/apache/zeppelin/redis/command/string/DECRCommand.java @@ -0,0 +1,38 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.zeppelin.redis.command.string; + +import org.apache.zeppelin.redis.command.RedisCommand; +import redis.clients.jedis.Jedis; +import redis.clients.jedis.JedisPool; + +/** + * Decrement the integer value of a key by one + */ +public class DECRCommand extends RedisCommand { + + public DECRCommand(JedisPool clientPool) { + super(clientPool); + } + + @Override + protected String execute(Jedis client, String[] tokens) { + String result = client.decr(tokens[1]).toString(); + return result; + } +} diff --git a/redis/src/main/java/org/apache/zeppelin/redis/command/string/GETBITCommand.java b/redis/src/main/java/org/apache/zeppelin/redis/command/string/GETBITCommand.java new file mode 100644 index 00000000000..8b636757f3b --- /dev/null +++ b/redis/src/main/java/org/apache/zeppelin/redis/command/string/GETBITCommand.java @@ -0,0 +1,38 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.zeppelin.redis.command.string; + +import org.apache.zeppelin.redis.command.RedisCommand; +import redis.clients.jedis.Jedis; +import redis.clients.jedis.JedisPool; + +/** + * Returns the bit value at offset in the string value stored at key + */ +public class GETBITCommand extends RedisCommand { + + public GETBITCommand(JedisPool clientPool) { + super(clientPool); + } + + @Override + protected String execute(Jedis client, String[] tokens) { + String result = client.getbit(tokens[1], Long.valueOf(tokens[2])).toString(); + return result; + } +} diff --git a/redis/src/main/java/org/apache/zeppelin/redis/command/string/GETCommand.java b/redis/src/main/java/org/apache/zeppelin/redis/command/string/GETCommand.java new file mode 100644 index 00000000000..a13bc9448cd --- /dev/null +++ b/redis/src/main/java/org/apache/zeppelin/redis/command/string/GETCommand.java @@ -0,0 +1,38 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.zeppelin.redis.command.string; + +import org.apache.zeppelin.redis.command.RedisCommand; +import redis.clients.jedis.Jedis; +import redis.clients.jedis.JedisPool; + +/** + * Get the value of a key + */ +public class GETCommand extends RedisCommand { + + public GETCommand(JedisPool clientPool) { + super(clientPool); + } + + @Override + protected String execute(Jedis client, String[] tokens) { + String result = client.get(tokens[1]); + return result; + } +} diff --git a/redis/src/main/java/org/apache/zeppelin/redis/command/string/GETRANGECommand.java b/redis/src/main/java/org/apache/zeppelin/redis/command/string/GETRANGECommand.java new file mode 100644 index 00000000000..fe8e75a0197 --- /dev/null +++ b/redis/src/main/java/org/apache/zeppelin/redis/command/string/GETRANGECommand.java @@ -0,0 +1,39 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.zeppelin.redis.command.string; + +import org.apache.zeppelin.redis.command.RedisCommand; +import redis.clients.jedis.Jedis; +import redis.clients.jedis.JedisPool; + +/** + * Get a substring of the string stored at a key + */ +public class GETRANGECommand extends RedisCommand { + + public GETRANGECommand(JedisPool clientPool) { + super(clientPool); + } + + @Override + protected String execute(Jedis client, String[] tokens) { + String result = client.getrange(tokens[1], Long.valueOf(tokens[2]), + Long.valueOf(tokens[3])); + return result; + } +} diff --git a/redis/src/main/java/org/apache/zeppelin/redis/command/string/GETSETCommand.java b/redis/src/main/java/org/apache/zeppelin/redis/command/string/GETSETCommand.java new file mode 100644 index 00000000000..ec7fff5e609 --- /dev/null +++ b/redis/src/main/java/org/apache/zeppelin/redis/command/string/GETSETCommand.java @@ -0,0 +1,38 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.zeppelin.redis.command.string; + +import org.apache.zeppelin.redis.command.RedisCommand; +import redis.clients.jedis.Jedis; +import redis.clients.jedis.JedisPool; + +/** + * Set the string value of a key and return its old value + */ +public class GETSETCommand extends RedisCommand { + + public GETSETCommand(JedisPool clientPool) { + super(clientPool); + } + + @Override + protected String execute(Jedis client, String[] tokens) { + String result = client.getSet(tokens[1], tokens[2]); + return result; + } +} diff --git a/redis/src/main/java/org/apache/zeppelin/redis/command/string/INCRBYCommand.java b/redis/src/main/java/org/apache/zeppelin/redis/command/string/INCRBYCommand.java new file mode 100644 index 00000000000..c355d635d18 --- /dev/null +++ b/redis/src/main/java/org/apache/zeppelin/redis/command/string/INCRBYCommand.java @@ -0,0 +1,38 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.zeppelin.redis.command.string; + +import org.apache.zeppelin.redis.command.RedisCommand; +import redis.clients.jedis.Jedis; +import redis.clients.jedis.JedisPool; + +/** + * Increment the integer value of a key by the given amount + */ +public class INCRBYCommand extends RedisCommand { + + public INCRBYCommand(JedisPool clientPool) { + super(clientPool); + } + + @Override + protected String execute(Jedis client, String[] tokens) { + String result = client.incrBy(tokens[1], Long.valueOf(tokens[2])).toString(); + return result; + } +} diff --git a/redis/src/main/java/org/apache/zeppelin/redis/command/string/INCRBYFLOATCommand.java b/redis/src/main/java/org/apache/zeppelin/redis/command/string/INCRBYFLOATCommand.java new file mode 100644 index 00000000000..becc2dd69da --- /dev/null +++ b/redis/src/main/java/org/apache/zeppelin/redis/command/string/INCRBYFLOATCommand.java @@ -0,0 +1,38 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.zeppelin.redis.command.string; + +import org.apache.zeppelin.redis.command.RedisCommand; +import redis.clients.jedis.Jedis; +import redis.clients.jedis.JedisPool; + +/** + * Increment the float value of a key by the given amount + */ +public class INCRBYFLOATCommand extends RedisCommand { + + public INCRBYFLOATCommand(JedisPool clientPool) { + super(clientPool); + } + + @Override + protected String execute(Jedis client, String[] tokens) { + String result = client.incrByFloat(tokens[1], Double.valueOf(tokens[2])).toString(); + return result; + } +} diff --git a/redis/src/main/java/org/apache/zeppelin/redis/command/string/INCRCommand.java b/redis/src/main/java/org/apache/zeppelin/redis/command/string/INCRCommand.java new file mode 100644 index 00000000000..b8c4326a457 --- /dev/null +++ b/redis/src/main/java/org/apache/zeppelin/redis/command/string/INCRCommand.java @@ -0,0 +1,38 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.zeppelin.redis.command.string; + +import org.apache.zeppelin.redis.command.RedisCommand; +import redis.clients.jedis.Jedis; +import redis.clients.jedis.JedisPool; + +/** + * Increment the integer value of a key by one + */ +public class INCRCommand extends RedisCommand { + + public INCRCommand(JedisPool clientPool) { + super(clientPool); + } + + @Override + protected String execute(Jedis client, String[] tokens) { + String result = client.incr(tokens[1]).toString(); + return result; + } +} diff --git a/redis/src/main/java/org/apache/zeppelin/redis/command/string/MGETCommand.java b/redis/src/main/java/org/apache/zeppelin/redis/command/string/MGETCommand.java new file mode 100644 index 00000000000..31587276fe1 --- /dev/null +++ b/redis/src/main/java/org/apache/zeppelin/redis/command/string/MGETCommand.java @@ -0,0 +1,40 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.zeppelin.redis.command.string; + +import org.apache.zeppelin.redis.command.RedisCommand; +import redis.clients.jedis.Jedis; +import redis.clients.jedis.JedisPool; + +/** + * Get the values of all the given keys + */ +public class MGETCommand extends RedisCommand { + + public MGETCommand(JedisPool clientPool) { + super(clientPool); + } + + @Override + protected String execute(Jedis client, String[] tokens) { + String[] fields = new String[tokens.length - 1]; + System.arraycopy(tokens, 1, fields, 0, tokens.length - 1); + String result = client.mget(fields).toString(); + return result; + } +} diff --git a/redis/src/main/java/org/apache/zeppelin/redis/command/string/MSETCommand.java b/redis/src/main/java/org/apache/zeppelin/redis/command/string/MSETCommand.java new file mode 100644 index 00000000000..8e9e188e33a --- /dev/null +++ b/redis/src/main/java/org/apache/zeppelin/redis/command/string/MSETCommand.java @@ -0,0 +1,40 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.zeppelin.redis.command.string; + +import org.apache.zeppelin.redis.command.RedisCommand; +import redis.clients.jedis.Jedis; +import redis.clients.jedis.JedisPool; + +/** + * Set multiple keys to multiple values + */ +public class MSETCommand extends RedisCommand { + + public MSETCommand(JedisPool clientPool) { + super(clientPool); + } + + @Override + protected String execute(Jedis client, String[] tokens) { + String[] fields = new String[tokens.length - 1]; + System.arraycopy(tokens, 1, fields, 0, tokens.length - 1); + String result = client.mset(fields); + return result; + } +} diff --git a/redis/src/main/java/org/apache/zeppelin/redis/command/string/MSETNXCommand.java b/redis/src/main/java/org/apache/zeppelin/redis/command/string/MSETNXCommand.java new file mode 100644 index 00000000000..87f987f9628 --- /dev/null +++ b/redis/src/main/java/org/apache/zeppelin/redis/command/string/MSETNXCommand.java @@ -0,0 +1,40 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.zeppelin.redis.command.string; + +import org.apache.zeppelin.redis.command.RedisCommand; +import redis.clients.jedis.Jedis; +import redis.clients.jedis.JedisPool; + +/** + * Set multiple keys to multiple values, only if none of the keys exist + */ +public class MSETNXCommand extends RedisCommand { + + public MSETNXCommand(JedisPool clientPool) { + super(clientPool); + } + + @Override + protected String execute(Jedis client, String[] tokens) { + String[] fields = new String[tokens.length - 1]; + System.arraycopy(tokens, 1, fields, 0, tokens.length - 1); + String result = client.msetnx(fields).toString(); + return result; + } +} diff --git a/redis/src/main/java/org/apache/zeppelin/redis/command/string/PSETEXCommand.java b/redis/src/main/java/org/apache/zeppelin/redis/command/string/PSETEXCommand.java new file mode 100644 index 00000000000..a6955f6d51b --- /dev/null +++ b/redis/src/main/java/org/apache/zeppelin/redis/command/string/PSETEXCommand.java @@ -0,0 +1,38 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.zeppelin.redis.command.string; + +import org.apache.zeppelin.redis.command.RedisCommand; +import redis.clients.jedis.Jedis; +import redis.clients.jedis.JedisPool; + +/** + * Set the value and expiration in milliseconds of a key + */ +public class PSETEXCommand extends RedisCommand { + + public PSETEXCommand(JedisPool clientPool) { + super(clientPool); + } + + @Override + protected String execute(Jedis client, String[] tokens) { + String result = client.psetex(tokens[1], Long.valueOf(tokens[2]), tokens[3]); + return result; + } +} diff --git a/redis/src/main/java/org/apache/zeppelin/redis/command/string/SETBITCommand.java b/redis/src/main/java/org/apache/zeppelin/redis/command/string/SETBITCommand.java new file mode 100644 index 00000000000..6178ab45e9f --- /dev/null +++ b/redis/src/main/java/org/apache/zeppelin/redis/command/string/SETBITCommand.java @@ -0,0 +1,39 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.zeppelin.redis.command.string; + +import org.apache.zeppelin.redis.command.RedisCommand; +import redis.clients.jedis.Jedis; +import redis.clients.jedis.JedisPool; + +/** + * Sets or clears the bit at offset in the string value stored at key + */ +public class SETBITCommand extends RedisCommand { + + public SETBITCommand(JedisPool clientPool) { + super(clientPool); + } + + @Override + protected String execute(Jedis client, String[] tokens) { + String result = client.setbit(tokens[1], Long.valueOf(tokens[2]), + Boolean.valueOf(tokens[3])).toString(); + return result; + } +} diff --git a/redis/src/main/java/org/apache/zeppelin/redis/command/string/SETCommand.java b/redis/src/main/java/org/apache/zeppelin/redis/command/string/SETCommand.java new file mode 100644 index 00000000000..37c87fdb324 --- /dev/null +++ b/redis/src/main/java/org/apache/zeppelin/redis/command/string/SETCommand.java @@ -0,0 +1,38 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.zeppelin.redis.command.string; + +import org.apache.zeppelin.redis.command.RedisCommand; +import redis.clients.jedis.Jedis; +import redis.clients.jedis.JedisPool; + +/** + * Set the string value of a key + */ +public class SETCommand extends RedisCommand { + + public SETCommand(JedisPool clientPool) { + super(clientPool); + } + + @Override + protected String execute(Jedis client, String[] tokens) { + String result = client.set(tokens[1], tokens[2]); + return result; + } +} diff --git a/redis/src/main/java/org/apache/zeppelin/redis/command/string/SETEXCommand.java b/redis/src/main/java/org/apache/zeppelin/redis/command/string/SETEXCommand.java new file mode 100644 index 00000000000..5fc4f9235ec --- /dev/null +++ b/redis/src/main/java/org/apache/zeppelin/redis/command/string/SETEXCommand.java @@ -0,0 +1,38 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.zeppelin.redis.command.string; + +import org.apache.zeppelin.redis.command.RedisCommand; +import redis.clients.jedis.Jedis; +import redis.clients.jedis.JedisPool; + +/** + * Set the value and expiration of a key + */ +public class SETEXCommand extends RedisCommand { + + public SETEXCommand(JedisPool clientPool) { + super(clientPool); + } + + @Override + protected String execute(Jedis client, String[] tokens) { + String result = client.setex(tokens[1], Integer.valueOf(tokens[2]), tokens[3]); + return result; + } +} diff --git a/redis/src/main/java/org/apache/zeppelin/redis/command/string/SETNXCommand.java b/redis/src/main/java/org/apache/zeppelin/redis/command/string/SETNXCommand.java new file mode 100644 index 00000000000..ddedaa95666 --- /dev/null +++ b/redis/src/main/java/org/apache/zeppelin/redis/command/string/SETNXCommand.java @@ -0,0 +1,38 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.zeppelin.redis.command.string; + +import org.apache.zeppelin.redis.command.RedisCommand; +import redis.clients.jedis.Jedis; +import redis.clients.jedis.JedisPool; + +/** + * Set the value of a key, only if the key does not exist + */ +public class SETNXCommand extends RedisCommand { + + public SETNXCommand(JedisPool clientPool) { + super(clientPool); + } + + @Override + protected String execute(Jedis client, String[] tokens) { + String result = client.setnx(tokens[1], tokens[2]).toString(); + return result; + } +} diff --git a/redis/src/main/java/org/apache/zeppelin/redis/command/string/SETRANGECommand.java b/redis/src/main/java/org/apache/zeppelin/redis/command/string/SETRANGECommand.java new file mode 100644 index 00000000000..6cc8996f6bb --- /dev/null +++ b/redis/src/main/java/org/apache/zeppelin/redis/command/string/SETRANGECommand.java @@ -0,0 +1,38 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.zeppelin.redis.command.string; + +import org.apache.zeppelin.redis.command.RedisCommand; +import redis.clients.jedis.Jedis; +import redis.clients.jedis.JedisPool; + +/** + * Overwrite part of a string at key starting at the specified offset + */ +public class SETRANGECommand extends RedisCommand { + + public SETRANGECommand(JedisPool clientPool) { + super(clientPool); + } + + @Override + protected String execute(Jedis client, String[] tokens) { + String result = client.setrange(tokens[1], Long.valueOf(tokens[2]), tokens[3]).toString(); + return result; + } +} diff --git a/redis/src/main/java/org/apache/zeppelin/redis/command/string/STRLENCommand.java b/redis/src/main/java/org/apache/zeppelin/redis/command/string/STRLENCommand.java new file mode 100644 index 00000000000..7c18d92095b --- /dev/null +++ b/redis/src/main/java/org/apache/zeppelin/redis/command/string/STRLENCommand.java @@ -0,0 +1,38 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.zeppelin.redis.command.string; + +import org.apache.zeppelin.redis.command.RedisCommand; +import redis.clients.jedis.Jedis; +import redis.clients.jedis.JedisPool; + +/** + * Get the length of the value stored in a key + */ +public class STRLENCommand extends RedisCommand { + + public STRLENCommand(JedisPool clientPool) { + super(clientPool); + } + + @Override + protected String execute(Jedis client, String[] tokens) { + String result = client.strlen(tokens[1]).toString(); + return result; + } +} diff --git a/redis/src/main/resources/interpreter-setting.json b/redis/src/main/resources/interpreter-setting.json new file mode 100644 index 00000000000..c4fb56f0011 --- /dev/null +++ b/redis/src/main/resources/interpreter-setting.json @@ -0,0 +1,21 @@ +[ + { + "group": "redis", + "name": "redis", + "className": "org.apache.zeppelin.redis.RedisInterpreter", + "properties": { + "redis.host": { + "envName": null, + "propertyName": "redis.host", + "defaultValue": "127.0.0.1", + "description": "redis server host" + }, + "redis.port": { + "envName": null, + "propertyName": "redis.port", + "defaultValue": 6379, + "description": "redis server port" + } + } + } +] diff --git a/zeppelin-zengine/src/main/java/org/apache/zeppelin/conf/ZeppelinConfiguration.java b/zeppelin-zengine/src/main/java/org/apache/zeppelin/conf/ZeppelinConfiguration.java index 414aed2a5bb..7264ac11e45 100644 --- a/zeppelin-zengine/src/main/java/org/apache/zeppelin/conf/ZeppelinConfiguration.java +++ b/zeppelin-zengine/src/main/java/org/apache/zeppelin/conf/ZeppelinConfiguration.java @@ -537,7 +537,8 @@ public static enum ConfVars { + "org.apache.zeppelin.jdbc.JDBCInterpreter," + "org.apache.zeppelin.hbase.HbaseInterpreter," + "org.apache.zeppelin.bigquery.BigQueryInterpreter," - + "org.apache.zeppelin.beam.BeamInterpreter"), + + "org.apache.zeppelin.beam.BeamInterpreter," + + "org.apache.zeppelin.redis.RedisInterpreter"), ZEPPELIN_INTERPRETER_JSON("zeppelin.interpreter.setting", "interpreter-setting.json"), ZEPPELIN_INTERPRETER_DIR("zeppelin.interpreter.dir", "interpreter"), ZEPPELIN_INTERPRETER_LOCALREPO("zeppelin.interpreter.localRepo", "local-repo"), @@ -545,7 +546,7 @@ public static enum ConfVars { ZEPPELIN_INTERPRETER_MAX_POOL_SIZE("zeppelin.interpreter.max.poolsize", 10), ZEPPELIN_INTERPRETER_GROUP_ORDER("zeppelin.interpreter.group.order", "spark,md,angular,sh," + "livy,alluxio,file,psql,flink,python,ignite,lens,cassandra,geode,kylin,elasticsearch," - + "scalding,jdbc,hbase,bigquery,beam,pig"), + + "scalding,jdbc,hbase,bigquery,beam,pig,redis"), ZEPPELIN_ENCODING("zeppelin.encoding", "UTF-8"), ZEPPELIN_NOTEBOOK_DIR("zeppelin.notebook.dir", "notebook"), // use specified notebook (id) as homescreen