...
This commit is contained in:
0
aiprompts/ai_core/namefix.md
Normal file
0
aiprompts/ai_core/namefix.md
Normal file
0
aiprompts/ai_core/redis.md
Normal file
0
aiprompts/ai_core/redis.md
Normal file
@@ -1,6 +1,63 @@
|
||||
# Redisclient
|
||||
|
||||
## basic example to connect to local redis on 127.0.0.1:6379
|
||||
Getting started:
|
||||
|
||||
```v
|
||||
// Connect to Redis (recommended way)
|
||||
import freeflowuniverse.herolib.core.base
|
||||
mut context := base.context()!
|
||||
mut redis := context.redis()!
|
||||
|
||||
// String commands
|
||||
redis.set('mykey', 'hello')!
|
||||
println(redis.get('mykey')!) // Output: hello
|
||||
redis.del('mykey')!
|
||||
|
||||
// Hash commands
|
||||
redis.hset('myhash', 'field1', 'value1')!
|
||||
println(redis.hget('myhash', 'field1')!) // Output: value1
|
||||
println(redis.hgetall('myhash')!) // Output: {'field1': 'value1', 'field2': 'value2'}
|
||||
redis.hdel('myhash', 'field1')!
|
||||
|
||||
// List commands
|
||||
redis.lpush('mylist', 'item1')!
|
||||
redis.rpush('mylist', 'item2')!
|
||||
println(redis.lrange('mylist', 0, -1)!) // Output: ['item1', 'item2']
|
||||
println(redis.lpop('mylist')!) // Output: item1
|
||||
println(redis.rpop('mylist')!) // Output: item2
|
||||
|
||||
// Set commands
|
||||
redis.sadd('myset', ['member1', 'member2', 'member3'])!
|
||||
println(redis.smismember('myset', ['member1', 'member4'])!) // Output: [1, 0]
|
||||
|
||||
// Key commands
|
||||
redis.set('key1', 'value1')!
|
||||
redis.set('key2', 'value2')!
|
||||
println(redis.keys('*')!) // Output: ['key1', 'key2'] (order may vary)
|
||||
redis.expire('key1', 10)! // Set expiry to 10 seconds
|
||||
|
||||
// Increment/Decrement commands
|
||||
redis.set('counter', '10')!
|
||||
println(redis.incr('counter')!) // Output: 11
|
||||
println(redis.decrby('counter', 5)!) // Output: 6
|
||||
|
||||
// Append command
|
||||
redis.set('mytext', 'hello')!
|
||||
println(redis.append('mytext', ' world')!) // Output: 11 (length of new string)
|
||||
println(redis.get('mytext')!) // Output: hello world
|
||||
|
||||
// Type command
|
||||
println(redis.type_of('mykey')!) // Output: string (or none if key doesn't exist)
|
||||
|
||||
// Flush commands (use with caution!)
|
||||
// redis.flushdb()! // Flushes the current database
|
||||
// redis.flushall()! // Flushes all databases
|
||||
|
||||
```
|
||||
|
||||
## archive
|
||||
|
||||
### non recommended example to connect to local redis on 127.0.0.1:6379
|
||||
|
||||
```v
|
||||
|
||||
@@ -16,4 +73,3 @@ if r != 'some data' {
|
||||
```
|
||||
|
||||
> redis commands can be found on https://redis.io/commands/
|
||||
|
||||
|
||||
@@ -2,7 +2,6 @@
|
||||
|
||||
The TextTools module provides a comprehensive set of utilities for text manipulation and processing in V. It includes functions for cleaning, parsing, formatting, and transforming text in various ways.
|
||||
|
||||
## Features
|
||||
|
||||
### Array Operations
|
||||
- `to_array(r string) []string` - Converts a comma or newline separated list to an array of strings
|
||||
@@ -37,6 +36,12 @@ The TextTools module provides a comprehensive set of utilities for text manipula
|
||||
- Handles comments, code blocks, and preserves formatting
|
||||
|
||||
### Name/Path Processing
|
||||
|
||||
```v
|
||||
import freeflowuniverse.herolib.core.texttools
|
||||
texttools.name_fix(sometext)
|
||||
```
|
||||
|
||||
- `name_fix(name string) string` - Normalizes filenames and paths
|
||||
- `name_fix_keepspace(name string) !string` - Like name_fix but preserves spaces
|
||||
- `name_fix_no_ext(name_ string) string` - Removes file extension
|
||||
@@ -121,26 +126,3 @@ ver := texttools.version("v1.4.36")
|
||||
// Result: 1004036
|
||||
```
|
||||
|
||||
## Error Handling
|
||||
|
||||
Many functions in the module return a Result type (indicated by `!` in the function signature). These functions can return errors that should be handled appropriately:
|
||||
|
||||
```v
|
||||
// Example of error handling
|
||||
name := texttools.name_fix_keepspace("some@name") or {
|
||||
println("Error: ${err}")
|
||||
return
|
||||
}
|
||||
```
|
||||
|
||||
## Best Practices
|
||||
|
||||
1. Always use appropriate error handling for functions that return Results
|
||||
2. Consider using `dedent()` before processing multiline text to ensure consistent formatting
|
||||
3. When working with filenames, use the appropriate name_fix variant based on your needs
|
||||
4. For command line parsing, be aware of quote handling and escaping rules
|
||||
5. When using tokenization, consider the context and whether smart splitting is needed
|
||||
|
||||
## Contributing
|
||||
|
||||
The TextTools module is part of the heroLib project. Contributions are welcome through pull requests.
|
||||
|
||||
@@ -237,7 +237,7 @@ fn (mut site DocSite) template_install() ! {
|
||||
|
||||
develop := $tmpl('templates/develop.sh')
|
||||
build := $tmpl('templates/build.sh')
|
||||
build_dev_publish := $tmpl('templates/build_dev_publish.sh')
|
||||
// build_dev_publish := $tmpl('templates/build_dev_publish.sh')
|
||||
build_publish := $tmpl('templates/build_publish.sh')
|
||||
|
||||
mut develop_ := site.path_build.file_get_new('develop.sh')!
|
||||
@@ -252,9 +252,9 @@ fn (mut site DocSite) template_install() ! {
|
||||
build_publish_.template_write(build_publish, true)!
|
||||
build_publish_.chmod(0o700)!
|
||||
|
||||
mut build_dev_publish_ := site.path_build.file_get_new('build_dev_publish.sh')!
|
||||
build_dev_publish_.template_write(build_dev_publish, true)!
|
||||
build_dev_publish_.chmod(0o700)!
|
||||
// mut build_dev_publish_ := site.path_build.file_get_new('build_dev_publish.sh')!
|
||||
// build_dev_publish_.template_write(build_dev_publish, true)!
|
||||
// build_dev_publish_.chmod(0o700)!
|
||||
|
||||
develop_templ := $tmpl('templates/develop_src.sh')
|
||||
mut develop2_ := site.path_src.file_get_new('develop.sh')!
|
||||
|
||||
Reference in New Issue
Block a user