Java连接redis
maven:
<!-- https://mvnrepository.com/artifact/redis.clients/jedis -->
<dependency>
<groupId>redis.clients</groupId>
<artifactId>jedis</artifactId>
<version>2.9.0</version>
</dependency>
public class App
{
public static void main( String[] args )
{
Jedis jedis = new Jedis("192.168.253.150");
System.out.println("连接成功");
jedis.set("zjw","game");
System.out.println(jedis.get("zjw"));
}
}
//输出
连接成功
game
192.168.253.150:6379> get zjw
"game"
public class App
{
public static void main( String[] args )
{
Jedis jedis = new Jedis("192.168.253.150");
System.out.println("连接成功");
jedis.lpush("xxx","zs","hehe","xixi","haha");
}
}
192.168.253.150:6379> LRANGE xxx 0 10
1) "haha"
2) "xixi"
3) "hehe"
4) "zs"
scala连接redis
maven:
<!-- https://mvnrepository.com/artifact/org.apache.spark/spark-core -->
<dependency>
<groupId>org.apache.spark</groupId>
<artifactId>spark-core_2.11</artifactId>
<version>2.3.4</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.apache.spark/spark-sql -->
<dependency>
<groupId>org.apache.spark</groupId>
<artifactId>spark-sql_2.11</artifactId>
<version>2.3.4</version>
</dependency>
<!-- https://mvnrepository.com/artifact/com.redislabs/spark-redis -->
<dependency>
<groupId>com.redislabs</groupId>
<artifactId>spark-redis</artifactId>
<version>2.4.0</version>
</dependency>
import org.apache.spark.sql.SparkSession
import redis.clients.jedis.Jedis
object rwRedis {
def main(args: Array[String]): Unit = {
val spark = SparkSession.builder().appName("ttt").master("local[*]").getOrCreate()
val jd = new Jedis("192.168.253.150")
val dd = jd.lrange("xxx",0,10)
val rdd = spark.sparkContext.parallelize(Seq(dd))
rdd.foreach(x=>println(x))
}
}
//输出结果
[haha, xixi, hehe, zs]
Python连接redis
添加redis:
import redis
if __name__ == '__main__':
handler = redis.Redis(host="192.168.253.150",port=6379,decode_responses=True)
print(handler.get("zjw"))
//输出
game