Connect Your Client
Upstash works with Redis® API, that means you can use any Redis client with Upstash. At the Redis Clients page you can find the list of Redis clients in different languages.
Probably, the easiest way to connect to your database is to use redis-cli
. Because it is already covered in Getting Started, we will skip it here.
#
DatabaseAfter completing the getting started guide, you will see the database page as below:
The information required for Redis clients is displayed here as Endpoint, Port and Password. Also when you click on Connect
button, you can copy the code that is required for your client.
Below we will give examples from popular Redis clients, but the above information should help you to configure all Redis clients similarly.
note
If you have enabled TLS in your database, please refer to Connect With TLS section instead.
#
Node.jsLibrary: ioredis
Example:
const Redis = require("ioredis");
let client = new Redis("redis://:YOUR_PASSWORD@YOUR_ENDPOINT:YOUR_PORT");await client.set('foo', 'bar');let x = await client.get('foo');console.log(x);
#
PythonLibrary: redis-py
Example:
import redisr = redis.Redis(host= 'YOUR_ENDPOINT',port= 'YOUR_PORT',password= 'YOUR_PASSWORD')r.set('foo','bar')print(r.get('foo'))
#
JavaLibrary: jedis
Example:
Jedis jedis = new Jedis("YOUR_ENDPOINT", "YOUR_PORT");jedis.auth("YOUR_PASSWORD");jedis.set("foo", "bar");String value = jedis.get("foo");System.out.println(value);
#
GoLangLibrary: redigo
Example:
func main() { c, err := redis.Dial("tcp", "YOUR_ENDPOINT:YOUR_PORT") if err != nil { panic(err) }
_, err = c.Do("AUTH", "YOUR_PASSWORD") if err != nil { panic(err) }
_, err = c.Do("SET", "foo", "bar") if err != nil { panic(err) }
value, err := redis.String(c.Do("GET", "foo")) if err != nil { panic(err) }
println(value)}