GET
GET key
get(
name: KeyT
) → ResponseT
GET(
key: RedisArgument
) → Any
get(
key: String
) → String // Bulk reply
get(
key: K // the key.
) → V // V bulk-string-reply the value of key, or null when key does not exist.
get(
key: K // the key.
) → RedisFuture<V> // V bulk-string-reply the value of key, or null when key does not exist.
get(
key: K // the key.
) → Mono<V> // V bulk-string-reply the value of key, or null when key does not exist.
Get(
ctx: context.Context,
key: string
) → *StringCmd
StringGet(
key: RedisKey,
flags: CommandFlags // The flags to use for this operation.
) → RedisValue // The values of the strings with Null for keys do not exist.
StringGet(
keys: RedisKey[], // The keys of the strings.
flags: CommandFlags // The flags to use for this operation.
) → RedisValue[] // The values of the strings with Null for keys do not exist.
StringGet(
key: Any,
flags: Any // The flags to use for this operation.
) → return // The values of the strings with Null for keys do not exist.
StringGet(
key: RedisKey,
flags: CommandFlags // The flags to use for this operation.
) → RedisValue // The values of the strings with Null for keys do not exist.
StringGet(
keys: RedisKey[], // The keys of the strings.
flags: CommandFlags // The flags to use for this operation.
) → RedisValue[] // The values of the strings with Null for keys do not exist.
StringGet(
key: RedisKey,
flags: CommandFlags // The flags to use for this operation.
) → RedisValue // The values of the strings with Null for keys do not exist.
StringGet(
keys: RedisKey[], // The keys of the strings.
flags: CommandFlags // The flags to use for this operation.
) → RedisValue[] // The values of the strings with Null for keys do not exist.
StringGet(
key: Any,
flags: Any // The flags to use for this operation.
) → return // The values of the strings with Null for keys do not exist.
StringGet(
key: RedisKey,
flags: CommandFlags // The flags to use for this operation.
) → RedisValue // The values of the strings with Null for keys do not exist.
StringGet(
keys: RedisKey[], // The keys of the strings.
flags: CommandFlags // The flags to use for this operation.
) → RedisValue[] // The values of the strings with Null for keys do not exist.
get(
$key: string
) → string|null
get(
key: K
) → (Option<String>)
get(
mut self: Any,
get: bool
) → Self
get(
key: K
) → (Option<String>)
get(
mut self: Any,
get: bool
) → Self
- Available since:
- Redis Open Source 1.0.0
- Time complexity:
- O(1)
- ACL categories:
-
@read,@string,@fast, - Compatibility:
- Redis Software and Redis Cloud compatibility
Get the value of key.
If the key does not exist, nil is returned.
An error is returned if the value stored at key is not a string, because GET
only handles string values.
Required arguments
key
The name of the key.
Examples
Foundational: Retrieve the string value of a key using GET (returns nil if key doesn't exist)
Redis CLI guide
Also, check out our other client tools
Redis Insight
and
Redis for VS Code.
"""
Code samples for data structure store quickstart pages:
https://redis.io/docs/latest/develop/get-started/data-store/
"""
import redis
r = redis.Redis(host="localhost", port=6379, db=0, decode_responses=True)
res = r.set("bike:1", "Process 134")
print(res)
# >>> True
res = r.get("bike:1")
print(res)
# >>> "Process 134"
-
Sets the string value of a key, ignoring its type. The key is created if it doesn't exist.
-
set(
- name: KeyT,
- value: EncodableT,
- ex: Optional[ExpiryT] = None,
- px: Optional[ExpiryT] = None,
- nx: bool = False,
- xx: bool = False,
- keepttl: bool = False,
- get: bool = False,
- exat: Optional[AbsExpiryT] = None,
- pxat: Optional[AbsExpiryT] = None,
- ifeq: Optional[Union[bytes, str]] = None,
- ifne: Optional[Union[bytes, str]] = None,
- ifdeq: Optional[str] = None,
- ifdne: Optional[str] = None
-
set(
import { createClient } from 'redis';
const client = createClient();
client.on('error', err => console.log('Redis Client Error', err));
await client.connect().catch(console.error);
await client.set('bike:1', 'Process 134');
const value = await client.get('bike:1');
console.log(value);
// returns 'Process 134'
await client.close();
package io.redis.examples;
import redis.clients.jedis.RedisClient;
public class SetGetExample {
public void run() {
RedisClient jedis = RedisClient.create("redis://localhost:6379");
String status = jedis.set("bike:1", "Process 134");
if ("OK".equals(status)) System.out.println("Successfully added a bike.");
String value = jedis.get("bike:1");
if (value != null) System.out.println("The name of the bike is: " + value + ".");
jedis.close();
}
}
-
Sets the string value of a key, ignoring its type. The key is created if it doesn't exist.
-
set(
- key: byte[],
- value: byte[]
-
set(
- key: byte[],
- value: byte[],
- params: SetParams // key if it already exists. EX|PX, expire time units: EX = seconds; PX = milliseconds
-
set(
- key: String,
- value: String
-
set(
- key: String,
- value: String,
- params: SetParams // key if it already exists. EX|PX, expire time units: EX = seconds; PX = milliseconds
-
set(
package example_commands_test
import (
"context"
"fmt"
"github.com/redis/go-redis/v9"
)
func ExampleClient_Set_and_get() {
ctx := context.Background()
rdb := redis.NewClient(&redis.Options{
Addr: "localhost:6379",
Password: "", // no password docs
DB: 0, // use default DB
})
err := rdb.Set(ctx, "bike:1", "Process 134", 0).Err()
if err != nil {
panic(err)
}
fmt.Println("OK")
value, err := rdb.Get(ctx, "bike:1").Result()
if err != nil {
panic(err)
}
fmt.Printf("The name of the bike is %s", value)
}
using NRedisStack.Tests;
using StackExchange.Redis;
public class SetGetExample
{
public void Run()
{
var muxer = ConnectionMultiplexer.Connect("localhost:6379");
var db = muxer.GetDatabase();
bool status = db.StringSet("bike:1", "Process 134");
if (status)
Console.WriteLine("Successfully added a bike.");
var value = db.StringGet("bike:1");
if (value.HasValue)
Console.WriteLine("The name of the bike is: " + value + ".");
}
}
-
Returns the string value of a key.
-
StringGet(
- key: RedisKey,
- flags: CommandFlags // The flags to use for this operation.
-
StringGet(
- keys: RedisKey[], // The keys of the strings.
- flags: CommandFlags // The flags to use for this operation.
-
StringGet(
- key: Any,
- flags: Any // The flags to use for this operation.
-
StringGet(
- key: RedisKey,
- flags: CommandFlags // The flags to use for this operation.
-
StringGet(
- keys: RedisKey[], // The keys of the strings.
- flags: CommandFlags // The flags to use for this operation.
-
StringGet(
-
Sets the string value of a key, ignoring its type. The key is created if it doesn't exist.
-
StringSet(
- key: RedisKey,
- value: RedisValue,
- expiry: TimeSpan?, // The expiry to set.
- when: When // Which condition to set the value under (defaults to always).
-
StringSet(
- key: RedisKey,
- value: RedisValue,
- expiry: TimeSpan?, // The expiry to set.
- when: When, // Which condition to set the value under (defaults to always).
- flags: CommandFlags // The flags to use for this operation.
-
StringSet(
- key: RedisKey,
- value: RedisValue,
- expiry: TimeSpan?, // The expiry to set.
- keepTtl: bool,
- when: When, // Which condition to set the value under (defaults to always).
- flags: CommandFlags // The flags to use for this operation.
-
StringSet(
- key: RedisKey,
- value: RedisValue,
- expiry: Expiration, // The expiry to set.
- when: ValueCondition, // Which condition to set the value under (defaults to always).
- flags: CommandFlags // The flags to use for this operation.
-
StringSet(
- values: KeyValuePair<RedisKey, RedisValue>[], // The keys and values to set.
- when: When, // Which condition to set the value under (defaults to always).
- flags: CommandFlags // The flags to use for this operation.
-
StringSet(
Redis Software and Redis Cloud compatibility
| Redis Software |
Redis Cloud |
Notes |
|---|---|---|
| ✅ Standard |
✅ Standard |
Return information
One of the following:
- Bulk string reply: the value of the key.
- Nil reply: if the key does not exist.
One of the following:
- Bulk string reply: the value of the key.
- Null reply: key does not exist.